bigint.js (1621B)
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 /*--- 5 description: Bitwise NOT for BigInt values 6 esid: sec-numeric-types-bigint-bitwiseNOT 7 info: | 8 BigInt::bitwiseNOT (x) 9 10 The abstract operation BigInt::bitwiseNOT with an argument x of BigInt type returns the one's complement of x; that is, -x - 1. 11 12 features: [BigInt] 13 ---*/ 14 15 assert.sameValue(~0n, -1n, "~0n === -1n"); 16 assert.sameValue(~(0n), -1n, "~(0n) === -1n"); 17 assert.sameValue(~1n, -2n, "~1n === -2n"); 18 assert.sameValue(~-1n, 0n, "~-1n === 0n"); 19 assert.sameValue(~(-1n), 0n, "~(-1n) === 0n"); 20 assert.sameValue(~~1n, 1n, "~~1n === 1n"); 21 assert.sameValue(~0x5an, -0x5bn, "~0x5an === -0x5bn"); 22 assert.sameValue(~-0x5an, 0x59n, "~-0x5an === 0x59n"); 23 assert.sameValue(~0xffn, -0x100n, "~0xffn === -0x100n"); 24 assert.sameValue(~-0xffn, 0xfen, "~-0xffn === 0xfen"); 25 assert.sameValue(~0xffffn, -0x10000n, "~0xffffn === -0x10000n"); 26 assert.sameValue(~-0xffffn, 0xfffen, "~-0xffffn === 0xfffen"); 27 assert.sameValue(~0xffffffffn, -0x100000000n, "~0xffffffffn === -0x100000000n"); 28 assert.sameValue(~-0xffffffffn, 0xfffffffen, "~-0xffffffffn === 0xfffffffen"); 29 assert.sameValue( 30 ~0xffffffffffffffffn, -0x10000000000000000n, 31 "~0xffffffffffffffffn === -0x10000000000000000n"); 32 assert.sameValue( 33 ~-0xffffffffffffffffn, 0xfffffffffffffffen, 34 "~-0xffffffffffffffffn === 0xfffffffffffffffen"); 35 assert.sameValue( 36 ~0x123456789abcdef0fedcba9876543210n, -0x123456789abcdef0fedcba9876543211n, 37 "~0x123456789abcdef0fedcba9876543210n === -0x123456789abcdef0fedcba9876543211n"); 38 39 reportCompare(0, 0);