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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Test Math.trunc() for IonMonkey.
// Requires --ion-eager to enter at the top of each loop.
var truncDITests = [
[0.49999999999999997, 0],
[0.5, 0],
[1.0, 1],
[1.5, 1],
[792.8, 792],
[-1.0001, -1],
[-3.14, -3],
[2137483649.5, 2137483649],
[2137483648.5, 2137483648],
[2137483647.1, 2137483647],
[-2147483647.8, -2147483647],
];
var truncDITests_bailout = [
...truncDITests,
// Bailout in bailoutCvttsd2si: https://bugzil.la/1379626#c1
[-2147483648.8, -2147483648],
];
var truncDTests = [
[-0, -0],
[0.49999999999999997, 0],
[0.5, 0],
[1.0, 1],
[1.5, 1],
[792.8, 792],
[-0.1, -0],
[-1.0001, -1],
[-3.14, -3],
[2137483649.5, 2137483649],
[2137483648.5, 2137483648],
[2137483647.1, 2137483647],
[900000000000, 900000000000],
[-0, -0],
[-Infinity, -Infinity],
[Infinity, Infinity],
[NaN, NaN],
[-2147483648.8, -2147483648],
[-2147483649.8, -2147483649],
];
var truncITests = [
[0, 0],
[4, 4],
[-1, -1],
[-7, -7],
[2147483647, 2147483647],
];
// Typed functions to be compiled by Ion.
function truncDI(x) { return Math.trunc(x); }
function truncDI_bailout(x) { return Math.trunc(x); }
function truncD(x) { return Math.trunc(x); }
function truncI(x) { return Math.trunc(x); }
function test() {
// Always run this function in the interpreter.
with ({}) {}
for (var i = 0; i < truncDITests.length; i++)
assertEq(truncDI(truncDITests[i][0]), truncDITests[i][1]);
for (var i = 0; i < truncDITests_bailout.length; i++)
assertEq(truncDI_bailout(truncDITests_bailout[i][0]), truncDITests_bailout[i][1]);
for (var i = 0; i < truncDTests.length; i++)
assertEq(truncD(truncDTests[i][0]), truncDTests[i][1]);
for (var i = 0; i < truncITests.length; i++)
assertEq(truncI(truncITests[i][0]), truncITests[i][1]);
}
for (var i = 0; i < 40; i++)
test();
|