arithmetic.js (2904B)
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 esid: sec-bigint.asintn 5 description: BigInt.asIntN arithmetic test cases 6 info: | 7 BigInt.asIntN ( bits, bigint ) 8 9 3. Let mod be a BigInt representing bigint modulo 2**bits. 10 4. If mod ≥ 2**bits - 1, return mod - 2**bits; otherwise, return mod. 11 12 features: [BigInt] 13 ---*/ 14 15 assert.sameValue(BigInt.asIntN(0, -2n), 0n); 16 assert.sameValue(BigInt.asIntN(0, -1n), 0n); 17 assert.sameValue(BigInt.asIntN(0, 0n), 0n); 18 assert.sameValue(BigInt.asIntN(0, 1n), 0n); 19 assert.sameValue(BigInt.asIntN(0, 2n), 0n); 20 21 assert.sameValue(BigInt.asIntN(1, -3n), -1n); 22 assert.sameValue(BigInt.asIntN(1, -2n), 0n); 23 assert.sameValue(BigInt.asIntN(1, -1n), -1n); 24 assert.sameValue(BigInt.asIntN(1, 0n), 0n); 25 assert.sameValue(BigInt.asIntN(1, 1n), -1n); 26 assert.sameValue(BigInt.asIntN(1, 2n), 0n); 27 assert.sameValue(BigInt.asIntN(1, 3n), -1n); 28 assert.sameValue(BigInt.asIntN(1, -123456789012345678901n), -1n); 29 assert.sameValue(BigInt.asIntN(1, -123456789012345678900n), 0n); 30 assert.sameValue(BigInt.asIntN(1, 123456789012345678900n), 0n); 31 assert.sameValue(BigInt.asIntN(1, 123456789012345678901n), -1n); 32 33 assert.sameValue(BigInt.asIntN(2, -3n), 1n); 34 assert.sameValue(BigInt.asIntN(2, -2n), -2n); 35 assert.sameValue(BigInt.asIntN(2, -1n), -1n); 36 assert.sameValue(BigInt.asIntN(2, 0n), 0n); 37 assert.sameValue(BigInt.asIntN(2, 1n), 1n); 38 assert.sameValue(BigInt.asIntN(2, 2n), -2n); 39 assert.sameValue(BigInt.asIntN(2, 3n), -1n); 40 assert.sameValue(BigInt.asIntN(2, -123456789012345678901n), -1n); 41 assert.sameValue(BigInt.asIntN(2, -123456789012345678900n), 0n); 42 assert.sameValue(BigInt.asIntN(2, 123456789012345678900n), 0n); 43 assert.sameValue(BigInt.asIntN(2, 123456789012345678901n), 1n); 44 45 assert.sameValue(BigInt.asIntN(8, 0xabn), -0x55n); 46 assert.sameValue(BigInt.asIntN(8, 0xabcdn), -0x33n); 47 assert.sameValue(BigInt.asIntN(8, 0xabcdef01n), 0x01n); 48 assert.sameValue(BigInt.asIntN(8, 0xabcdef0123456789abcdef0123n), 0x23n); 49 assert.sameValue(BigInt.asIntN(8, 0xabcdef0123456789abcdef0183n), -0x7dn); 50 51 assert.sameValue(BigInt.asIntN(64, 0xabcdef0123456789abcdefn), 0x0123456789abcdefn); 52 assert.sameValue(BigInt.asIntN(65, 0xabcdef0123456789abcdefn), -0xfedcba9876543211n); 53 54 assert.sameValue(BigInt.asIntN(200, 55 0xcffffffffffffffffffffffffffffffffffffffffffffffffffn), -0x00000000000000000000000000000000000000000000000001n); 56 assert.sameValue(BigInt.asIntN(201, 57 0xcffffffffffffffffffffffffffffffffffffffffffffffffffn), 58 0xffffffffffffffffffffffffffffffffffffffffffffffffffn 59 ); 60 61 assert.sameValue(BigInt.asIntN(200, 62 0xc89e081df68b65fedb32cffea660e55df9605650a603ad5fc54n), -0x761f7e209749a0124cd3001599f1aa2069fa9af59fc52a03acn); 63 assert.sameValue(BigInt.asIntN(201, 64 0xc89e081df68b65fedb32cffea660e55df9605650a603ad5fc54n), 65 0x89e081df68b65fedb32cffea660e55df9605650a603ad5fc54n 66 ); 67 68 reportCompare(0, 0);