summaryrefslogtreecommitdiff
path: root/src/pkg/math/log.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/math/log.go')
-rw-r--r--src/pkg/math/log.go29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/pkg/math/log.go b/src/pkg/math/log.go
index 4f9a37606..22df7ac1b 100644
--- a/src/pkg/math/log.go
+++ b/src/pkg/math/log.go
@@ -43,7 +43,7 @@ package math
// | |
// Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
// In order to guarantee error in log below 1ulp, we compute log by
-// log(1+f) = f - s*(f - R) (if f is not too large)
+// log(1+f) = f - s*(f - R) (if f is not too large)
// log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy)
//
// 3. Finally, log(x) = k*Ln2 + log(1+f).
@@ -76,15 +76,15 @@ package math
// Log(NaN) = NaN
func Log(x float64) float64 {
const (
- Ln2Hi = 6.93147180369123816490e-01; /* 3fe62e42 fee00000 */
- Ln2Lo = 1.90821492927058770002e-10; /* 3dea39ef 35793c76 */
- L1 = 6.666666666666735130e-01; /* 3FE55555 55555593 */
- L2 = 3.999999999940941908e-01; /* 3FD99999 9997FA04 */
- L3 = 2.857142874366239149e-01; /* 3FD24924 94229359 */
- L4 = 2.222219843214978396e-01; /* 3FCC71C5 1D8E78AF */
- L5 = 1.818357216161805012e-01; /* 3FC74664 96CB03DE */
- L6 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */
- L7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
+ Ln2Hi = 6.93147180369123816490e-01; /* 3fe62e42 fee00000 */
+ Ln2Lo = 1.90821492927058770002e-10; /* 3dea39ef 35793c76 */
+ L1 = 6.666666666666735130e-01; /* 3FE55555 55555593 */
+ L2 = 3.999999999940941908e-01; /* 3FD99999 9997FA04 */
+ L3 = 2.857142874366239149e-01; /* 3FD24924 94229359 */
+ L4 = 2.222219843214978396e-01; /* 3FCC71C5 1D8E78AF */
+ L5 = 1.818357216161805012e-01; /* 3FC74664 96CB03DE */
+ L6 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */
+ L7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
)
// special cases
@@ -103,7 +103,7 @@ func Log(x float64) float64 {
f1 *= 2;
ki--;
}
- f := f1 - 1;
+ f := f1-1;
k := float64(ki);
// compute
@@ -112,9 +112,9 @@ func Log(x float64) float64 {
s4 := s2*s2;
t1 := s2*(L1 + s4*(L3 + s4*(L5 + s4*L7)));
t2 := s4*(L2 + s4*(L4 + s4*L6));
- R := t1 + t2;
+ R := t1+t2;
hfsq := 0.5*f*f;
- return k*Ln2Hi - ((hfsq-(s*(hfsq+R)+k*Ln2Lo)) - f);
+ return k*Ln2Hi - ((hfsq-(s*(hfsq+R) + k*Ln2Lo))-f);
}
// Log10 returns the decimal logarithm of x.
@@ -123,6 +123,5 @@ func Log10(x float64) float64 {
if x <= 0 {
return NaN();
}
- return Log(x) * (1/Ln10);
+ return Log(x)*(1/Ln10);
}
-