Created
April 3, 2016 06:20
-
-
Save mizdra/a2bf93e5b76cf8c33340afcda615bd93 to your computer and use it in GitHub Desktop.
See https://gist.github.com/odanado/26834f30406b25c47a5b and https://gist.github.com/oupo/eb53ffcd1db2020b3f20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calcPow(a, n, mask) { | |
return n === 0 ? 1 : | |
Math.imul((n & 1 ? a : 1), calcPow(Math.imul(a, a) & mask, n >>> 1, mask)); | |
} | |
function calcInverse(mul, mask) { | |
return calcPow(mul, mask >>> 1, mask); | |
} | |
function u32(x) { | |
return x >>> 0; | |
} | |
function main() { | |
var mul = 0x41c64e6d; | |
var incr = 0x6073; | |
var mask = 0x7FFFFFFF; | |
var inverseMul = calcInverse(mul, mask); | |
var inverseIncr = ~Math.imul(inverseMul, incr) + 1; | |
console.log("%s, %s", u32(inverseMul).toString(16), u32(inverseIncr).toString(16)); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mul = 0x41c64e6d, incr = 0x6073
のときmul = 0x6c078965, incr = 0x1
のとき