Menu Close

Go – How to get the natural logarithm of number in go

Here, We will learn how to get the natural logarithm of number in go. We can get it by using Log() function in math package in go golang.

Function prototype:

func Log(num float64) float64

Return value:

Log() function in math package returns
the natural logarithm of number.

Example with code:

package main

import (
  "fmt"
  "math"
)

func main() {

  no := math.Log(1.2)
  fmt.Println(no)

  no = math.Log(2.3)
  fmt.Println(no)

  no = math.Log(0.0)
  fmt.Println(no)

  no = math.Log(-2.9)
  fmt.Println(no)
}

Output:

0.1823215567939546
0.832909122935104
-Inf
NaN

To learn more about golang, Please refer given below link:

https://techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, math

Leave a Reply

Your email address will not be published. Required fields are marked *