mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
LibJS: Add spec comments and check for edge cases in Math.asin
This commit is contained in:
parent
cf4daa3941
commit
6bdf021b0c
Notes:
sideshowbarker
2024-07-17 03:59:33 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/6bdf021b0c Pull-request: https://github.com/SerenityOS/serenity/pull/16234
|
@ -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()));
|
||||
}
|
||||
|
||||
|
|
|
@ -12,4 +12,8 @@ test("basic functionality", () => {
|
|||
expect(Math.asin([1, 2, 3])).toBeNaN();
|
||||
expect(Math.asin({})).toBeNaN();
|
||||
expect(Math.asin("foo")).toBeNaN();
|
||||
expect(Math.asin(NaN)).toBe(NaN);
|
||||
expect(Math.asin(-0.0)).toBe(-0.0);
|
||||
expect(Math.asin(1.1)).toBe(NaN);
|
||||
expect(Math.asin(-1.1)).toBe(NaN);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue