mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:18:12 +00:00
LibJS: Add Math.atan()
This commit is contained in:
parent
fe3963f3d4
commit
63b748642a
4 changed files with 29 additions and 0 deletions
|
@ -66,6 +66,7 @@ namespace JS {
|
|||
P(asIntN) \
|
||||
P(asUintN) \
|
||||
P(asinh) \
|
||||
P(atan) \
|
||||
P(atanh) \
|
||||
P(bind) \
|
||||
P(byteLength) \
|
||||
|
|
|
@ -62,6 +62,7 @@ void MathObject::initialize(GlobalObject& global_object)
|
|||
define_native_function(vm.names.clz32, clz32, 1, attr);
|
||||
define_native_function(vm.names.acosh, acosh, 1, attr);
|
||||
define_native_function(vm.names.asinh, asinh, 1, attr);
|
||||
define_native_function(vm.names.atan, atan, 1, attr);
|
||||
define_native_function(vm.names.atanh, atanh, 1, attr);
|
||||
define_native_function(vm.names.log1p, log1p, 1, attr);
|
||||
define_native_function(vm.names.cbrt, cbrt, 1, attr);
|
||||
|
@ -290,6 +291,20 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::asinh)
|
|||
return Value(::asinh(number.as_double()));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::atan)
|
||||
{
|
||||
auto number = vm.argument(0).to_number(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero())
|
||||
return number;
|
||||
if (number.is_positive_infinity())
|
||||
return Value(M_PI_2);
|
||||
if (number.is_negative_infinity())
|
||||
return Value(-M_PI_2);
|
||||
return Value(::atan(number.as_double()));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::atanh)
|
||||
{
|
||||
auto number = vm.argument(0).to_number(global_object);
|
||||
|
|
|
@ -58,6 +58,7 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(clz32);
|
||||
JS_DECLARE_NATIVE_FUNCTION(acosh);
|
||||
JS_DECLARE_NATIVE_FUNCTION(asinh);
|
||||
JS_DECLARE_NATIVE_FUNCTION(atan);
|
||||
JS_DECLARE_NATIVE_FUNCTION(atanh);
|
||||
JS_DECLARE_NATIVE_FUNCTION(log1p);
|
||||
JS_DECLARE_NATIVE_FUNCTION(cbrt);
|
||||
|
|
12
Libraries/LibJS/Tests/builtins/Math/Math.atan.js
Normal file
12
Libraries/LibJS/Tests/builtins/Math/Math.atan.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Math.atan).toHaveLength(1);
|
||||
|
||||
expect(Math.atan(0)).toBe(0);
|
||||
expect(Math.atan(-0)).toBe(-0);
|
||||
expect(Math.atan(NaN)).toBeNaN();
|
||||
expect(Math.atan(-2)).toBeCloseTo(-1.1071487177940904);
|
||||
expect(Math.atan(2)).toBeCloseTo(1.1071487177940904);
|
||||
expect(Math.atan(Infinity)).toBeCloseTo(Math.PI / 2);
|
||||
expect(Math.atan(-Infinity)).toBeCloseTo(-Math.PI / 2);
|
||||
expect(Math.atan(0.5)).toBeCloseTo(0.4636476090008061);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue