Menu Close

Go – How to get the the natural logarithm of 1 plus its argument x in go

Here, We will learn how to get the the natural logarithm of 1 plus its argument x in go. We can get it by using Log1p() function in math package in go golang.

Function prototype:

func Log1p(x float64) float64

Return value:

Log1p() function in math package returns
the natural logarithm of 1 plus its
argument x. It is more accurate than
Log(1 + x) when x is near zero.

Example with code:

package main

import (
  "fmt"
  "math"
)

func main() {

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

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

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

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

Output:

0.7884573603642702
1.1939224684724346
0
NaN

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

https://www.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 *