mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:47:44 +00:00
LibCrypto: Add a way to compare UnsignedBigInteger with double
This patch also make SignedBigInteger::compare_to_double make use of the new function.
This commit is contained in:
parent
e03f014e7a
commit
54b8a2b094
7 changed files with 259 additions and 158 deletions
|
@ -1536,7 +1536,7 @@ ThrowCompletionOr<bool> is_loosely_equal(VM& vm, Value lhs, Value rhs)
|
|||
auto& number_side = lhs.is_number() ? lhs : rhs;
|
||||
auto& bigint_side = lhs.is_number() ? rhs : lhs;
|
||||
|
||||
return bigint_side.as_bigint().big_integer().compare_to_double(number_side.as_double()) == Crypto::SignedBigInteger::CompareResult::DoubleEqualsBigInt;
|
||||
return bigint_side.as_bigint().big_integer().compare_to_double(number_side.as_double()) == Crypto::UnsignedBigInteger::CompareResult::DoubleEqualsBigInt;
|
||||
}
|
||||
|
||||
// 14. Return false.
|
||||
|
@ -1635,10 +1635,10 @@ ThrowCompletionOr<TriState> is_less_than(VM& vm, Value lhs, Value rhs, bool left
|
|||
VERIFY(!x_numeric.is_nan() && !y_numeric.is_nan());
|
||||
if (x_numeric.is_number()) {
|
||||
x_lower_than_y = y_numeric.as_bigint().big_integer().compare_to_double(x_numeric.as_double())
|
||||
== Crypto::SignedBigInteger::CompareResult::DoubleLessThanBigInt;
|
||||
== Crypto::UnsignedBigInteger::CompareResult::DoubleLessThanBigInt;
|
||||
} else {
|
||||
x_lower_than_y = x_numeric.as_bigint().big_integer().compare_to_double(y_numeric.as_double())
|
||||
== Crypto::SignedBigInteger::CompareResult::DoubleGreaterThanBigInt;
|
||||
== Crypto::UnsignedBigInteger::CompareResult::DoubleGreaterThanBigInt;
|
||||
}
|
||||
if (x_lower_than_y)
|
||||
return TriState::True;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue