diff options
author | Nico Weber <thakis@chromium.org> | 2022-01-17 12:22:51 -0500 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-01-18 20:04:06 +0330 |
commit | 945d9623223b307fe3026a5a9753c3ca003646a1 (patch) | |
tree | 9994319c8388f2faffe9c4419362f9585147944f /Tests/LibCrypto/TestBigInteger.cpp | |
parent | ec37eadb394a2aef8ccc3326611ee0b2fb3ce8c7 (diff) | |
download | serenity-945d9623223b307fe3026a5a9753c3ca003646a1.zip |
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()).
Diffstat (limited to 'Tests/LibCrypto/TestBigInteger.cpp')
-rw-r--r-- | Tests/LibCrypto/TestBigInteger.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Tests/LibCrypto/TestBigInteger.cpp b/Tests/LibCrypto/TestBigInteger.cpp index 504fb4eab1..16cf58ae8c 100644 --- a/Tests/LibCrypto/TestBigInteger.cpp +++ b/Tests/LibCrypto/TestBigInteger.cpp @@ -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; |