diff --git a/static_core/plugins/ets/stdlib/escompat/BigInt.ets b/static_core/plugins/ets/stdlib/escompat/BigInt.ets index 05417565012f89ed7d65d19cb019ba89f4f4c96d..6d043cb81b0e4b12ec8c4559a4d514f96db682c2 100644 --- a/static_core/plugins/ets/stdlib/escompat/BigInt.ets +++ b/static_core/plugins/ets/stdlib/escompat/BigInt.ets @@ -304,7 +304,7 @@ export final class BigInt { internal toStringAsBinary(): string { let reversedInts = BigInt.reverse(this.bytes) let intToBinaryString = (value: Long) => { return value.toString(2) } - let result = new StringBuilder(intToBinaryString((reversedInts[0]!).toLong())) + let result = new StringBuilder(intToBinaryString((reversedInts[0]!).toLong() & BigInt.maskSys)) for (let i = 1; i < reversedInts.length; ++i) { result = result.append(intToBinaryString((reversedInts[i]).toLong() & BigInt.maskSys).padStart(BigInt.shiftSys, '0')) } diff --git a/static_core/plugins/ets/tests/ets_func_tests/escompat/BigIntTest.ets b/static_core/plugins/ets/tests/ets_func_tests/escompat/BigIntTest.ets index 58808b6ca8641af26e117b0d4675e549b855fa07..daf06397728d4a63d7123740f7ce2faa0bd1895c 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/escompat/BigIntTest.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/escompat/BigIntTest.ets @@ -47,6 +47,30 @@ function testBigIntToString5() { arktest.assertEQ(result, "a") } +function testBigIntToString6() { + let n = -106233993686329866388788451887415352037722042843148312087371682210961017881854n; + let result = n.toString(16); + arktest.assertEQ(result, "-eade4f43ef29faba54e2276cd2fb250b9cfe381912e4cb7b4d98ca527fa544fe") +} + +function testBigIntToString7() { + let n = -24734529127909305130315118443084729844173892131808286553102471449170n; + let result = n.toString(16); + arktest.assertEQ(result, "-eade4f43ef29faba54e2276cd2fb250b9cfe381912e4cb7b4d98ca52") +} + +function testBigIntToString8() { + let n = 17994542461121645181648364671329822175764606026173143432826568886866n; + let result = n.toString(16); + arktest.assertEQ(result, "aade4f43ef29faba54e2276cd2fb250b9cfe381912e4cb7b4d98ca52") +} + +function testBigIntToString9() { + let n = 4581999761941507497992146088338584893584933027760574876539n; + let result = n.toString(16); + arktest.assertEQ(result, "bade4f43ef29faba54e2276cd2fb250b9cfe381912e4cb7b") +} + function testBigIntConstructor1() { let n = BigInt(0x0102030405060708) arktest.assertEQ(n, BigInt("72623859790382848")) @@ -86,6 +110,10 @@ function main(): int { suite.addTest("convert 0b10 to toString(undefined)", testBigIntToString3) suite.addTest("convert 0x10 to toString(undefined)", testBigIntToString4) suite.addTest("test union number|undefined as params for toString", testBigIntToString5) + suite.addTest("convert -106233993686329866388788451887415352037722042843148312087371682210961017881854 to toString(16)",testBigIntToString6) + suite.addTest("convert -24734529127909305130315118443084729844173892131808286553102471449170 to toString(16)",testBigIntToString7) + suite.addTest("convert 17994542461121645181648364671329822175764606026173143432826568886866 to toString(16)",testBigIntToString8) + suite.addTest("convert 4581999761941507497992146088338584893584933027760574876539 to toString(16)",testBigIntToString9) suite.addTest("test large numbers and decimals", testBigIntConstructor1) suite.addTest("test ordinary numbers", testBigIntConstructor2) suite.addTest("test strings", testBigIntConstructor3)