tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

bigint-and-number-extremes.js (3835B)


      1 // Copyright (C) 2017 Josh Wolfe. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 description: Comparisons of large 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(1n >= Number.MAX_VALUE, false, 'The result of (1n >= Number.MAX_VALUE) is false');
     22 assert.sameValue(Number.MAX_VALUE >= 1n, true, 'The result of (Number.MAX_VALUE >= 1n) is true');
     23 assert.sameValue(1n >= -Number.MAX_VALUE, true, 'The result of (1n >= -Number.MAX_VALUE) is true');
     24 
     25 assert.sameValue(
     26  -Number.MAX_VALUE >= 1n,
     27  false,
     28  'The result of (-Number.MAX_VALUE >= 1n) is false'
     29 );
     30 
     31 assert.sameValue(
     32  0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn >= Number.MAX_VALUE,
     33  false,
     34  'The result of (0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn >= Number.MAX_VALUE) is false'
     35 );
     36 
     37 assert.sameValue(
     38  Number.MAX_VALUE >= 0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn,
     39  true,
     40  'The result of (Number.MAX_VALUE >= 0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn) is true'
     41 );
     42 
     43 assert.sameValue(
     44  0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n >= Number.MAX_VALUE,
     45  true,
     46  'The result of (0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n >= Number.MAX_VALUE) is true'
     47 );
     48 
     49 assert.sameValue(
     50  Number.MAX_VALUE >= 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n,
     51  false,
     52  'The result of (Number.MAX_VALUE >= 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n) is false'
     53 );
     54 
     55 reportCompare(0, 0);