1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:57:44 +00:00

LibJS+LibCrypto: Fix SignedBitInteger::bitwise_not and use it in LibJS

Bitwise operators are defined on two's complement, but SignedBitInteger
uses sign-magnitude. Correctly convert between the two.

Let LibJS delegate to SignedBitInteger for bitwise_not, like it does
for all other bitwise_ operations on bigints.

No behavior change (LibJS is now the only client of
SignedBitInteger::bitwise_not()).
This commit is contained in:
Nico Weber 2022-01-17 12:22:51 -05:00 committed by Ali Mohammad Pur
parent ec37eadb39
commit 945d962322
4 changed files with 15 additions and 5 deletions

View file

@ -467,6 +467,12 @@ TEST_CASE(test_bigint_bitwise_and_different_lengths)
EXPECT_EQ(num1.bitwise_and(num2), "1180290"_bigint);
}
TEST_CASE(test_signed_bigint_bitwise_not)
{
EXPECT_EQ("3"_sbigint.bitwise_not(), "-4"_sbigint);
EXPECT_EQ("-1"_sbigint.bitwise_not(), "0"_sbigint);
}
TEST_CASE(test_signed_bigint_bitwise_and)
{
auto num1 = "-1234567"_sbigint;