Go math.Log10
In Go, math.Log10 returns the base-ten logarithm of a positive number. A result of 2 for 100 means that 10² = 100.
A simple example
math.Log10
- Start with 100
- Do this Find the base-10 logarithm
- Result 2
package main
import "fmt"
import "math"
func main() {
fmt.Println(math.Log10(100.0))
}
2
Syntax
math.Log10(ratio)
Run these examples in Go
Save one example at a time as main.go. Use Go 1.21 or later.
go run main.goCount orders of magnitude in a reading
A sensor report must compare readings that span very different scales. Express the measurements on a logarithmic scale so a multiplicative change has a manageable numerical description.
package main
import (
"fmt"
"math"
)
func main() {
ratio := 1000.0
fmt.Printf("%.3f\n", math.Log10(ratio))
}
3.000
A sensor reading 1000 times its baseline is three orders of magnitude higher.
Compare light meter readings
A lab compares readings from a light meter over a wide range of intensities. Convert the readings to a logarithmic scale to see their separation in orders of magnitude.
package main
import (
"fmt"
"math"
)
func main() {
ratio := 100.0
fmt.Printf("%.3f\n", math.Log10(ratio))
}
2.000
A reading one hundred times its baseline is two powers of ten above it.
Mark a tenfold light change
A sensor reads ten times its reference intensity. The chart marks powers of ten on its vertical scale.
Using 10 gives 1.000 for this measurement.
What to watch for
A zero or negative ratio has no finite real base-ten logarithm.