bigint-and-number.js (2593B)
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, false, 'The result of (0n > 0) is false'); 22 assert.sameValue(0 > 0n, false, 'The result of (0 > 0n) is false'); 23 assert.sameValue(0n > -0, false, 'The result of (0n > -0) is false'); 24 assert.sameValue(-0 > 0n, false, 'The result of (-0 > 0n) is false'); 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, false, 'The result of (1n > 1) is false'); 34 assert.sameValue(1 > 1n, false, 'The result of (1 > 1n) is false'); 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 assert.sameValue(-Number.MIN_VALUE > 0n, false, 'The result of (-Number.MIN_VALUE > 0n) is false'); 39 40 assert.sameValue( 41 -10n > Number.MIN_VALUE, 42 false, 43 'The result of (-10n > Number.MIN_VALUE) is false' 44 ); 45 46 assert.sameValue(Number.MIN_VALUE > -10n, true, 'The result of (Number.MIN_VALUE > -10n) is true'); 47 48 reportCompare(0, 0);