1/* 2 * Copyright (c) 2023 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 16/* 17 * @tc.name:BigInt 18 * @tc.desc:test BigInt 19 * @tc.type: FUNC 20 * @tc.require: issueI7DG0J 21 */ 22 23var number = Number(0x01000000000000080000000000000000000000n) 24print(number) 25 26try { 27 BigInt.asUintN(2147483649, -1873965464n); 28} catch (e) { 29 print("test successful"); 30} 31 32const n1 = Number(0x1fffeffafbfcfen); 33print(n1); 34 35try { 36 print((9007199254740991n + 9007199254740991n) ** 0n); 37 print(0n ** (9007199254740991n + 9007199254740991n)); 38 print((9007199254740991n + 9007199254740991n) ** 9007199254740991n); 39} catch (err) { 40 print(err.name); 41} 42 43try { 44 print(0x4141414141414141n << 0n); 45 print(0n << 0x4141414141414141n); 46 print(0x4141414141414141n << 0x4141414141414141n); 47} catch (err) { 48 print(err.name); 49} 50 51try { 52 const atom = this.Atomics; 53 atom.and(new BigInt64Array(3807), atom, atom); 54} catch (err) { 55 print(err.name) 56} 57 58const v33 = String.fromCharCode(48).padStart(48, String.fromCharCode(48)); 59const v35 = [-1073741824, 2, -9007199254740992]; 60const v42 = Symbol.toPrimitive; 61Symbol.for(v42.description); 62function f36(a37, a38) { 63 try { 64 a37.lastIndexOf(0); 65 } catch (err) { 66 print(err); 67 } 68 return v33; 69} 70v35[v42] = f36; 71let v49 = -12n; 72v49--; 73const v52 = (v49 >> v49).constructor; 74const t48 = v52.__defineSetter__; 75print(v52(v35)); 76 77let map = new Map(); 78let a = BigInt(9007199254740991); 79let b = BigInt(0x1fffffffffffff); 80let c = BigInt(0b11111111111111111111111111111111111111111111111111111); 81let d = BigInt(9007199254740991); 82map.set(a, '1'); 83map.set(b, '2'); 84map.set(c, '3'); 85map.set(d, '4'); 86map.forEach((val,key)=>{ 87 print("map val:" + val, "key :" + key); 88}) 89 90var HashMap = ArkPrivate.Load(ArkPrivate.HashMap); 91let hmap = new HashMap(); 92hmap.set(a, '1'); 93hmap.set(b, '2'); 94hmap.set(c, '3'); 95hmap.set(d, '4'); 96hmap.forEach((val,key)=>{ 97 print("hmap val:" + val, "key :" + key); 98}) 99 100const v83 = new BigUint64Array(1096); 101try { 102 v83["toLocaleString"]("toLocaleString", "toLocaleString"); 103} catch (error) { 104 print(error); 105} 106 107print(BigInt.asUintN(2**32, 42n)); 108print(BigInt.asIntN(2**32, 42n)); 109print((1n)<<(61n)>>(61n)); 110