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-2004 by Sun Microsystems, Inc. All rights reserved. | 4 // Copyright (C) 1993-2004 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 var w = x + y; | 260 var w = x + y; |
261 var z = %_ConstructDouble(%_DoubleHi(w), 0); | 261 var z = %_ConstructDouble(%_DoubleHi(w), 0); |
262 var v = y - (z - x); | 262 var v = y - (z - x); |
263 var a = -1 / w; | 263 var a = -1 / w; |
264 var t = %_ConstructDouble(%_DoubleHi(a), 0); | 264 var t = %_ConstructDouble(%_DoubleHi(a), 0); |
265 var s = 1 + t * z; | 265 var s = 1 + t * z; |
266 return t + a * (s + t * v); | 266 return t + a * (s + t * v); |
267 } | 267 } |
268 } | 268 } |
269 } | 269 } |
270 if (ix >= 0x3fe59429) { // |x| > .6744 | 270 if (ix >= 0x3fe59428) { // |x| > .6744 |
Raymond Toy
2014/11/04 16:49:52
Sorry about the typo!
More tests should be added
| |
271 if (x < 0) { | 271 if (x < 0) { |
272 x = -x; | 272 x = -x; |
273 y = -y; | 273 y = -y; |
274 } | 274 } |
275 z = PIO4 - x; | 275 z = PIO4 - x; |
276 w = PIO4LO - y; | 276 w = PIO4LO - y; |
277 x = z + w; | 277 x = z + w; |
278 y = 0; | 278 y = 0; |
279 } | 279 } |
280 z = x * x; | 280 z = x * x; |
281 w = z * z; | 281 w = z * z; |
282 | 282 |
283 // Break x^5 * (T1 + x^2*T2 + ...) into | 283 // Break x^5 * (T1 + x^2*T2 + ...) into |
284 // x^5 * (T1 + x^4*T3 + ... + x^20*T11) + | 284 // x^5 * (T1 + x^4*T3 + ... + x^20*T11) + |
285 // x^5 * (x^2 * (T2 + x^4*T4 + ... + x^22*T12)) | 285 // x^5 * (x^2 * (T2 + x^4*T4 + ... + x^22*T12)) |
286 var r = KTAN(1) + w * (KTAN(3) + w * (KTAN(5) + | 286 var r = KTAN(1) + w * (KTAN(3) + w * (KTAN(5) + |
287 w * (KTAN(7) + w * (KTAN(9) + w * KTAN(11))))); | 287 w * (KTAN(7) + w * (KTAN(9) + w * KTAN(11))))); |
288 var v = z * (KTAN(2) + w * (KTAN(4) + w * (KTAN(6) + | 288 var v = z * (KTAN(2) + w * (KTAN(4) + w * (KTAN(6) + |
289 w * (KTAN(8) + w * (KTAN(10) + w * KTAN(12)))))); | 289 w * (KTAN(8) + w * (KTAN(10) + w * KTAN(12)))))); |
290 var s = z * x; | 290 var s = z * x; |
291 r = y + z * (s * (r + v) + y); | 291 r = y + z * (s * (r + v) + y); |
292 r = r + KTAN(0) * s; | 292 r = r + KTAN(0) * s; |
293 w = x + r; | 293 w = x + r; |
294 if (ix >= 0x3fe59428) { | 294 if (ix >= 0x3fe59428) { |
Yang
2014/11/03 09:35:27
compare to this.
| |
295 return (1 - ((hx >> 30) & 2)) * | 295 return (1 - ((hx >> 30) & 2)) * |
296 (returnTan - 2.0 * (x - (w * w / (w + returnTan) - r))); | 296 (returnTan - 2.0 * (x - (w * w / (w + returnTan) - r))); |
297 } | 297 } |
298 if (returnTan == 1) { | 298 if (returnTan == 1) { |
299 return w; | 299 return w; |
300 } else { | 300 } else { |
301 z = %_ConstructDouble(%_DoubleHi(w), 0); | 301 z = %_ConstructDouble(%_DoubleHi(w), 0); |
302 v = r - (z - x); | 302 v = r - (z - x); |
303 var a = -1 / w; | 303 var a = -1 / w; |
304 var t = %_ConstructDouble(%_DoubleHi(a), 0); | 304 var t = %_ConstructDouble(%_DoubleHi(a), 0); |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
805 // |x| in [log(maxdouble), overflowthreshold] | 805 // |x| in [log(maxdouble), overflowthreshold] |
806 if (MathAbs(x) <= KCOSH_OVERFLOW) { | 806 if (MathAbs(x) <= KCOSH_OVERFLOW) { |
807 var w = MathExp(0.5 * MathAbs(x)); | 807 var w = MathExp(0.5 * MathAbs(x)); |
808 var t = 0.5 * w; | 808 var t = 0.5 * w; |
809 return t * w; | 809 return t * w; |
810 } | 810 } |
811 if (NUMBER_IS_NAN(x)) return x; | 811 if (NUMBER_IS_NAN(x)) return x; |
812 // |x| > overflowthreshold. | 812 // |x| > overflowthreshold. |
813 return INFINITY; | 813 return INFINITY; |
814 } | 814 } |
OLD | NEW |