mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:28:12 +00:00
LibJS: Add extreme value tests for cos and sin
These sometimes produce different NaN patterns which can mess up the value encoding.
This commit is contained in:
parent
27abbfdf09
commit
da8715a07c
4 changed files with 35 additions and 3 deletions
|
@ -183,27 +183,53 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::trunc)
|
|||
// 21.3.2.30 Math.sin ( x ), https://tc39.es/ecma262/#sec-math.sin
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::sin)
|
||||
{
|
||||
// 1. Let n be ? ToNumber(x).
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
if (number.is_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 +∞𝔽 or n is -∞𝔽, return NaN.
|
||||
if (number.is_infinity())
|
||||
return js_nan();
|
||||
|
||||
// 4. Return an implementation-approximated Number value representing the result of the sine of ℝ(n).
|
||||
return Value(::sin(number.as_double()));
|
||||
}
|
||||
|
||||
// 21.3.2.12 Math.cos ( x ), https://tc39.es/ecma262/#sec-math.cos
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::cos)
|
||||
{
|
||||
// 1. Let n be ? ToNumber(x).
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
if (number.is_nan())
|
||||
|
||||
// 2. If n is NaN, n is +∞𝔽, or n is -∞𝔽, return NaN.
|
||||
if (number.is_nan() || number.is_infinity())
|
||||
return js_nan();
|
||||
|
||||
// 3. If n is +0𝔽 or n is -0𝔽, return 1𝔽.
|
||||
if (number.is_positive_zero() || number.is_negative_zero())
|
||||
return Value(1);
|
||||
|
||||
// 4. Return an implementation-approximated Number value representing the result of the cosine of ℝ(n).
|
||||
return Value(::cos(number.as_double()));
|
||||
}
|
||||
|
||||
// 21.3.2.33 Math.tan ( x ), https://tc39.es/ecma262/#sec-math.tan
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::tan)
|
||||
{
|
||||
// Let n be ? ToNumber(x).
|
||||
auto number = TRY(vm.argument(0).to_number(global_object));
|
||||
if (number.is_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 +∞𝔽, or n is -∞𝔽, return NaN.
|
||||
if (number.is_infinity())
|
||||
return js_nan();
|
||||
|
||||
// 4. Return an implementation-approximated Number value representing the result of the tangent of ℝ(n).
|
||||
return Value(::tan(number.as_double()));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue