summaryrefslogtreecommitdiff
path: root/src/pkg/math/exp.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/math/exp.go')
-rw-r--r--src/pkg/math/exp.go38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/pkg/math/exp.go b/src/pkg/math/exp.go
index cdee0d70a..9ad2b3877 100644
--- a/src/pkg/math/exp.go
+++ b/src/pkg/math/exp.go
@@ -90,18 +90,18 @@ package math
// Very small values underflow to 1.
func Exp(x float64) float64 {
const (
- 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 */
+ 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 */
- Overflow = 7.09782712893383973096e+02;
- Underflow = -7.45133219101941108420e+02;
- NearZero = 1.0 / (1 << 28); // 2^-28
+ Overflow = 7.09782712893383973096e+02
+ Underflow = -7.45133219101941108420e+02
+ NearZero = 1.0 / (1 << 28) // 2^-28
)
// special cases
@@ -119,21 +119,21 @@ func Exp(x float64) float64 {
}
// reduce; computed as r = hi - lo for extra precision.
- var k int;
+ var k int
switch {
case x < 0:
k = int(Log2e*x - 0.5)
case x > 0:
k = int(Log2e*x + 0.5)
}
- hi := x - float64(k)*Ln2Hi;
- lo := float64(k) * Ln2Lo;
- r := hi - lo;
+ hi := x - float64(k)*Ln2Hi
+ lo := float64(k) * Ln2Lo
+ 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);
+ return Ldexp(y, k)
}