Go Log10()
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.
Syntax
result := Log10(x)
Log10() accepts an argument of type float64 and returns a value of type float64.
Note these special cases:
- If
xis negative orNan, the function will returnNaN(not-a-number). - If
xis zero, the result will be-Inf. - If
xis+Inf, the result will be+Inf.
Example
The example below demonstrates the basic use of Log10().
package mainimport ("fmt""math")func main() {x := 10.0result := 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.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Go on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn how to use Go (Golang), an open-source programming language supported by Google!
- Beginner Friendly.6 hours