1/* 2 * Copyright (c) 2023-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16function test_bitwise_and(): void { 17 assertEQ(new BigInt(10).operatorBitwiseAnd(new BigInt(2)), (2n)) 18 assertEQ(new BigInt(256).operatorBitwiseAnd(new BigInt(1)), (0n)) 19 assertEQ(new BigInt(3124378143267041203423n).operatorBitwiseAnd(new BigInt(43621978)), (41948250n)) 20 assertEQ(new BigInt(256).operatorBitwiseAnd(new BigInt(256)), (256n)) 21 assertEQ(new BigInt(12345678).operatorBitwiseAnd(new BigInt(1234)), (66n)) 22} 23 24function test_bitwise_or(): void { 25 assertEQ(new BigInt(10).operatorBitwiseOr(new BigInt(2)), (10n)) 26 assertEQ(new BigInt(256).operatorBitwiseOr(new BigInt(1)), (257n)) 27 assertEQ(new BigInt(256).operatorBitwiseOr(new BigInt(256)), (256n)) 28 assertEQ(new BigInt(3124378143267041203423n).operatorBitwiseOr(new BigInt(43621978)), (3124378143267042877151n)) 29 assertEQ(new BigInt(12345678).operatorBitwiseOr(new BigInt(1234)), (12346846n)) 30} 31 32function test_bitwise_xor(): void { 33 assertEQ(new BigInt(10).operatorBitwiseXor(new BigInt(2)), (8n)) 34 assertEQ(new BigInt(256).operatorBitwiseXor(new BigInt(1)), (257n)) 35 assertEQ(new BigInt(256).operatorBitwiseXor(new BigInt(256)), (0n)) 36 assertEQ(new BigInt(3124378143267041203423n).operatorBitwiseXor(new BigInt(43621978)), (3124378143267000928901n)) 37 assertEQ(new BigInt(12345678).operatorBitwiseXor(new BigInt(1234)), (12346780n)) 38} 39 40function test_bitwise(): void { 41 const a = 123456789123456789123456789123456789123456789123456789n 42 let b = 123456790n 43 const zero = 0n 44 45 assertEQ(~zero, -1n) 46 assertEQ(~a, -123456789123456789123456789123456789123456789123456790n) 47} 48 49function main(): void { 50 test_bitwise_and() 51 test_bitwise_or() 52 test_bitwise_xor() 53 test_bitwise() 54} 55