Published Aug 9, 2023
Contribute to Docs

The Log10() function in the Go programming language calculates the base-10 logarithm of a given number. It returns the logarithm value as a floating-point number. The math package must be imported to use this function.


result := Log10(x)

Log10() accepts an argument of type float64 and returns a value of type float64.

Note these special cases:

  • If x is negative or Nan, the function will return NaN (not-a-number).
  • If x is zero, the result will be -Inf.
  • If x is +Inf, the result will be +Inf.


The example below demonstrates the basic use of Log10().

package main
import (
func main() {
x := 10.0
result := math.Log10(x)
fmt.Printf("Log10(%f) = %f\n", x, result)

The above code results in the following output:

Log10(10.000000) = 1.000000

Codebyte Example

The example below is runnable and demonstrates the results of Log10() with several values.

Visit us
Hide code
Hide output
Hide output

All contributors

Looking to contribute?

Learn Go on Codecademy