mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
LibJS: Add spec comments and check for edge cases in Math.tanh
This commit is contained in:
parent
8de8742b7c
commit
bf1b2d63c6
2 changed files with 13 additions and 2 deletions
|
@ -636,13 +636,22 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::cosh)
|
|||
// 21.3.2.34 Math.tanh ( x ), https://tc39.es/ecma262/#sec-math.tanh
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::tanh)
|
||||
{
|
||||
// 1. Let n be ? ToNumber(x).
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
if (number.is_nan())
|
||||
return js_nan();
|
||||
|
||||
// 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 is +∞𝔽, return 1𝔽.
|
||||
if (number.is_positive_infinity())
|
||||
return Value(1);
|
||||
|
||||
// 4. If n is -∞𝔽, return -1𝔽.
|
||||
if (number.is_negative_infinity())
|
||||
return Value(-1);
|
||||
|
||||
// 5. Return an implementation-approximated Number value representing the result of the hyperbolic tangent of ℝ(n).
|
||||
return Value(::tanh(number.as_double()));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue