LibJS: Use the UnsignedBigInteger compare_to_double algorithm

This also avoids an unnecessary copy
This commit is contained in:
Moustafa Raafat 2022-10-23 19:53:23 +01:00 committed by Andrew Kaster
parent 54b8a2b094
commit 939374a037
Notes: sideshowbarker 2024-07-17 06:46:15 +09:00

View File

@ -555,8 +555,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM& vm, Crypto::S
return vm.throw_completion<RangeError>(ErrorType::TemporalNanosecondsConvertedToRemainderOfNanosecondsWithOppositeSign); return vm.throw_completion<RangeError>(ErrorType::TemporalNanosecondsConvertedToRemainderOfNanosecondsWithOppositeSign);
// 23. If abs(nanoseconds) ≥ abs(dayLengthNs), throw a RangeError exception. // 23. If abs(nanoseconds) ≥ abs(dayLengthNs), throw a RangeError exception.
auto nanoseconds_absolute = nanoseconds.is_negative() ? nanoseconds.negated_value() : nanoseconds; auto compare_result = nanoseconds.unsigned_value().compare_to_double(fabs(day_length_ns.to_double()));
auto compare_result = nanoseconds_absolute.compare_to_double(fabs(day_length_ns.to_double()));
if (compare_result == Crypto::UnsignedBigInteger::CompareResult::DoubleLessThanBigInt || compare_result == Crypto::UnsignedBigInteger::CompareResult::DoubleEqualsBigInt) if (compare_result == Crypto::UnsignedBigInteger::CompareResult::DoubleLessThanBigInt || compare_result == Crypto::UnsignedBigInteger::CompareResult::DoubleEqualsBigInt)
return vm.throw_completion<RangeError>(ErrorType::TemporalNanosecondsConvertedToRemainderOfNanosecondsLongerThanDayLength); return vm.throw_completion<RangeError>(ErrorType::TemporalNanosecondsConvertedToRemainderOfNanosecondsLongerThanDayLength);