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

LibJS: Add spec comments and check for edge cases in Math.asin

This commit is contained in:
davidot 2022-11-28 12:00:09 +01:00 committed by Andreas Kling
parent cf4daa3941
commit 6bdf021b0c
2 changed files with 13 additions and 0 deletions

View file

@ -319,9 +319,18 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::acosh)
// 21.3.2.4 Math.asin ( x ), https://tc39.es/ecma262/#sec-math.asin
JS_DEFINE_NATIVE_FUNCTION(MathObject::asin)
{
// 1. Let n be ? ToNumber(x).
auto number = TRY(vm.argument(0).to_number(vm));
// 2. If n is NaN, n is +0𝔽, or n is -0𝔽, return n.
if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero())
return number;
// 3. If n > 1𝔽 or n < -1𝔽, return NaN.
if (number.as_double() > 1 || number.as_double() < -1)
return js_nan();
// 4. Return an implementation-approximated Number value representing the result of the inverse sine of (n).
return Value(::asin(number.as_double()));
}