OLD | NEW |
---|---|
1 // The following is adapted from fdlibm (http://www.netlib.org/fdlibm). | 1 // The following is adapted from fdlibm (http://www.netlib.org/fdlibm). |
2 // | 2 // |
3 // ==================================================== | 3 // ==================================================== |
4 // Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | 4 // Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
5 // | 5 // |
6 // Developed at SunSoft, a Sun Microsystems, Inc. business. | 6 // Developed at SunSoft, a Sun Microsystems, Inc. business. |
7 // Permission to use, copy, modify, and distribute this | 7 // Permission to use, copy, modify, and distribute this |
8 // software is freely granted, provided that this notice | 8 // software is freely granted, provided that this notice |
9 // is preserved. | 9 // is preserved. |
10 // ==================================================== | 10 // ==================================================== |
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1243 u_threshold = -7.45133219101941108420e+02, /* 0xc0874910, 0xD52D3051 */ | 1243 u_threshold = -7.45133219101941108420e+02, /* 0xc0874910, 0xD52D3051 */ |
1244 ln2HI[2] = {6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ | 1244 ln2HI[2] = {6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ |
1245 -6.93147180369123816490e-01}, /* 0xbfe62e42, 0xfee00000 */ | 1245 -6.93147180369123816490e-01}, /* 0xbfe62e42, 0xfee00000 */ |
1246 ln2LO[2] = {1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */ | 1246 ln2LO[2] = {1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */ |
1247 -1.90821492927058770002e-10}, /* 0xbdea39ef, 0x35793c76 */ | 1247 -1.90821492927058770002e-10}, /* 0xbdea39ef, 0x35793c76 */ |
1248 invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */ | 1248 invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */ |
1249 P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ | 1249 P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ |
1250 P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ | 1250 P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ |
1251 P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ | 1251 P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ |
1252 P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ | 1252 P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ |
1253 P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ | 1253 P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */ |
1254 E = 2.718281828459045; /* 0x4005bf0a, 0x8b145769 */ | |
1254 | 1255 |
1255 static volatile double | 1256 static volatile double |
1256 huge = 1.0e+300, | 1257 huge = 1.0e+300, |
1257 twom1000 = 9.33263618503218878990e-302, /* 2**-1000=0x01700000,0*/ | 1258 twom1000 = 9.33263618503218878990e-302, /* 2**-1000=0x01700000,0*/ |
1258 two1023 = 8.988465674311579539e307; /* 0x1p1023 */ | 1259 two1023 = 8.988465674311579539e307; /* 0x1p1023 */ |
1259 | 1260 |
1260 double y, hi = 0.0, lo = 0.0, c, t, twopk; | 1261 double y, hi = 0.0, lo = 0.0, c, t, twopk; |
1261 int32_t k = 0, xsb; | 1262 int32_t k = 0, xsb; |
1262 uint32_t hx; | 1263 uint32_t hx; |
1263 | 1264 |
(...skipping 11 matching lines...) Expand all Loading... | |
1275 else | 1276 else |
1276 return (xsb == 0) ? x : 0.0; /* exp(+-inf)={inf,0} */ | 1277 return (xsb == 0) ? x : 0.0; /* exp(+-inf)={inf,0} */ |
1277 } | 1278 } |
1278 if (x > o_threshold) return huge * huge; /* overflow */ | 1279 if (x > o_threshold) return huge * huge; /* overflow */ |
1279 if (x < u_threshold) return twom1000 * twom1000; /* underflow */ | 1280 if (x < u_threshold) return twom1000 * twom1000; /* underflow */ |
1280 } | 1281 } |
1281 | 1282 |
1282 /* argument reduction */ | 1283 /* argument reduction */ |
1283 if (hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ | 1284 if (hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ |
1284 if (hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ | 1285 if (hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ |
1286 /* TODO(rtoy): We special case exp(1) here to return the correct | |
1287 * value of E, as the computation below would get the last bit | |
1288 * wrong. We should probably fix the algorithm instead. | |
1289 */ | |
1290 if (x == 1.0) return E; | |
Raymond Toy
2016/06/21 16:20:12
It's probably not possible to fix the algorithm ea
Benedikt Meurer
2016/06/22 03:55:59
Since exp is not performance critical or anything,
Raymond Toy
2016/06/22 22:11:48
Yes, this is possible, and something that I would
Benedikt Meurer
2016/06/23 03:30:58
This would be super awesome and highly appreciated
| |
1285 hi = x - ln2HI[xsb]; | 1291 hi = x - ln2HI[xsb]; |
1286 lo = ln2LO[xsb]; | 1292 lo = ln2LO[xsb]; |
1287 k = 1 - xsb - xsb; | 1293 k = 1 - xsb - xsb; |
1288 } else { | 1294 } else { |
1289 k = static_cast<int>(invln2 * x + halF[xsb]); | 1295 k = static_cast<int>(invln2 * x + halF[xsb]); |
1290 t = k; | 1296 t = k; |
1291 hi = x - t * ln2HI[0]; /* t*ln2HI is exact here */ | 1297 hi = x - t * ln2HI[0]; /* t*ln2HI is exact here */ |
1292 lo = t * ln2LO[0]; | 1298 lo = t * ln2LO[0]; |
1293 } | 1299 } |
1294 STRICT_ASSIGN(double, x, hi - lo); | 1300 STRICT_ASSIGN(double, x, hi - lo); |
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2298 /* argument reduction needed */ | 2304 /* argument reduction needed */ |
2299 n = __ieee754_rem_pio2(x, y); | 2305 n = __ieee754_rem_pio2(x, y); |
2300 /* 1 -> n even, -1 -> n odd */ | 2306 /* 1 -> n even, -1 -> n odd */ |
2301 return __kernel_tan(y[0], y[1], 1 - ((n & 1) << 1)); | 2307 return __kernel_tan(y[0], y[1], 1 - ((n & 1) << 1)); |
2302 } | 2308 } |
2303 } | 2309 } |
2304 | 2310 |
2305 } // namespace ieee754 | 2311 } // namespace ieee754 |
2306 } // namespace base | 2312 } // namespace base |
2307 } // namespace v8 | 2313 } // namespace v8 |
OLD | NEW |