summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2022-01-17 19:54:02 -0500
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-01-18 20:04:06 +0330
commit1f9863939641793f823bd872b24d26e2df2e8e1e (patch)
tree70f6d7b31dfb795d330ff9b061002053268e649e /Tests
parent945d9623223b307fe3026a5a9753c3ca003646a1 (diff)
downloadserenity-1f9863939641793f823bd872b24d26e2df2e8e1e.zip
LibCrypto+LibJS: Better bigint bitwise_and binop
Bitwise and is defined in terms of two's complement, so some converting needs to happen for SignedBigInteger's sign/magnitude representation to work out. UnsignedBigInteger::bitwise_not() is repurposed to convert all high-order zero bits to ones up to a limit, for the two's complement conversion to work. Fixes test262/test/language/expressions/bitwise-and/bigint.js.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/LibCrypto/TestBigInteger.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/Tests/LibCrypto/TestBigInteger.cpp b/Tests/LibCrypto/TestBigInteger.cpp
index 16cf58ae8c..8a58102cb9 100644
--- a/Tests/LibCrypto/TestBigInteger.cpp
+++ b/Tests/LibCrypto/TestBigInteger.cpp
@@ -478,9 +478,11 @@ TEST_CASE(test_signed_bigint_bitwise_and)
auto num1 = "-1234567"_sbigint;
auto num2 = "1234567"_sbigint;
EXPECT_EQ(num1.bitwise_and(num1), num1);
- EXPECT_EQ(num1.bitwise_and(num2), num2);
- EXPECT_EQ(num2.bitwise_and(num1), num2);
+ EXPECT_EQ(num1.bitwise_and(num2), "1"_sbigint);
+ EXPECT_EQ(num2.bitwise_and(num1), "1"_sbigint);
EXPECT_EQ(num2.bitwise_and(num2), num2);
+
+ EXPECT_EQ("-3"_sbigint.bitwise_and("-2"_sbigint), "-4"_sbigint);
}
TEST_CASE(test_bigint_bitwise_xor)