Menu Close

Go – How to get the gamma value of number in go

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

Function prototype:

func Gamma(x float64) float64

Return value:

Gamma() function in math package returns
the gamma value of number.

Example with code:

package main

import (
  "fmt"
  "math"
)

func main() {

  no := math.Gamma(1)
  fmt.Printf("%.1f\n", no)

  no = math.Gamma(0)
  fmt.Printf("%.1f\n", no)

  no = math.Gamma(0.25)
  fmt.Printf("%.1f\n", no)

  no = math.Gamma(-1)
  fmt.Printf("%.1f\n", no)
}

Output:

1.0
+Inf
3.6
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 *