Reviewers: jarin,
Description:
Implement hyperbolic math functions for ES6.
[email protected]
BUG=v8:2938
LOG=Y
Please review this at https://codereview.chromium.org/102023003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+86, -1 lines):
M src/harmony-math.js
M src/runtime.h
M src/runtime.cc
Index: src/harmony-math.js
diff --git a/src/harmony-math.js b/src/harmony-math.js
index
a4d3f2e8a5e9c5936630571644605402dee1199d..61d377c2c58c6fc0a4dc0971a1cff61c02f43e99
100644
--- a/src/harmony-math.js
+++ b/src/harmony-math.js
@@ -47,13 +47,80 @@ function MathTrunc(x) {
}
+// ES6 draft 09-27-13, section 20.2.2.30.
+function MathSinh(x) {
+ if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
+ // Idempotent for NaN, +/-0 and +/-Infinity.
+ if (x === 0 || !NUMBER_IS_FINITE(x)) return x;
+ return (MathExp(x) - MathExp(-x)) / 2;
+}
+
+
+// ES6 draft 09-27-13, section 20.2.2.12.
+function MathCosh(x) {
+ if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
+ // Idempotent for NaN and +/-Infinity.
+ if (!NUMBER_IS_FINITE(x)) return x;
+ return (MathExp(x) + MathExp(-x)) / 2;
+}
+
+
+// ES6 draft 09-27-13, section 20.2.2.33.
+function MathTanh(x) {
+ if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
+ // Idempotent for +/-0.
+ if (x === 0) return x;
+ // Returns +/-1 for +/-Infinity.
+ if (!NUMBER_IS_FINITE(x)) return MathSign(x);
+ var exp1 = MathExp(x);
+ var exp2 = MathExp(-x);
+ return (exp1 - exp2) / (exp1 + exp2);
+}
+
+
+// ES6 draft 09-27-13, section 20.2.2.5.
+function MathAsinh(x) {
+ if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
+ // Idempotent for NaN, +/-0 and +/-Infinity.
+ if (x === 0 || !NUMBER_IS_FINITE(x)) return x;
+ return %Math_asinh(x);
+}
+
+
+// ES6 draft 09-27-13, section 20.2.2.3.
+function MathAcosh(x) {
+ if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
+ if (x < 1) return NAN;
+ // Idempotent for NaN and +Infinity.
+ if (!NUMBER_IS_FINITE(x)) return x;
+ return %Math_acosh(x);
+}
+
+
+// ES6 draft 09-27-13, section 20.2.2.7.
+function MathAtanh(x) {
+ if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
+ // Idempotent for +/-0.
+ if (x === 0) return x;
+ // Returns NaN for NaN and +/- Infinity.
+ if (!NUMBER_IS_FINITE(x)) return NAN;
+ return %Math_atanh(x);
+}
+
+
function ExtendMath() {
%CheckIsBootstrapping();
// Set up the non-enumerable functions on the Math object.
InstallFunctions($Math, DONT_ENUM, $Array(
"sign", MathSign,
- "trunc", MathTrunc
+ "trunc", MathTrunc,
+ "sinh", MathSinh,
+ "cosh", MathCosh,
+ "tanh", MathTanh,
+ "asinh", MathAsinh,
+ "acosh", MathAcosh,
+ "atanh", MathAtanh
));
}
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
7dc96f201970eec90466b79f20fa2823271fe737..28e2ad420633073871a651059dd68589582ab35e
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -7788,6 +7788,21 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_Math_pow_cfunction) {
}
+#define
HYPERBOLIC_MATH_FUNCTION(name) \
+RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_##name)
{ \
+ SealHandleScope
shs(isolate); \
+ ASSERT(args.length() ==
1); \
+ CONVERT_DOUBLE_ARG_CHECKED(x,
0); \
+ return
isolate->heap()->AllocateHeapNumber(name(x)); \
+}
+
+HYPERBOLIC_MATH_FUNCTION(asinh)
+HYPERBOLIC_MATH_FUNCTION(acosh)
+HYPERBOLIC_MATH_FUNCTION(atanh)
+
+#undef HYPERBOLIC_MATH_FUNCTION
+
+
RUNTIME_FUNCTION(MaybeObject*, Runtime_RoundNumber) {
SealHandleScope shs(isolate);
ASSERT(args.length() == 1);
Index: src/runtime.h
diff --git a/src/runtime.h b/src/runtime.h
index
0f920c7259eba9fc3521013d3fe2027f24c8f461..4b2ba0434488e0d3d5ed3f928aa24307df2c152a
100644
--- a/src/runtime.h
+++ b/src/runtime.h
@@ -190,6 +190,9 @@ namespace internal {
F(Math_sin, 1, 1) \
F(Math_sqrt, 1, 1) \
F(Math_tan, 1, 1) \
+ F(Math_asinh, 1, 1) \
+ F(Math_acosh, 1, 1) \
+ F(Math_atanh, 1, 1) \
\
/* Regular expressions */ \
F(RegExpCompile, 3, 1) \
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.