summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Value.cpp
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-06-06 02:33:55 +0300
committerLinus Groh <mail@linusgroh.de>2021-06-06 01:34:22 +0100
commitaa5b144f9024cb155f34464849988250e4df5935 (patch)
treebbf1cc097bde0214e426fc1f583f9752c9787498 /Userland/Libraries/LibJS/Runtime/Value.cpp
parentbbf75d0beab57498d5a757126972791244932a91 (diff)
downloadserenity-aa5b144f9024cb155f34464849988250e4df5935.zip
LibJS: Correct modulo behaviour in to_i32 to match the specification
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Value.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp
index c63d9b7fbb..1801f75245 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Value.cpp
@@ -566,7 +566,8 @@ i32 Value::to_i32_slow_case(GlobalObject& global_object) const
auto int_val = floor(abs);
if (signbit(value))
int_val = -int_val;
- auto int32bit = fmod(int_val, 4294967296.0);
+ auto remainder = fmod(int_val, 4294967296.0);
+ auto int32bit = remainder >= 0.0 ? remainder : remainder + 4294967296.0; // The notation “x modulo y” computes a value k of the same sign as y
if (int32bit >= 2147483648.0)
int32bit -= 4294967296.0;
return static_cast<i32>(int32bit);