mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +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
Notes:
sideshowbarker
2024-07-18 16:50:53 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/24ffe91b16c Pull-request: https://github.com/SerenityOS/serenity/pull/7797 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/linusg
1 changed files with 5 additions and 1 deletions
|
@ -82,7 +82,11 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::abs)
|
|||
return {};
|
||||
if (number.is_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)
|
||||
|
|
Loading…
Reference in a new issue