forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathany-int-as-double-add.js
43 lines (32 loc) · 1.08 KB
/
any-int-as-double-add.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function shouldBe(actual, expected)
{
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var array = [];
for (var i = 0; i < 100; ++i)
array.push(1024 * 1024 * 1024 * 1024 + i);
for (var i = 0; i < 100; ++i)
array.push(-(1024 * 1024 * 1024 * 1024 + i));
array.push(2251799813685248);
array.push(0.5);
function test(array, index, value)
{
return array[index] + fiatInt52(value);
}
noInline(test);
for (var i = 0; i < 1e4; ++i) {
for (var index = 0; index < 100; ++index)
shouldBe(test(array, index, 20), 1024 * 1024 * 1024 * 1024 + index + 20);
for (var index = 0; index < 100; ++index)
shouldBe(test(array, index + 100, 20), -(1024 * 1024 * 1024 * 1024 + index) + 20);
}
// Int52Overflow.
shouldBe(test(array, 200, 200), 2251799813685448);
// Not AnyIntAsDouble, Int52Overflow.
shouldBe(test(array, 201, 200), 200.5);
// Recompile the code as ArithAdd(Double, Double).
for (var i = 0; i < 1e4; ++i)
shouldBe(test(array, 201, 200), 200.5);
shouldBe(test(array, 200, 200), 2251799813685448);
shouldBe(test(array, 201, 200), 200.5);