diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/parseTools.js | 10 | ||||
-rw-r--r-- | src/preamble.js | 1 |
2 files changed, 8 insertions, 3 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); |