diff options
Diffstat (limited to 'src/pkg/math/exp.go')
-rw-r--r-- | src/pkg/math/exp.go | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/pkg/math/exp.go b/src/pkg/math/exp.go index 22014daac..2bf80bcdd 100644 --- a/src/pkg/math/exp.go +++ b/src/pkg/math/exp.go @@ -93,16 +93,15 @@ func Exp(x float64) float64 { Ln2Hi = 6.93147180369123816490e-01; Ln2Lo = 1.90821492927058770002e-10; Log2e = 1.44269504088896338700e+00; - - P1 = 1.66666666666666019037e-01; /* 0x3FC55555; 0x5555553E */ - P2 = -2.77777777770155933842e-03; /* 0xBF66C16C; 0x16BEBD93 */ - P3 = 6.61375632143793436117e-05; /* 0x3F11566A; 0xAF25DE2C */ - P4 = -1.65339022054652515390e-06; /* 0xBEBBBD41; 0xC5D26BF1 */ - P5 = 4.13813679705723846039e-08; /* 0x3E663769; 0x72BEA4D0 */ + P1 = 1.66666666666666019037e-01; /* 0x3FC55555; 0x5555553E */ + P2 = -2.77777777770155933842e-03; /* 0xBF66C16C; 0x16BEBD93 */ + P3 = 6.61375632143793436117e-05; /* 0x3F11566A; 0xAF25DE2C */ + P4 = -1.65339022054652515390e-06; /* 0xBEBBBD41; 0xC5D26BF1 */ + P5 = 4.13813679705723846039e-08; /* 0x3E663769; 0x72BEA4D0 */ Overflow = 7.09782712893383973096e+02; Underflow = -7.45133219101941108420e+02; - NearZero = 1.0/(1<<28); // 2^-28 + NearZero = 1.0/(1<<28); // 2^-28 ) // special cases @@ -129,12 +128,12 @@ func Exp(x float64) float64 { } hi := x - float64(k)*Ln2Hi; lo := float64(k)*Ln2Lo; - r := hi - lo; + r := hi-lo; // compute - t := r * r; - c := r - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); - y := 1 - ((lo - (r*c)/(2-c)) - hi); + t := r*r; + c := r - t*(P1 + t*(P2 + t*(P3 + t*(P4 + t*P5)))); + y := 1-((lo - (r*c)/(2-c))-hi); // TODO(rsc): make sure Ldexp can handle boundary k return Ldexp(y, k); } |