1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

LibJS: Do not negate zero into negative zero in ToIntegerOrInfinity

When the input value was in the range of [-1, 0] we would incorrectly
negate the resulting integer, resulting in -0 instead of the expected 0
This commit is contained in:
Idan Horowitz 2022-04-30 21:38:32 +03:00 committed by Linus Groh
parent 0083fb629b
commit 0399239e3f

View file

@ -800,7 +800,7 @@ ThrowCompletionOr<double> Value::to_integer_or_infinity(GlobalObject& global_obj
if (number.is_infinity())
return number.as_double();
auto integer = floor(fabs(number.as_double()));
if (number.as_double() < 0)
if (number.as_double() < 0 && integer != 0)
integer = -integer;
return integer;
}