mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 14:14:45 +03:00
LibCrypto+LibJS: Better bitwise binary_xor binop
We went through some trouble to make & and | work right. Reimplement ^ in terms of & and | to make ^ work right as well. This is less fast than a direct implementation, but let's get things working first.
This commit is contained in:
parent
013799a4dd
commit
d9b6eb29bc
Notes:
sideshowbarker
2024-07-18 03:35:30 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/d9b6eb29bcd Pull-request: https://github.com/SerenityOS/serenity/pull/11996 Reviewed-by: https://github.com/alimpfard
@ -526,8 +526,8 @@ TEST_CASE(test_signed_bigint_bitwise_xor)
|
||||
auto num1 = "-3"_sbigint;
|
||||
auto num2 = "1"_sbigint;
|
||||
EXPECT_EQ(num1.bitwise_xor(num1), "0"_sbigint);
|
||||
EXPECT_EQ(num1.bitwise_xor(num2), "-2"_sbigint);
|
||||
EXPECT_EQ(num2.bitwise_xor(num1), "-2"_sbigint);
|
||||
EXPECT_EQ(num1.bitwise_xor(num2), "-4"_sbigint);
|
||||
EXPECT_EQ(num2.bitwise_xor(num1), "-4"_sbigint);
|
||||
EXPECT_EQ(num2.bitwise_xor(num2), "0"_sbigint);
|
||||
}
|
||||
|
||||
|
@ -238,12 +238,7 @@ FLATTEN SignedBigInteger SignedBigInteger::bitwise_and(const SignedBigInteger& o
|
||||
|
||||
FLATTEN SignedBigInteger SignedBigInteger::bitwise_xor(const SignedBigInteger& other) const
|
||||
{
|
||||
auto result = bitwise_xor(other.unsigned_value());
|
||||
|
||||
// The sign bit will have to be XOR'd manually.
|
||||
result.m_sign = is_negative() ^ other.is_negative();
|
||||
|
||||
return result;
|
||||
return bitwise_or(other).minus(bitwise_and(other));
|
||||
}
|
||||
|
||||
bool SignedBigInteger::operator==(const UnsignedBigInteger& other) const
|
||||
|
Loading…
Reference in New Issue
Block a user