summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/cacheir/parseInt-double-truncate.js
blob: 2b989f2624c4a90a35570c08e0802c52ea27c2e9 (plain)
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
// Test some double-truncation edge cases with parseInt(double).

function testPos1() {
    with({}) {}
    var fun = d => parseInt(d);
    for (var i = 0; i < 2000; i++) {
        assertEq(fun(i + 0.5), i);
    }
    assertEq(fun(0xf_ffff_ffff) + 345, 68719477080);
}
testPos1();

function testPos2() {
    with({}) {}
    var fun = d => parseInt(d);
    for (var i = 0; i < 2000; i++) {
        assertEq(fun(i + 0.5), i);
    }
    assertEq(fun(0x8000_0000) + 345, 2147483993);
}
testPos2();

function testNeg1() {
    with({}) {}
    var fun = d => parseInt(d);
    for (var i = 0; i < 2000; i++) {
        assertEq(fun(i + 0.5), i);
    }
    assertEq(fun(-0xf_ffff_ffff) - 345, -68719477080);
}
testNeg1();

function testNeg2() {
    with({}) {}
    var fun = d => parseInt(d);
    for (var i = 0; i < 2000; i++) {
        assertEq(fun(i + 0.5), i);
    }
    assertEq(fun(-0x8000_0001) - 345, -2147483994);
}
testNeg2();