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:
Timothy Flynn 2022-01-15 17:36:25 -05:00 committed by Andreas Kling
parent 8d30e14d28
commit 8ad043fe5e
Notes: sideshowbarker 2024-07-17 20:47:39 +09:00

View File

@ -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