1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

LibJS/JIT: Add builtin for Math.exp()

This commit is contained in:
Andreas Kling 2023-11-24 09:53:52 +01:00
parent 8447544e17
commit afeb551d57
4 changed files with 24 additions and 3 deletions

View file

@ -42,7 +42,7 @@ void MathObject::initialize(Realm& realm)
define_native_function(realm, vm.names.cos, cos, 1, attr);
define_native_function(realm, vm.names.tan, tan, 1, attr);
define_native_function(realm, vm.names.pow, pow, 2, attr, Bytecode::Builtin::MathPow);
define_native_function(realm, vm.names.exp, exp, 1, attr);
define_native_function(realm, vm.names.exp, exp, 1, attr, Bytecode::Builtin::MathExp);
define_native_function(realm, vm.names.expm1, expm1, 1, attr);
define_native_function(realm, vm.names.sign, sign, 1, attr);
define_native_function(realm, vm.names.clz32, clz32, 1, attr);
@ -422,10 +422,10 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::cosh)
}
// 21.3.2.14 Math.exp ( x ), https://tc39.es/ecma262/#sec-math.exp
JS_DEFINE_NATIVE_FUNCTION(MathObject::exp)
ThrowCompletionOr<Value> MathObject::exp_impl(VM& vm, Value x)
{
// 1. Let n be ? ToNumber(x).
auto number = TRY(vm.argument(0).to_number(vm));
auto number = TRY(x.to_number(vm));
// 2. If n is either NaN or +∞𝔽, return n.
if (number.is_nan() || number.is_positive_infinity())
@ -443,6 +443,12 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::exp)
return Value(::exp(number.as_double()));
}
// 21.3.2.14 Math.exp ( x ), https://tc39.es/ecma262/#sec-math.exp
JS_DEFINE_NATIVE_FUNCTION(MathObject::exp)
{
return exp_impl(vm, vm.argument(0));
}
// 21.3.2.15 Math.expm1 ( x ), https://tc39.es/ecma262/#sec-math.expm1
JS_DEFINE_NATIVE_FUNCTION(MathObject::expm1)
{