diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h index daf2a5ecd7..f73d3bcdaf 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h @@ -300,7 +300,8 @@ auto modulo(T x, U y) if constexpr (IsFloatingPoint || IsFloatingPoint) { if constexpr (IsFloatingPoint) VERIFY(isfinite(y)); - return fmod(fmod(x, y) + y, y); + auto r = fmod(x, y); + return r < 0 ? r + y : r; } else { return ((x % y) + y) % y; }