[JSC] Do not use asArrayModes() with Structures because it discards TypedArray inform...
[WebKit-https.git] / JSTests / stress / big-int-greater-than-or-equal.js
1 //@ runBigIntEnabled
2
3 // Copyright (C) 2017 Josh Wolfe. All rights reserved.
4 // Copyright (C) 2018 Igalia, S.L. All rights reserved.
5 // This code is governed by the BSD license found in the LICENSE file.
6
7 function assert(v, e, m) {
8     if (v !== e)
9         throw new Error(m);
10 }
11
12 assert(0n >= 0n, true, "0n >= 0n");
13 assert(1n >= 1n, true, "1n >= 1n");
14 assert(BigInt("-1") >= BigInt("-1"), true, "-1n >= -1n");
15 assert(0n >= BigInt("-0"), true, "0n >= -0n");
16 assert(BigInt("-0") >= 0n, true, "-0n >= 0n");
17 assert(0n >= 1n, false, "0n >= 1n");
18 assert(1n >= 0n, true, "1n >= 0n");
19 assert(0n >= BigInt("-1"), true, "0n >= -1n");
20 assert(BigInt("-1") >= 0n, false, "-1n >= 0n");
21 assert(1n >= BigInt("-1"), true, "1n >= -1n");
22 assert(BigInt("-1") >= 1n, false, "-1n >= 1n");
23 assert(0x1fffffffffffff01n >= 0x1fffffffffffff02n, false, "0x1fffffffffffff01n >= 0x1fffffffffffff02n");
24 assert(0x1fffffffffffff02n >= 0x1fffffffffffff01n, true, "0x1fffffffffffff02n >= 0x1fffffffffffff01n");
25 assert(BigInt("-2305843009213693697") >= BigInt("-2305843009213693698"), true, "-2305843009213693697n >= -2305843009213693698n");
26 assert(BigInt("-2305843009213693698") >= BigInt("-2305843009213693697"), false, "-2305843009213693698n >= -2305843009213693697n");
27 assert(0x10000000000000000n >= 0n, true, "0x10000000000000000n >= 0n");
28 assert(0n >= 0x10000000000000000n, false, "0n >= 0x10000000000000000n");
29 assert(0x10000000000000000n >= 1n, true, "0x10000000000000000n >= 1n");
30 assert(1n >= 0x10000000000000000n, false, "1n >= 0x10000000000000000n");
31 assert(0x10000000000000000n >= BigInt("-1"), true, "0x10000000000000000n >= -1n");
32 assert(BigInt("-1") >= 0x10000000000000000n, false, "-1n >= 0x10000000000000000n");
33 assert(0x10000000000000001n >= 0n, true, "0x10000000000000001n >= 0n");
34 assert(0n >= 0x10000000000000001n, false, "0n >= 0x10000000000000001n");
35 assert(BigInt("-18446744073709551616") >= 0n, false, "-18446744073709551616n >= 0n");
36 assert(0n >= BigInt("-18446744073709551616"), true, "0n >= -18446744073709551616n");
37 assert(BigInt("-18446744073709551616") >= 1n, false, "-18446744073709551616n >= 1n");
38 assert(1n >= BigInt("-18446744073709551616"), true, "1n >= -18446744073709551616n");
39 assert(BigInt("-18446744073709551616") >= BigInt("-1"), false, "-18446744073709551616n >= -1n");
40 assert(BigInt("-1") >= BigInt("-18446744073709551616"), true, "-1n >= -18446744073709551616n");
41 assert(BigInt("-18446744073709551617") >= 0n, false, "-18446744073709551617n >= 0n");
42 assert(0n >= BigInt("-18446744073709551617"), true, "0n >= -18446744073709551617n");
43 assert(0x10000000000000000n >= 0x100000000n, true, "0x10000000000000000n >= 0x100000000n");
44 assert(0x100000000n >= 0x10000000000000000n, false, "0x100000000n >= 0x10000000000000000n");
45
46 // BigInt - String
47
48 assert(0n >= "0", true, "0n >= '0'");
49 assert("0" >= 0n, true, "'0' >= 0n");
50 assert(0n >= "1", false, "0n >= '1'");
51 assert("0" >= 1n, false, "'0' >= 1n");
52 assert(1n >= "0", true, "1n >= '0'");
53 assert("1" >= 0n, true, "'1' >= 0n");
54 assert(0n >= "", true, "0n >= ''");
55 assert("" >= 0n, true, "'' >= 0n");
56 assert(0n >= "1", false, "0n >= '1'");
57 assert("" >= 1n, false, "'' >= 1n");
58 assert(1n >= "", true, "1n >= ''");
59 assert(1n >= "1", true, "1n >= '1'");
60 assert("1" >= 1n, true, "'1' >= 1n");
61 assert(1n >= "-1", true, "1n >= '-1'");
62 assert("1" >= BigInt("-1"), true, "'1' >= -1n");
63 assert(BigInt("-1") >= "1", false, "-1n >= '1'");
64 assert("-1" >= 1n, false, "'-1' >= 1n");
65 assert(BigInt("-1") >= "-1", true, "-1n >= '-1'");
66 assert("-1" >= BigInt("-1"), true, "'-1' >= -1n");
67 assert(9007199254740993n >= "9007199254740992", true, "9007199254740993n >= '9007199254740992'");
68 assert("9007199254740993" >= 9007199254740992n, true, "'9007199254740993' >= 9007199254740992n");
69 assert(BigInt("-9007199254740992") >= "-9007199254740993", true, "-9007199254740992n >= '-9007199254740993'");
70 assert("-9007199254740992" >= BigInt("-9007199254740993"), true, "'-9007199254740992' >= -9007199254740993n");
71 assert("0x10" >= 14n, true, "'0x10' >= 3n");
72 assert("0b10" >= 2n, true, "'0b10' >= 2n");
73 assert("0b10" >= 1n, true, "'0b10' >= 1n");
74
75 // Invalid String
76
77 assert("b10" >= 2n, false, "'b10' >= 2n");
78 assert("bbb10" >= 2n, false, "'bbb10' >= 2n");
79
80 // BigInt - Number
81
82 assert(0n >= 0, true, "0n >= 0");
83 assert(0 >= 0n, true, "0 >= 0n");
84 assert(0n >= -0, true, "0n >= -0");
85 assert(-0 >= 0n, true, "-0 >= 0n");
86 assert(0n >= 0.000000000001, false, "0n >= 0.000000000001");
87 assert(0.000000000001 >= 0n, true, "0.000000000001 >= 0n");
88 assert(0n >= 1, false, "0n >= 1");
89 assert(1 >= 0n, true, "1 >= 0n");
90 assert(1n >= 0, true, "1n >= 0");
91 assert(0 >= 1n, false, "0 >= 1n");
92 assert(1n >= 0.999999999999, true, "1n >= 0.999999999999");
93 assert(0.999999999999 >= 1n, false, "0.999999999999 >= 1n");
94 assert(1n >= 1, true, "1n >= 1");
95 assert(1 >= 1n, true, "1 >= 1n");
96 assert(0n >= Number.MIN_VALUE, false, "0n >= Number.MIN_VALUE");
97 assert(Number.MIN_VALUE >= 0n, true, "Number.MIN_VALUE >= 0n");
98 assert(0n >= -Number.MIN_VALUE, true, "0n >= -Number.MIN_VALUE");
99 assert(-Number.MIN_VALUE >= 0n, false, "-Number.MIN_VALUE >= 0n");
100 assert(BigInt("-10") >= Number.MIN_VALUE, false, "-10n >= Number.MIN_VALUE");
101 assert(Number.MIN_VALUE >= BigInt("-10"), true, "Number.MIN_VALUE >= -10n");
102 assert(1n >= Number.MAX_VALUE, false, "1n >= Number.MAX_VALUE");
103 assert(Number.MAX_VALUE >= 1n, true, "Number.MAX_VALUE >= 1n");
104 assert(1n >= -Number.MAX_VALUE, true, "1n >= -Number.MAX_VALUE");
105 assert(-Number.MAX_VALUE >= 1n, false, "-Number.MAX_VALUE >= 1n");
106 assert(0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn >= Number.MAX_VALUE, false, "0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn >= Number.MAX_VALUE");
107 assert(Number.MAX_VALUE >= 0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn, true, "Number.MAX_VALUE >= 0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn");
108 assert(0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n >= Number.MAX_VALUE, true, "0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n >= Number.MAX_VALUE");
109 assert(Number.MAX_VALUE >= 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n, false, "Number.MAX_VALUE >= 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n");
110 assert(1n >= Infinity, false, "1n >= Infinity");
111 assert(Infinity >= 1n, true, "Infinity >= 1n");
112 assert(BigInt("-1") >= Infinity, false, "-1n >= Infinity");
113 assert(Infinity >= BigInt("-1"), true, "Infinity >= -1n");
114 assert(1n >= -Infinity, true, "1n >= -Infinity");
115 assert(-Infinity >= 1n, false, "-Infinity >= 1n");
116 assert(BigInt("-1") >= -Infinity, true, "-1n >= -Infinity");
117 assert(-Infinity >= BigInt("-1"), false, "-Infinity >= -1n");
118 assert(0n >= NaN, false, "0n >= NaN");
119 assert(NaN >= 0n, false, "NaN >= 0n");
120
121 // BigInt - Boolean
122
123 assert(false >= 1n, false, "false >= 1n");
124 assert(1n >= false, true, "1n >= false");
125 assert(false >= 0n, true, "false >= 0n");
126 assert(0n >= false, true, "0n >= false");
127 assert(true >= 1n, true, "true >= 1n");
128 assert(1n >= true, true, "1n >= true");
129 assert(true >= 2n, false, "true >= 2n");
130 assert(2n >= true, true, "2n >= true");
131
132 // BigInt - Symbol
133
134 try {
135     1n >= Symbol("1");
136     assert(false, true, "Comparison with Symbol shoud throw TypeError, but executed without exception");
137 } catch(e) {
138     assert(e instanceof TypeError, true, "Comparison with Symbol shoud throw TypeError, but throwed something else");
139 }
140