diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-01-15 17:36:25 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-16 11:07:02 +0100 |
commit | 8ad043fe5e0f05bbe654a93a14ecc8269473379b (patch) | |
tree | 76d47d7474cf65f0247324c48fa8ca55ae8d5df0 /Userland/Libraries/LibJS/Runtime/Date.cpp | |
parent | 8d30e14d28d8732760bfd471b46771a9d2ff2f48 (diff) | |
download | serenity-8ad043fe5e0f05bbe654a93a14ecc8269473379b.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Date.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Date.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index 96706e5fb4..152870d0f6 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -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 |