tor-browser

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

bigint-not-64-fold.js (1187B)


      1 const tests = [
      2  [-0x8000000000000000n, 0x7fffffffffffffffn],
      3  [-0x7fffffffffffffffn, 0x7ffffffffffffffen],
      4  [-0x7ffffffffffffffen, 0x7ffffffffffffffdn],
      5  [-0x100000001n, 0x100000000n],
      6  [-0x100000000n, 0xffffffffn],
      7  [-0xffffffffn, 0xfffffffen],
      8  [-0xfffffffen, 0xfffffffdn],
      9  [-0x80000001n, 0x80000000n],
     10  [-0x80000000n, 0x7fffffffn],
     11  [-0x7fffffffn, 0x7ffffffen],
     12  [-0x7ffffffen, 0x7ffffffdn],
     13  [-2n, 1n],
     14  [-1n, 0n],
     15  [0n, -1n],
     16  [1n, -2n],
     17  [2n, -3n],
     18  [0x7ffffffen, -0x7fffffffn],
     19  [0x7fffffffn, -0x80000000n],
     20  [0x80000000n, -0x80000001n],
     21  [0x80000001n, -0x80000002n],
     22  [0xfffffffen, -0xffffffffn],
     23  [0xffffffffn, -0x100000000n],
     24  [0x100000000n, -0x100000001n],
     25  [0x100000001n, -0x100000002n],
     26  [0x7ffffffffffffffen, -0x7fffffffffffffffn],
     27  [0x7fffffffffffffffn, -0x8000000000000000n],
     28 ];
     29 
     30 function f(tests) {
     31  for (let test of tests) {
     32    let input = test[0], expected = test[1];
     33    assertEq(BigInt.asIntN(64, input), input);
     34    assertEq(BigInt.asIntN(64, expected), expected);
     35 
     36    let f = Function(`
     37      let input = ${input}n;
     38      assertEq(~input, ${expected}n);
     39    `);
     40 
     41    for (let j = 0; j < 100; ++j) {
     42      f();
     43    }
     44  }
     45 }
     46 
     47 f(tests);