mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:07:44 +00:00
LibJS: Correct modulo behaviour in to_i32 to match the specification
This commit is contained in:
parent
bbf75d0bea
commit
aa5b144f90
1 changed files with 2 additions and 1 deletions
|
@ -566,7 +566,8 @@ i32 Value::to_i32_slow_case(GlobalObject& global_object) const
|
||||||
auto int_val = floor(abs);
|
auto int_val = floor(abs);
|
||||||
if (signbit(value))
|
if (signbit(value))
|
||||||
int_val = -int_val;
|
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)
|
if (int32bit >= 2147483648.0)
|
||||||
int32bit -= 4294967296.0;
|
int32bit -= 4294967296.0;
|
||||||
return static_cast<i32>(int32bit);
|
return static_cast<i32>(int32bit);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue