Skip to content

Instantly share code, notes, and snippets.

@zbinlin
Created December 2, 2014 13:45
Show Gist options
  • Save zbinlin/25725792d737d8cd2521 to your computer and use it in GitHub Desktop.
Save zbinlin/25725792d737d8cd2521 to your computer and use it in GitHub Desktop.
Math.mod = function (a, b) {
return (a - Math.floor(a / b) * b);
};
Math.rem = function (a, b) {
return (a - ((a / b) | 0) * b);
};
Math.sign = function (a) {
return 0 > a ? -1 : 1;
};
function toInt64(a) { // 只能精確到 52 位
a = Number(a);
if (0 === a || !isFinite(a)) {
return +0;
}
a = Math.sign(a) * Math.floor(Math.abs(a));
return a >= Math.pow(2, 63) ? a - Math.pow(2, 64) : a;
}
function toUint64(a) { // 只能精確到 52 位
a = Number(a);
if (0 === a || !isFinite(a)) {
return +0;
}
a = Math.sign(a) * Math.floor(Math.abs(a));
a = Math.mod(a, Math.pow(2, 64));
return a;
}
function mod(a, b) {
return (a - Math.floor(a / b) * b);
}
Hi = Math.floor(a / Math.pow(2, 32));
//Lo = a % Math.pow(2, 32);
Lo = mod(a, Math.pow(2, 32));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment