blob: 4f5a12bbb586d1ca1ae11d65231e25534187950a [file] [log] [blame]
utatane.tea@gmail.comd2de85f2017-02-04 13:46:19 +00001function shouldBe(actual, expected) {
2 if (actual !== expected)
3 throw new Error('bad value: ' + actual);
4}
5
6// ValueToInt32(DoubleRep)
7function toInt32(number)
8{
9 return (number * 0.5) >> 0;
10}
11noInline(toInt32);
12for (var i = 0; i < 1e5; ++i)
13 toInt32(i * 1.0);
14
15function test(number)
16{
17 return toInt32(number * 2);
18}
19
20const INT32_MAX = 2147483647;
21const INT32_MIN = -2147483648;
22
23shouldBe(test(INT32_MAX - 1), INT32_MAX - 1);
24shouldBe(test(INT32_MAX - 0.5), INT32_MAX - 1);
25shouldBe(test(INT32_MAX), INT32_MAX);
26shouldBe(test(INT32_MAX + 0.5), INT32_MAX);
27shouldBe(test(INT32_MAX + 1), INT32_MIN);
28
29shouldBe(test(INT32_MIN - 1), INT32_MAX);
30shouldBe(test(INT32_MIN - 0.5), INT32_MIN);
31shouldBe(test(INT32_MIN), INT32_MIN);
32shouldBe(test(INT32_MIN + 0.5), INT32_MIN + 1);
33shouldBe(test(INT32_MIN + 1), INT32_MIN + 1);
34
35shouldBe(test(Number.EPSILON), 0);
36shouldBe(test(Number.NaN), 0);
37shouldBe(test(Number.POSITIVE_INFINITY), 0);
38shouldBe(test(Number.NEGATIVE_INFINITY), 0);
39shouldBe(test(Number.MAX_SAFE_INTEGER), -1);
40shouldBe(test(Number.MIN_SAFE_INTEGER), 1);