mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 19:05:07 +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,11 +60,13 @@ namespace JS {
|
||||||
P(Symbol) \
|
P(Symbol) \
|
||||||
P(UTC) \
|
P(UTC) \
|
||||||
P(abs) \
|
P(abs) \
|
||||||
|
P(acos) \
|
||||||
P(acosh) \
|
P(acosh) \
|
||||||
P(apply) \
|
P(apply) \
|
||||||
P(arguments) \
|
P(arguments) \
|
||||||
P(asIntN) \
|
P(asIntN) \
|
||||||
P(asUintN) \
|
P(asUintN) \
|
||||||
|
P(asin) \
|
||||||
P(asinh) \
|
P(asinh) \
|
||||||
P(atan) \
|
P(atan) \
|
||||||
P(atanh) \
|
P(atanh) \
|
||||||
|
|
|
@ -60,7 +60,9 @@ void MathObject::initialize(GlobalObject& global_object)
|
||||||
define_native_function(vm.names.expm1, expm1, 1, attr);
|
define_native_function(vm.names.expm1, expm1, 1, attr);
|
||||||
define_native_function(vm.names.sign, sign, 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.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.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.asinh, asinh, 1, attr);
|
||||||
define_native_function(vm.names.atan, atan, 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.atanh, atanh, 1, attr);
|
||||||
|
@ -273,6 +275,18 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::clz32)
|
||||||
return Value(__builtin_clz((unsigned)number.as_double()));
|
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)
|
JS_DEFINE_NATIVE_FUNCTION(MathObject::acosh)
|
||||||
{
|
{
|
||||||
auto number = vm.argument(0).to_number(global_object);
|
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()));
|
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)
|
JS_DEFINE_NATIVE_FUNCTION(MathObject::asinh)
|
||||||
{
|
{
|
||||||
auto number = vm.argument(0).to_number(global_object);
|
auto number = vm.argument(0).to_number(global_object);
|
||||||
|
|
|
@ -56,7 +56,9 @@ private:
|
||||||
JS_DECLARE_NATIVE_FUNCTION(expm1);
|
JS_DECLARE_NATIVE_FUNCTION(expm1);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(sign);
|
JS_DECLARE_NATIVE_FUNCTION(sign);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(clz32);
|
JS_DECLARE_NATIVE_FUNCTION(clz32);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(acos);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(acosh);
|
JS_DECLARE_NATIVE_FUNCTION(acosh);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(asin);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(asinh);
|
JS_DECLARE_NATIVE_FUNCTION(asinh);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(atan);
|
JS_DECLARE_NATIVE_FUNCTION(atan);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(atanh);
|
JS_DECLARE_NATIVE_FUNCTION(atanh);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue