mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +00:00
LibJS/JIT: Add builtin for Math.pow()
This commit is contained in:
parent
94b634f029
commit
5e976d611e
4 changed files with 25 additions and 4 deletions
|
@ -41,7 +41,7 @@ void MathObject::initialize(Realm& realm)
|
|||
define_native_function(realm, vm.names.sin, sin, 1, attr);
|
||||
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);
|
||||
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.expm1, expm1, 1, attr);
|
||||
define_native_function(realm, vm.names.sign, sign, 1, attr);
|
||||
|
@ -729,18 +729,24 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::min)
|
|||
}
|
||||
|
||||
// 21.3.2.26 Math.pow ( base, exponent ), https://tc39.es/ecma262/#sec-math.pow
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::pow)
|
||||
ThrowCompletionOr<Value> MathObject::pow_impl(VM& vm, Value base, Value exponent)
|
||||
{
|
||||
// Set base to ? ToNumber(base).
|
||||
auto base = TRY(vm.argument(0).to_number(vm));
|
||||
base = TRY(base.to_number(vm));
|
||||
|
||||
// 2. Set exponent to ? ToNumber(exponent).
|
||||
auto exponent = TRY(vm.argument(1).to_number(vm));
|
||||
exponent = TRY(exponent.to_number(vm));
|
||||
|
||||
// 3. Return Number::exponentiate(base, exponent).
|
||||
return JS::exp(vm, base, exponent);
|
||||
}
|
||||
|
||||
// 21.3.2.26 Math.pow ( base, exponent ), https://tc39.es/ecma262/#sec-math.pow
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::pow)
|
||||
{
|
||||
return pow_impl(vm, vm.argument(0), vm.argument(1));
|
||||
}
|
||||
|
||||
// 21.3.2.27 Math.random ( ), https://tc39.es/ecma262/#sec-math.random
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::random)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue