mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +03:00
LibJS: Ensure final computation in DayFromYear is performed on a double
When we multiple by 365, ensure the result is a double (not an i32) to prevent overflow.
This commit is contained in:
parent
8d30e14d28
commit
8ad043fe5e
Notes:
sideshowbarker
2024-07-17 20:47:39 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/8ad043fe5e0 Pull-request: https://github.com/SerenityOS/serenity/pull/11930 Reviewed-by: https://github.com/linusg ✅
@ -133,7 +133,7 @@ u16 days_in_year(i32 y)
|
||||
double day_from_year(i32 y)
|
||||
{
|
||||
// 𝔽(365 × (ℝ(y) - 1970) + floor((ℝ(y) - 1969) / 4) - floor((ℝ(y) - 1901) / 100) + floor((ℝ(y) - 1601) / 400))
|
||||
return 365 * (y - 1970) + floor((y - 1969) / 4.0) - floor((y - 1901) / 100.0) + floor((y - 1601) / 400.0);
|
||||
return 365.0 * (y - 1970) + floor((y - 1969) / 4.0) - floor((y - 1901) / 100.0) + floor((y - 1601) / 400.0);
|
||||
}
|
||||
|
||||
// TimeFromYear(y), https://tc39.es/ecma262/#eqn-TimeFromYear
|
||||
|
Loading…
Reference in New Issue
Block a user