mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 14:25:08 +00:00
LibJS: Add Math.acos() and Math.asin()
This commit is contained in:
parent
231171364d
commit
df2a6cb4ab
3 changed files with 28 additions and 0 deletions
|
@ -60,7 +60,9 @@ void MathObject::initialize(GlobalObject& global_object)
|
|||
define_native_function(vm.names.expm1, expm1, 1, attr);
|
||||
define_native_function(vm.names.sign, sign, 1, attr);
|
||||
define_native_function(vm.names.clz32, clz32, 1, attr);
|
||||
define_native_function(vm.names.acos, acos, 1, attr);
|
||||
define_native_function(vm.names.acosh, acosh, 1, attr);
|
||||
define_native_function(vm.names.asin, asin, 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);
|
||||
|
@ -273,6 +275,18 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::clz32)
|
|||
return Value(__builtin_clz((unsigned)number.as_double()));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::acos)
|
||||
{
|
||||
auto number = vm.argument(0).to_number(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
if (number.is_nan() || number.as_double() > 1 || number.as_double() < -1)
|
||||
return js_nan();
|
||||
if (number.as_double() == 1)
|
||||
return Value(0);
|
||||
return Value(::acos(number.as_double()));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::acosh)
|
||||
{
|
||||
auto number = vm.argument(0).to_number(global_object);
|
||||
|
@ -283,6 +297,16 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::acosh)
|
|||
return Value(::acosh(number.as_double()));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::asin)
|
||||
{
|
||||
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;
|
||||
return Value(::asin(number.as_double()));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::asinh)
|
||||
{
|
||||
auto number = vm.argument(0).to_number(global_object);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue