Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save catid/6fa5ed33b42c793ab4ccb1cd9804ec99 to your computer and use it in GitHub Desktop.
Save catid/6fa5ed33b42c793ab4ccb1cd9804ec99 to your computer and use it in GitHub Desktop.
q = x >> 32
r = x - (q << 32)
i = 0
while (q > 0) {
t = (q << 4) - q
q = t >> 32
r_i = t - (q << 32)
if (++i % 2 == 1)
r -= r_i
else
r += r_i
}
while (r >= m) {
r = r - m
}
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment