diff options
-rw-r--r-- | src/parseTools.js | 10 | ||||
-rw-r--r-- | src/preamble.js | 1 | ||||
-rw-r--r-- | tests/runner.py | 12 |
3 files changed, 19 insertions, 4 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index 0e30aa5e..350083e6 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1175,6 +1175,10 @@ function processMathop(item) { with(item) { } var bitsLeft = ident2 ? ident2.substr(2, ident2.length-3) : null; // remove (i and ), to leave number. This value is important in float ops + function integerizeBignum(value) { + return '(tempNumber=(' + value + '), tempNumber-tempNumber%1)'; + } + switch (op) { // basic integer ops case 'add': return handleOverflow(ident1 + ' + ' + ident2, bits); @@ -1218,15 +1222,15 @@ function processMathop(item) { with(item) { } } */ - if (bits > 32) return ident1 + '*Math.pow(2,' + ident2 + ')'; + if (bits > 32) return ident1 + '*Math.pow(2,' + ident2 + ')'; // TODO: calculate Math.pow at runtime for consts, and below too return ident1 + ' << ' + ident2; } case 'ashr': { - if (bits > 32) return ident1 + '/Math.pow(2,' + ident2 + ')'; + if (bits > 32) return integerizeBignum(ident1 + '/Math.pow(2,' + ident2 + ')'); return ident1 + ' >> ' + ident2; } case 'lshr': { - if (bits > 32) return ident1 + '/Math.pow(2,' + ident2 + ')'; + if (bits > 32) return integerizeBignum(ident1 + '/Math.pow(2,' + ident2 + ')'); return ident1 + ' >>> ' + ident2; } // basic float ops diff --git a/src/preamble.js b/src/preamble.js index dccf2c31..ceeca7b6 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -289,6 +289,7 @@ var ABORT = false; var undef = 0; var tempValue; +var tempNumber; function abort(text) { print(text + ':\n' + (new Error).stack); diff --git a/tests/runner.py b/tests/runner.py index 990bc8ea..9a4af753 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -406,10 +406,20 @@ if 'benchmark' not in str(sys.argv): long long x = 0x0000def123450789ULL; // any bigger than this, and we long long y = 0x00020ef123456089ULL; // start to run into the double precision limit! printf("*%Ld,%Ld,%Ld,%Ld,%Ld*\\n", x, y, x | y, x & y, x ^ y, x >> 2, y << 2); + + printf("*"); + long long z = 13; + int n = 0; + while (z > 1) { + printf("%.2f,", (float)z); // these must be integers! + z = z >> 1; + n++; + } + printf("*%d*\\n", n); return 0; } ''' - self.do_test(src, '*245127260211081,579378795077769,808077213656969,16428841631881,791648372025088*') + self.do_test(src, '*245127260211081,579378795077769,808077213656969,16428841631881,791648372025088*\n*13.00,6.00,3.00,*3*') def test_unsigned(self): global CORRECT_SIGNS; CORRECT_SIGNS = 1 # We test for exactly this sort of thing here |