bigint-and-number.js (2639B)
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, true, 'The result of (0n <= 0.000000000001) is true'); 26 assert.sameValue(0.000000000001 <= 0n, false, 'The result of (0.000000000001 <= 0n) is false'); 27 assert.sameValue(0n <= 1, true, 'The result of (0n <= 1) is true'); 28 assert.sameValue(1 <= 0n, false, 'The result of (1 <= 0n) is false'); 29 assert.sameValue(1n <= 0, false, 'The result of (1n <= 0) is false'); 30 assert.sameValue(0 <= 1n, true, 'The result of (0 <= 1n) is true'); 31 assert.sameValue(1n <= 0.999999999999, false, 'The result of (1n <= 0.999999999999) is false'); 32 assert.sameValue(0.999999999999 <= 1n, true, 'The result of (0.999999999999 <= 1n) is true'); 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, true, 'The result of (0n <= Number.MIN_VALUE) is true'); 36 assert.sameValue(Number.MIN_VALUE <= 0n, false, 'The result of (Number.MIN_VALUE <= 0n) is false'); 37 38 assert.sameValue( 39 0n <= -Number.MIN_VALUE, 40 false, 41 'The result of (0n <= -Number.MIN_VALUE) is false' 42 ); 43 44 assert.sameValue(-Number.MIN_VALUE <= 0n, true, 'The result of (-Number.MIN_VALUE <= 0n) is true'); 45 46 assert.sameValue( 47 -10n <= Number.MIN_VALUE, 48 true, 49 'The result of (-10n <= Number.MIN_VALUE) is true' 50 ); 51 52 assert.sameValue( 53 Number.MIN_VALUE <= -10n, 54 false, 55 'The result of (Number.MIN_VALUE <= -10n) is false' 56 ); 57 58 reportCompare(0, 0);