summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/testStringToNumber.js
blob: 7f7aa57266350ccee31f17cc242f028e0f7e21f3 (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
enableOsiPointRegisterChecks();

function convertToInt(str) {
    return str | 0;
}

function convertToIntOnTrace(str) {
    var z;
    for (var i = 0; i < 9; ++i) {
        z = str | 0;
    }
    return z;
}

function convertToDouble(str) {
    return str * 1.5;
}

function convertToDoubleOnTrace(str) {
    var z;
    for (var i = 0; i < 9; ++i) {
        z = str * 1.5;
    }
    return z;
}

assertEq(convertToInt("0x10"), 16);
assertEq(convertToInt("-0x10"), 0);

assertEq(convertToIntOnTrace("0x10"), 16);
assertEq(convertToIntOnTrace("-0x10"), 0);

assertEq(convertToDouble("0x10"), 24);
assertEq(convertToDouble("-0x10"), NaN);

assertEq(convertToDoubleOnTrace("0x10"), 24);
assertEq(convertToDoubleOnTrace("-0x10"), NaN);