github.com/primecitizens/pcz/std@v0.2.1/math/log10.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package math 6 7 // Log10 returns the decimal logarithm of x. 8 // The special cases are the same as for Log. 9 func Log10(x float64) float64 { 10 return log10(x) 11 } 12 13 func log10(x float64) float64 { 14 return Log(x) * (1 / Ln10) 15 } 16 17 // Log2 returns the binary logarithm of x. 18 // The special cases are the same as for Log. 19 func Log2(x float64) float64 { 20 return log2(x) 21 } 22 23 func log2(x float64) float64 { 24 frac, exp := Frexp(x) 25 // Make sure exact powers of two give an exact answer. 26 // Don't depend on Log(0.5)*(1/Ln2)+exp being exactly exp-1. 27 if frac == 0.5 { 28 return float64(exp - 1) 29 } 30 return Log(frac)*(1/Ln2) + float64(exp) 31 }