aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-09-10 18:52:35 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-09-10 18:52:35 -0700
commitfd28971b9a57ee0b9d6237e38fdb75ec2b7b8016 (patch)
treeb5e1d38524e2b2951beecda3bdc8056f4e8b4d05
parent5c7eb019a48e181be105964dd0867e28de3e6de8 (diff)
force shifts on i64s to remain integers
-rw-r--r--src/parseTools.js10
-rw-r--r--src/preamble.js1
-rw-r--r--tests/runner.py12
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