mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
LibJS: Handle negative zero and negative infinity in Math.abs()
As required by the specification: 3. If n is -0, return +0. 4. If n is -∞, return +∞.
This commit is contained in:
parent
9d2e90d569
commit
24ffe91b16
1 changed files with 5 additions and 1 deletions
|
@ -82,7 +82,11 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::abs)
|
||||||
return {};
|
return {};
|
||||||
if (number.is_nan())
|
if (number.is_nan())
|
||||||
return js_nan();
|
return js_nan();
|
||||||
return Value(number.as_double() >= 0 ? number.as_double() : -number.as_double());
|
if (number.is_negative_zero())
|
||||||
|
return Value(0);
|
||||||
|
if (number.is_negative_infinity())
|
||||||
|
return js_infinity();
|
||||||
|
return Value(number.as_double() < 0 ? -number.as_double() : number.as_double());
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::random)
|
JS_DEFINE_NATIVE_FUNCTION(MathObject::random)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue