Index: src/third_party/fdlibm/fdlibm.js |
diff --git a/src/third_party/fdlibm/fdlibm.js b/src/third_party/fdlibm/fdlibm.js |
index 880446990536b62a633fced0ba3b446c9801b396..ecac16d461bdca4c867ef063ddd97aedb7a17000 100644 |
--- a/src/third_party/fdlibm/fdlibm.js |
+++ b/src/third_party/fdlibm/fdlibm.js |
@@ -28,6 +28,8 @@ |
var kMath; |
var rempio2result; |
+(function() { |
+ |
const INVPIO2 = kMath[0]; |
const PIO2_1 = kMath[1]; |
const PIO2_1T = kMath[2]; |
@@ -79,7 +81,7 @@ macro REMPIO2(X) |
} |
} else if (ix <= 0x413921fb) { |
// |X| ~<= 2^19*(pi/2), medium size |
- var t = MathAbs(X); |
+ var t = $abs(X); |
n = (t * INVPIO2 + 0.5) | 0; |
var r = t - n * PIO2_1; |
var w = n * PIO2_1T; |
@@ -257,7 +259,7 @@ function KernelTan(x, y, returnTan) { |
if (ix < 0x3e300000) { // |x| < 2^-28 |
if (((ix | %_DoubleLo(x)) | (returnTan + 1)) == 0) { |
// x == 0 && returnTan = -1 |
- return 1 / MathAbs(x); |
+ return 1 / $abs(x); |
} else { |
if (returnTan == 1) { |
return x; |
@@ -745,7 +747,7 @@ function MathSinh(x) { |
x = x * 1; // Convert to number. |
var h = (x < 0) ? -0.5 : 0.5; |
// |x| in [0, 22]. return sign(x)*0.5*(E+E/(E+1)) |
- var ax = MathAbs(x); |
+ var ax = $abs(x); |
if (ax < 22) { |
// For |x| < 2^-28, sinh(x) = x |
if (ax < TWO_M28) return x; |
@@ -754,11 +756,11 @@ function MathSinh(x) { |
return h * (t + t / (t + 1)); |
} |
// |x| in [22, log(maxdouble)], return 0.5 * exp(|x|) |
- if (ax < LOG_MAXD) return h * MathExp(ax); |
+ if (ax < LOG_MAXD) return h * $exp(ax); |
// |x| in [log(maxdouble), overflowthreshold] |
// overflowthreshold = 710.4758600739426 |
if (ax <= KSINH_OVERFLOW) { |
- var w = MathExp(0.5 * ax); |
+ var w = $exp(0.5 * ax); |
var t = h * w; |
return t * w; |
} |
@@ -796,7 +798,7 @@ function MathCosh(x) { |
var ix = %_DoubleHi(x) & 0x7fffffff; |
// |x| in [0,0.5*log2], return 1+expm1(|x|)^2/(2*exp(|x|)) |
if (ix < 0x3fd62e43) { |
- var t = MathExpm1(MathAbs(x)); |
+ var t = MathExpm1($abs(x)); |
var w = 1 + t; |
// For |x| < 2^-55, cosh(x) = 1 |
if (ix < 0x3c800000) return w; |
@@ -804,14 +806,14 @@ function MathCosh(x) { |
} |
// |x| in [0.5*log2, 22], return (exp(|x|)+1/exp(|x|)/2 |
if (ix < 0x40360000) { |
- var t = MathExp(MathAbs(x)); |
+ var t = $exp($abs(x)); |
return 0.5 * t + 0.5 / t; |
} |
// |x| in [22, log(maxdouble)], return half*exp(|x|) |
- if (ix < 0x40862e42) return 0.5 * MathExp(MathAbs(x)); |
+ if (ix < 0x40862e42) return 0.5 * $exp($abs(x)); |
// |x| in [log(maxdouble), overflowthreshold] |
- if (MathAbs(x) <= KCOSH_OVERFLOW) { |
- var w = MathExp(0.5 * MathAbs(x)); |
+ if ($abs(x) <= KCOSH_OVERFLOW) { |
+ var w = $exp(0.5 * $abs(x)); |
var t = 0.5 * w; |
return t * w; |
} |
@@ -879,7 +881,7 @@ function MathLog10(x) { |
y = k + i; |
x = %_ConstructDouble(hx, lx); |
- z = y * LOG10_2LO + IVLN10 * MathLog(x); |
+ z = y * LOG10_2LO + IVLN10 * %_MathLogRT(x); |
return z + y * LOG10_2HI; |
} |
@@ -914,7 +916,7 @@ const TWO53 = 9007199254740992; |
function MathLog2(x) { |
x = x * 1; // Convert to number. |
- var ax = MathAbs(x); |
+ var ax = $abs(x); |
var hx = %_DoubleHi(x); |
var lx = %_DoubleLo(x); |
var ix = hx & 0x7fffffff; |
@@ -997,3 +999,20 @@ function MathLog2(x) { |
// t1 + t2 = log2(ax), sum up because we do not care about extra precision. |
return t1 + t2; |
} |
+ |
+InstallFunctions($Math, DONT_ENUM, $Array( |
+ "cos", MathCos, |
+ "sin", MathSin, |
+ "tan", MathTan, |
+ "sinh", MathSinh, |
+ "cosh", MathCosh, |
+ "log10", MathLog10, |
+ "log2", MathLog2, |
+ "log1p", MathLog1p, |
+ "expm1", MathExpm1 |
+)); |
+ |
+%SetInlineBuiltinFlag(MathSin); |
+%SetInlineBuiltinFlag(MathCos); |
+ |
+})(); |