mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:47:45 +00:00
LibJS/Temporal: Perform floating point arithmetic in RoundTime
The valid range for temporal values (`nsMinInstant`/`nsMaxInstant`) means performing nanosecond-valued integers could lead to an overflow. NB: Only the `roundingMode: "day"` case was affected, as all others were already performing the division on floating-point `fractional_second` values. I'm adding `.0` suffixes everywhere to make this fact clearer. This adds a few local tests as well, as those are tested with sanitizers enabled by default, unlike test262.
This commit is contained in:
parent
1dce1994eb
commit
96b197ef46
2 changed files with 25 additions and 3 deletions
|
@ -559,17 +559,17 @@ DaysAndTime round_time(u8 hour, u8 minute, u8 second, u16 millisecond, u16 micro
|
|||
day_length_ns = ns_per_day;
|
||||
|
||||
// b. Let quantity be (((((hour × 60 + minute) × 60 + second) × 1000 + millisecond) × 1000 + microsecond) × 1000 + nanosecond) / dayLengthNs.
|
||||
quantity = (((((hour * 60 + minute) * 60 + second) * 1000 + millisecond) * 1000 + microsecond) * 1000 + nanosecond) / *day_length_ns;
|
||||
quantity = (((((hour * 60.0 + minute) * 60.0 + second) * 1000.0 + millisecond) * 1000.0 + microsecond) * 1000.0 + nanosecond) / *day_length_ns;
|
||||
}
|
||||
// 4. Else if unit is "hour", then
|
||||
else if (unit == "hour"sv) {
|
||||
// a. Let quantity be (fractionalSecond / 60 + minute) / 60 + hour.
|
||||
quantity = (fractional_second / 60 + minute) / 60 + hour;
|
||||
quantity = (fractional_second / 60.0 + minute) / 60.0 + hour;
|
||||
}
|
||||
// 5. Else if unit is "minute", then
|
||||
else if (unit == "minute"sv) {
|
||||
// a. Let quantity be fractionalSecond / 60 + minute.
|
||||
quantity = fractional_second / 60 + minute;
|
||||
quantity = fractional_second / 60.0 + minute;
|
||||
}
|
||||
// 6. Else if unit is "second", then
|
||||
else if (unit == "second"sv) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue