Index: src/harmony-math.js |
diff --git a/src/harmony-math.js b/src/harmony-math.js |
index a4d3f2e8a5e9c5936630571644605402dee1199d..2bf33d63f2c81b26263abffea9e931bb9a60008e 100644 |
--- a/src/harmony-math.js |
+++ b/src/harmony-math.js |
@@ -47,13 +47,82 @@ 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; |
+ if (x > 0) return MathLog(x + MathSqrt(x * x + 1)); |
+ // This is to prevent numerical errors caused by large negative x. |
+ return -MathLog(-x + MathSqrt(x * x + 1)); |
+} |
+ |
+ |
+// 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 MathLog(x + MathSqrt(x + 1) * MathSqrt(x - 1)); |
+} |
+ |
+ |
+// 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 0.5 * MathLog((1 + x) / (1 - 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 |
)); |
} |