Created
December 2, 2014 13:45
-
-
Save zbinlin/25725792d737d8cd2521 to your computer and use it in GitHub Desktop.
This file contains 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
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