What is the Lgamma function in Golang?
The Lgamma function in the Go programming language is used to find the value of the natural logarithm and sign of Gamma(), where is the input value to the Lgamma function.
To use the Lgamma function, you must import the math package in your file and access the Lgamma function within it using the . notation (math.Lgamma). Here, Lgamma is the actual function, while math is the Go package that stores the definition of this function.
Syntax
The definition of the Lgamma function inside the math package is shown below:
Parameters
The Lgamma function takes a single argument of type float64, whose gamma value and sign you wish to find.
Return value
The Lgamma function returns two values:
-
lgamma: This return value has typefloat64and represents the natural logarithm of Gamma() ( here, represents the input value). -
sign: This return value has typeintand represents the sign of the above value. This return value is restricted to either +1 or -1.
Special cases of return values:
-
+Inf: Positive infinity is returned if the input given is positive infinity,0, or a negative integer. -
-Inf: Negative infinity is returned if the input given is negative infinity. -
NAN: ANANis returned if the input isNAN.
Examples
Below is a simple example in which we use the Lgamma function on 25:
package mainimport "fmt"import "math"func main() {inp := 25.0x, y := math.Lgamma(inp)fmt.Print("natural log of Gamma(",inp, "):", x,"\n")fmt.Println("sign:", y)}