mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
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.
This commit is contained in:
parent
28a8e4a105
commit
656efe5d6c
1 changed files with 2 additions and 1 deletions
|
@ -760,7 +760,8 @@ ThrowCompletionOr<RoundedDuration> 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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue