diff options
author | Linus Groh <mail@linusgroh.de> | 2020-04-05 13:40:00 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-05 15:32:06 +0200 |
commit | 0403845d3edce9caf6823e0579074f57e9a4b9b9 (patch) | |
tree | f545e5cc2f4be20bd90d696174090e333077512c /Libraries/LibJS/Runtime | |
parent | eafd3dbaf88461ba7fb99ce8c5c6e7a295bed9b4 (diff) | |
download | serenity-0403845d3edce9caf6823e0579074f57e9a4b9b9.zip |
LibJS: Implement exponentiation (** operator)
Diffstat (limited to 'Libraries/LibJS/Runtime')
-rw-r--r-- | Libraries/LibJS/Runtime/Value.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibJS/Runtime/Value.h | 1 |
2 files changed, 7 insertions, 0 deletions
diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index 13687cb5b3..ea0594245f 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -35,6 +35,7 @@ #include <LibJS/Runtime/PrimitiveString.h> #include <LibJS/Runtime/StringObject.h> #include <LibJS/Runtime/Value.h> +#include <math.h> namespace JS { @@ -268,6 +269,11 @@ Value mod(Value lhs, Value rhs) return Value(index - trunc * period); } +Value exp(Value lhs, Value rhs) +{ + return Value(pow(lhs.to_number().as_double(), rhs.to_number().as_double())); +} + Value typed_eq(Value lhs, Value rhs) { if (rhs.type() != lhs.type()) diff --git a/Libraries/LibJS/Runtime/Value.h b/Libraries/LibJS/Runtime/Value.h index df0e742ab9..b6d30c80f1 100644 --- a/Libraries/LibJS/Runtime/Value.h +++ b/Libraries/LibJS/Runtime/Value.h @@ -196,6 +196,7 @@ Value sub(Value lhs, Value rhs); Value mul(Value lhs, Value rhs); Value div(Value lhs, Value rhs); Value mod(Value lhs, Value rhs); +Value exp(Value lhs, Value rhs); Value eq(Value lhs, Value rhs); Value typed_eq(Value lhs, Value rhs); Value instance_of(Value lhs, Value rhs); |