From 656efe5d6c160e6f3102d6d4ac164f21283a7af8 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 13 Nov 2021 16:53:12 +0000 Subject: [PATCH] LibJS: Fix days calculation in round_duration() for "year" - "day" units This relies on floating point division, which is not possible with LibCrypto bigints at the moment. So, instead of completely ignoring the remainder we now first do a bigint division, then convert the remainder to a double, and do another native floating point division to get the final result. --- Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp index 034bbfc4d0..6b9e1cf279 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp @@ -760,7 +760,8 @@ ThrowCompletionOr round_duration(GlobalObject& global_object, d auto result = TRY(nanoseconds_to_days(global_object, *nanoseconds_bigint, intermediate)); // e. Set days to days + result.[[Days]] + result.[[Nanoseconds]] / result.[[DayLength]]. - days += result.days + result.nanoseconds.cell()->big_integer().divided_by(Crypto::UnsignedBigInteger::create_from((u64)result.day_length)).quotient.to_double(); + auto nanoseconds_division_result = result.nanoseconds.cell()->big_integer().divided_by(Crypto::UnsignedBigInteger::create_from((u64)result.day_length)); + days += result.days + nanoseconds_division_result.quotient.to_double() + nanoseconds_division_result.remainder.to_double() / result.day_length; // f. Set hours, minutes, seconds, milliseconds, microseconds, and nanoseconds to 0. hours = 0;