force shifts on i64s to remain integers
This commit is contained in:
Родитель
5c7eb019a4
Коммит
fd28971b9a
|
@ -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
|
||||
|
|
|
@ -289,6 +289,7 @@ var ABORT = false;
|
|||
|
||||
var undef = 0;
|
||||
var tempValue;
|
||||
var tempNumber;
|
||||
|
||||
function abort(text) {
|
||||
print(text + ':\n' + (new Error).stack);
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче