mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:24:57 +00:00
LibJS/JIT: Add builtin for Math.exp()
This commit is contained in:
parent
8447544e17
commit
afeb551d57
4 changed files with 24 additions and 3 deletions
|
@ -16,6 +16,7 @@ namespace JS::Bytecode {
|
|||
O(MathAbs, math_abs, Math, abs, 1) \
|
||||
O(MathLog, math_log, Math, log, 1) \
|
||||
O(MathPow, math_pow, Math, pow, 2) \
|
||||
O(MathExp, math_exp, Math, exp, 1) \
|
||||
O(MathCeil, math_ceil, Math, ceil, 1) \
|
||||
O(MathFloor, math_floor, Math, floor, 1) \
|
||||
O(MathRound, math_round, Math, round, 1) \
|
||||
|
|
|
@ -2702,6 +2702,19 @@ void Compiler::compile_builtin_math_round(Assembler::Label&, Assembler::Label& e
|
|||
m_assembler.jump(end);
|
||||
}
|
||||
|
||||
static Value cxx_math_exp(VM& vm, Value, Value value)
|
||||
{
|
||||
return TRY_OR_SET_EXCEPTION(MathObject::exp_impl(vm, value));
|
||||
}
|
||||
|
||||
void Compiler::compile_builtin_math_exp(Assembler::Label&, Assembler::Label& end)
|
||||
{
|
||||
native_call((void*)cxx_math_exp);
|
||||
store_accumulator(RET);
|
||||
check_exception();
|
||||
m_assembler.jump(end);
|
||||
}
|
||||
|
||||
void Compiler::compile_builtin_math_abs(Assembler::Label& slow_case, Assembler::Label& end)
|
||||
{
|
||||
branch_if_int32(ARG2, [&] {
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
static ThrowCompletionOr<Value> floor_impl(VM&, Value);
|
||||
static ThrowCompletionOr<Value> ceil_impl(VM&, Value);
|
||||
static ThrowCompletionOr<Value> round_impl(VM&, Value);
|
||||
static ThrowCompletionOr<Value> exp_impl(VM&, Value);
|
||||
|
||||
private:
|
||||
explicit MathObject(Realm&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue