Log()
Anonymous contributor
Published Jul 25, 2023
Contribute to Docs
The Log()
function returns the natural logarithm of a given number of type float64
. The math
library must be imported in order to use this function.
Syntax
import math
result := math.Log(number)
Where result
is the logarithmic value of number
, returned as type float64
, except under the following circumstances:
- The result of
Log(+Inf)
is +Inf - The result of
Log(0)
is -Inf - The result of
Log(x < 0)
isNaN
- The result of
Log(NaN)
isNaN
Example
The following calculates the logarithm of number
and prints out the result:
package mainimport ("fmt""math")func main() {number := 4.2result := math.Log(number)fmt.Printf("%.1f\n", result)}
The above code results in the following output:
1.4
Codebyte Example
The following example is runnable and shows how the Log()
function handles special cases where zero or a negative number are supplied as arguments.
All contributors
- Anonymous contributor
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
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Go
Learn how to use Go (Golang), an open-source programming language supported by Google!Beginner Friendly6 hours