diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-04-01 14:34:26 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-04-01 14:34:26 -0700 |
commit | 7455fa112b79e73aa7c731c5c18c040dcd536a8a (patch) | |
tree | 30af15b357c27293160ab92aa973fa239676370f | |
parent | b215efb7c115aa0c62daf081dc9098042fe2ffda (diff) |
work towards unsigned precise i64s: add, subtract and multiply work but divide and modulo do not; printing is rounded
-rw-r--r-- | src/library.js | 15 | ||||
-rw-r--r-- | src/long.js | 9 | ||||
-rwxr-xr-x | tests/runner.py | 7 |
3 files changed, 19 insertions, 12 deletions
diff --git a/src/library.js b/src/library.js index 6ccd398f..f49a8a58 100644 --- a/src/library.js +++ b/src/library.js @@ -2487,13 +2487,13 @@ LibraryManager.library = { var signed = next == 'd'.charCodeAt(0) || next == 'i'.charCodeAt(0); argSize = argSize || 4; var currArg = getNextArg('i' + (argSize * 8)); - var argText = null; +#if PRECISE_I64_MATH == 1 + var origArg = currArg; +#endif + var argText; #if USE_TYPED_ARRAYS == 2 // Flatten i64-1 [low, high] into a (slightly rounded) double if (argSize == 8) { -#if PRECISE_I64_MATH == 1 - argText = i64Math.stringify(currArg[0], currArg[1]); -#endif currArg = Runtime.makeBigInt(currArg[0], currArg[1], next == 'u'.charCodeAt(0)); } #endif @@ -2505,12 +2505,15 @@ LibraryManager.library = { // Format the number. var currAbsArg = Math.abs(currArg); var prefix = ''; + if (next == 'd'.charCodeAt(0) || next == 'i'.charCodeAt(0)) { #if PRECISE_I64_MATH == 1 - if (argText !== null) {} else + if (argSize == 8) argText = i64Math.stringify(origArg[0], origArg[1]); else #endif - if (next == 'd'.charCodeAt(0) || next == 'i'.charCodeAt(0)) { argText = reSign(currArg, 8 * argSize, 1).toString(10); } else if (next == 'u'.charCodeAt(0)) { +#if PRECISE_I64_MATH == 1 + if (argSize == 8) argText = i64Math.stringify(origArg[0], origArg[1], true); else +#endif argText = unSign(currArg, 8 * argSize, 1).toString(10); currArg = Math.abs(currArg); } else if (next == 'o'.charCodeAt(0)) { diff --git a/src/long.js b/src/long.js index af908322..bdeafe77 100644 --- a/src/long.js +++ b/src/long.js @@ -840,8 +840,13 @@ return { this.result[0] = ret.low_; this.result[1] = ret.high_; }, - stringify: function(l, h) { - return new goog.math.Long(l, h).toString(); + stringify: function(l, h, unsigned) { + var ret = new goog.math.Long(l, h).toString(); + if (unsigned && ret[0] == '-') { + // unsign, approximately.. + ret = Math.pow(2, 64) + parseFloat(ret); + } + return ret; } }; })(); diff --git a/tests/runner.py b/tests/runner.py index 1bd8a165..c8a29184 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -839,15 +839,14 @@ m_divisor is 1091269979 #include <stdio.h> int main() { - /*uint64_t x = 0, y = 0; + uint64_t x = 0, y = 0; for (int i = 0; i < 64; i++) { x += 1ULL << i; y += x; x /= 3; y *= 5; - printf("unsigned %d: %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu\n", i, x, y, x+y, x-y, x*y, y ? x/y : 0, x ? y/x : 0, y ? x%y : 0, x ? y%x : 0); -return 0; - }*/ + printf("unsigned %d: %llu,%llu,%llu,%llu,%llu\n", i, x, y, x+y, x-y, x*y);//, y ? x/y : 0, x ? y/x : 0, y ? x%y : 0, x ? y%x : 0); + } int64_t x2 = 0, y2 = 0; for (int i = 0; i < 64; i++) { x2 += 1LL << i; |