summaryrefslogtreecommitdiff
path: root/js/src/jit-test/tests/ion/doubleComparisons.js
blob: e9f78382a6dc901865d62d13b5e82312689bd887 (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
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
77
78
79
80
81
82
83
84
85
86
87
88

function gen_f(x) {
    var f = "{\n" +
	    "    var x = " + x + ";\n" + 
	    "    if (x)\n" +
	    "        return true;\n" +
	    "    return false;\n" +
	    "}";
    return new Function(f);
}

function run_f(x) {
    return gen_f(x)();
}

function gen_k(x, op, y) {
    var f = "{\n" +
	    "    var x = " + x + ";\n" +
	    "    var y = " + y + ";\n" +
	    "    if (x " + op + " y)\n" +
	    "        return true;\n" +
	    "    return false;\n" +
	    "}";
    return new Function(f);
}

function run_k(x, op, y) {
    return gen_k(x, op, y)();
}

function gen_r(x, op, y) {
    var f = "{\n" +
	    "    var x = " + x + ";\n" +
	    "    var y = " + y + ";\n" +
	    "    return x " + op + " y;\n" +
	    "}";
    return new Function(f);
}

function run_r(x, op, y) {
    return gen_r(x, op, y)();
}

assertEq(run_f("1 / 0"), true);
assertEq(run_f("0 / 0"), false);
assertEq(run_f("-0"), false);
assertEq(run_f(1.3), true);

// Ordered results.
assertEq(run_k(1.3, ">", 2.3), false);
assertEq(run_k(2.3, ">", 2.3), false);
assertEq(run_k(2.4, ">", 2.3), true);
assertEq(run_k(1.3, ">=", 2.3), false);
assertEq(run_k(2.3, ">=", 2.3), true);
assertEq(run_k(2.4, ">=", 2.3), true);
assertEq(run_k(1.3, "<", 2.3), true);
assertEq(run_k(2.3, "<", 2.3), false);
assertEq(run_k(2.4, "<", 2.3), false);
assertEq(run_k(1.3, "<", 2.3), true);
assertEq(run_k(2.3, "<=", 2.3), true);
assertEq(run_k(2.4, "<", 2.3), false);

// Unordered results.
assertEq(run_k("NaN", "<", 2.5), false);
assertEq(run_k("NaN", "<=", 2.5), false);
assertEq(run_k("NaN", ">", 2.5), false);
assertEq(run_k("NaN", ">=", 2.5), false);

// Ordered results.
assertEq(run_r(1.3, ">", 2.3), false);
assertEq(run_r(2.3, ">", 2.3), false);
assertEq(run_r(2.4, ">", 2.3), true);
assertEq(run_r(1.3, ">=", 2.3), false);
assertEq(run_r(2.3, ">=", 2.3), true);
assertEq(run_r(2.4, ">=", 2.3), true);
assertEq(run_r(1.3, "<", 2.3), true);
assertEq(run_r(2.3, "<", 2.3), false);
assertEq(run_r(2.4, "<", 2.3), false);
assertEq(run_r(1.3, "<", 2.3), true);
assertEq(run_r(2.3, "<=", 2.3), true);
assertEq(run_r(2.4, "<", 2.3), false);

// Unordered results.
assertEq(run_r("NaN", "<", 2.5), false);
assertEq(run_r("NaN", "<=", 2.5), false);
assertEq(run_r("NaN", ">", 2.5), false);
assertEq(run_r("NaN", ">=", 2.5), false);