diff --git a/Userland/Libraries/LibJS/Runtime/MathObject.cpp b/Userland/Libraries/LibJS/Runtime/MathObject.cpp index da51b95897..b503869922 100644 --- a/Userland/Libraries/LibJS/Runtime/MathObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/MathObject.cpp @@ -337,7 +337,15 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::asin) // 21.3.2.5 Math.asinh ( x ), https://tc39.es/ecma262/#sec-math.asinh JS_DEFINE_NATIVE_FUNCTION(MathObject::asinh) { - return Value(::asinh(TRY(vm.argument(0).to_number(vm)).as_double())); + // 1. Let n be ? ToNumber(x). + auto number = TRY(vm.argument(0).to_number(vm)); + + // 2. If n is not finite or n is either +0𝔽 or -0𝔽, return n. + if (!number.is_finite_number() || number.is_positive_zero() || number.is_negative_zero()) + return number; + + // 3. Return an implementation-approximated Number value representing the result of the inverse hyperbolic sine of ℝ(n). + return Value(::asinh(number.as_double())); } // 21.3.2.6 Math.atan ( x ), https://tc39.es/ecma262/#sec-math.atan diff --git a/Userland/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js b/Userland/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js index f52f6c2d0b..0de0bdedff 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Math/Math.asinh.js @@ -3,4 +3,9 @@ test("basic functionality", () => { expect(Math.asinh(0)).toBeCloseTo(0); expect(Math.asinh(1)).toBeCloseTo(0.881373); + expect(Math.asinh(NaN)).toBe(NaN); + expect(Math.asinh(Number.POSITIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY); + expect(Math.asinh(Number.NEGATIVE_INFINITY)).toBe(Number.NEGATIVE_INFINITY); + expect(Math.asinh(0.0)).toBe(0.0); + expect(Math.asinh(-0.0)).toBe(-0.0); });