diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-09-10 18:52:35 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-09-10 18:52:35 -0700 |
commit | fd28971b9a57ee0b9d6237e38fdb75ec2b7b8016 (patch) | |
tree | b5e1d38524e2b2951beecda3bdc8056f4e8b4d05 /src/parseTools.js | |
parent | 5c7eb019a48e181be105964dd0867e28de3e6de8 (diff) |
force shifts on i64s to remain integers
Diffstat (limited to 'src/parseTools.js')
-rw-r--r-- | src/parseTools.js | 10 |
1 files changed, 7 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 |