Log()
Anonymous contributor
Anonymous contributor2 total contributions
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 contributorAnonymous contributor2 total contributions
- Anonymous contributor
Looking to contribute?
- 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.