bigint-and-number.js (2638B)
1 // Copyright (C) 2017 Robin Templeton. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 description: Comparisons of BigInt and Number values 5 esid: sec-abstract-relational-comparison 6 info: | 7 ... 8 3. If both px and py are Strings, then 9 ... 10 4. Else, 11 a. Let nx be ? ToNumeric(px). Because px and py are primitive values evaluation order is not important. 12 b. Let ny be ? ToNumeric(py). 13 c. If Type(nx) is Type(ny), return ? Type(nx)::lessThan(nx, ny). 14 d. Assert: Type(nx) is BigInt and Type(ny) is Number, or if Type(nx) is Number and Type(ny) is BigInt. 15 e. If x or y are any of NaN, return undefined. 16 f. If x is -∞, or y is +∞, return true. 17 g. If x is +∞, or y is -∞, return false. 18 h. If the mathematical value of nx is less than the mathematical value of ny, return true, otherwise return false. 19 features: [BigInt] 20 ---*/ 21 assert.sameValue(0n >= 0, true, 'The result of (0n >= 0) is true'); 22 assert.sameValue(0 >= 0n, true, 'The result of (0 >= 0n) is true'); 23 assert.sameValue(0n >= -0, true, 'The result of (0n >= -0) is true'); 24 assert.sameValue(-0 >= 0n, true, 'The result of (-0 >= 0n) is true'); 25 assert.sameValue(0n >= 0.000000000001, false, 'The result of (0n >= 0.000000000001) is false'); 26 assert.sameValue(0.000000000001 >= 0n, true, 'The result of (0.000000000001 >= 0n) is true'); 27 assert.sameValue(0n >= 1, false, 'The result of (0n >= 1) is false'); 28 assert.sameValue(1 >= 0n, true, 'The result of (1 >= 0n) is true'); 29 assert.sameValue(1n >= 0, true, 'The result of (1n >= 0) is true'); 30 assert.sameValue(0 >= 1n, false, 'The result of (0 >= 1n) is false'); 31 assert.sameValue(1n >= 0.999999999999, true, 'The result of (1n >= 0.999999999999) is true'); 32 assert.sameValue(0.999999999999 >= 1n, false, 'The result of (0.999999999999 >= 1n) is false'); 33 assert.sameValue(1n >= 1, true, 'The result of (1n >= 1) is true'); 34 assert.sameValue(1 >= 1n, true, 'The result of (1 >= 1n) is true'); 35 assert.sameValue(0n >= Number.MIN_VALUE, false, 'The result of (0n >= Number.MIN_VALUE) is false'); 36 assert.sameValue(Number.MIN_VALUE >= 0n, true, 'The result of (Number.MIN_VALUE >= 0n) is true'); 37 assert.sameValue(0n >= -Number.MIN_VALUE, true, 'The result of (0n >= -Number.MIN_VALUE) is true'); 38 39 assert.sameValue( 40 -Number.MIN_VALUE >= 0n, 41 false, 42 'The result of (-Number.MIN_VALUE >= 0n) is false' 43 ); 44 45 assert.sameValue( 46 -10n >= Number.MIN_VALUE, 47 false, 48 'The result of (-10n >= Number.MIN_VALUE) is false' 49 ); 50 51 assert.sameValue( 52 Number.MIN_VALUE >= -10n, 53 true, 54 'The result of (Number.MIN_VALUE >= -10n) is true' 55 ); 56 57 reportCompare(0, 0);