find the base e logarithm of a number in go

To find the base e logarithm of a number in Go, you can use the math package's Log function. The Log function takes in the number whose logarithm needs to be found as the first argument and the base of the logarithm as the second argument. Since we want to find the base e logarithm, we can pass in the math.E constant as the second argument. Here's an example:

main.go
package main

import (
    "fmt"
    "math"
)

func main() {
    num := 10.0
    log := math.Log(num)

    fmt.Printf("The base e logarithm of %g is %g\n", num, log)
}
168 chars
14 lines

Output:

main.go
The base e logarithm of 10 is 2.302585092994046
48 chars
2 lines

related categories

gistlibby LogSnag