[go: up one dir, main page]

Open In App

math.Lgamma() Function in Golang with Examples

Last Updated : 28 Apr, 2020
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. This package provides Lgamma() function which is used to find the natural logarithm and sign (either -1 or +1) of Gamma(a). So, you need to add a math package in your program with the help of the import keyword to access the Lgamma() function.

Syntax:

func Lgamma(a float64) (lgamma float64, sign int)
  • If Lgamma(+Inf), then this function will return +Inf.
  • If Lgamma(0), then this function will return +Inf.
  • If Lgamma(-integer), then this function will return +Inf.
  • If Lgamma(-Inf), then this function will return -Inf.
  • If Lgamma(NaN), then this function will return NaN.

Example 1:




// Golang program to illustrate
// math.Lgamma() Function
package main
  
import (
    "fmt"
    "math"
)
  
// Main function
func main() {
  
    // Finding the natural logarithm of Gamma()
    // Using Lgamma() function
    res_1, s1 := math.Lgamma(0)
    res_2, s2 := math.Lgamma(-2.3)
    res_3, s3 := math.Lgamma(math.Inf(-2))
    res_4, s4 := math.Lgamma(-2)
    res_5, s5 := math.Lgamma(math.NaN())
  
    // Displaying the result
    fmt.Printf("\nResult 1: %f and sign: %d", res_1, s1)
    fmt.Printf("\nResult 2: %f and sign: %d", res_2, s2)
    fmt.Printf("\nResult 3: %f and sign: %d", res_3, s3)
    fmt.Printf("\nResult 4: %f and sign: %d", res_4, s4)
    fmt.Printf("\nResult 5: %f and sign: %d", res_5, s5)
}


Output:

Result 1: +Inf and sign: 1
Result 2: 0.369567 and sign: -1
Result 3: -Inf and sign: 1
Result 4: +Inf and sign: 1
Result 5: NaN and sign: 1

Example 2:




// Golang program to illustrate
// math.Lgamma() Function
  
package main
  
import (
    "fmt"
    "math"
)
  
// Main function
func main() {
  
    // Finding the natural logarithm of Gamma()
    // Using Lgamma() function
    nvalue_1, sign_1 := math.Lgamma(1.5)
    nvalue_2, sign_2 := math.Lgamma(3.45)
  
    // Finding the sum of the 
    // natural logarithm of Gamma()
    res := nvalue_1 + nvalue_2
    fmt.Printf("Result 1: %f and sign: %d", nvalue_1, sign_1)
    fmt.Printf("\nResult 2: %f and sign: %d \n", nvalue_2, sign_2)
    fmt.Println("Sum of Result 1 and Result 2: ", res)
  
}


Output:

Result 1: -0.120782 and sign: 1
Result 2: 1.146231 and sign: 1 
Sum of Result 1 and Result 2:  1.0254487526135667


Similar Reads

math.Float64bits() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. This package provides Float64bits() function which returns the IEEE 754 binary representation of a with the sign bit of a and the result in the same bit position. So, you need to add a math pack
2 min read
math.Dim() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. Dim() function provided by the math package return the maximum of a-b or 0. So, to access this function you need to add a math package in your program with the help of the import keyword. Syntax
2 min read
math.Expm1 Function() in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You are allowed to find base-e exponential of the specified number minus 1, i.e., e**a -1 with the help of Expm1() function provided by the math package. So, you need to add a math package in yo
2 min read
math.Hypot Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the hypotenuse, i.e., Sqrt(a*a + b*b) with the help of Hypot() function provided by the math package. So, you need to add a math package in your program with the help of the import
2 min read
math.Round() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can round off the given number to the nearest integer(rounding half away from zero) with the help of Round() function provided by the math package. So, you need to add a math package in your
2 min read
math.Remainder() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the remainder or the IEEE 754 floating-point remainder of a/b with the help of Remainder() function provided by the math package. So, you need to add a math package in your program
2 min read
math.RoundToEven() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can round off the given number to the nearest even integer with the help of RoundToEven() function provided by the math package. So, you need to add a math package in your program with the h
2 min read
math.Signbit() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You check whether the sign of the specified number is negative or negative zero with the help of Signbit() function provided by the math package. If the sign of the given number is negative, the
2 min read
math.NaN() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You get an IEEE 754 "not-a-number" value with the help of NaN() function provided by the math package. So, you need to add a math package in your program with the help of the import keyword to a
1 min read
math.Y0() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the order-zero Bessel function of the second kind with the help of Y0() function provided by the math package. So, you need to add a math package in your program with the help of th
2 min read
math.Y1() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the order-one Bessel function of the second kind with the help of Y1() function provided by the math package. So, you need to add a math package in your program with the help of the
2 min read
math.Yn() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can the order-n Bessel function of the second kind the help of Yn() function provided by the math package. So, you need to add a math package in your program with the help of the import keyw
2 min read
math.Pow() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the base-a exponential of b(a**b)with the help of Pow() function provided by the math package. So, you need to add a math package in your program with the help of the import keyword
3 min read
math.Inf() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find positive infinity (if sign >= 0) or negative infinity (if sign < 0) with the help of the Inf() function provided by the math package. So, you need to add a math package in you
2 min read
math.J0() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the order-zero Bessel function of the first kind with the help of J0() function provided by the math package. So, you need to add a math package in your program with the help of the
2 min read
math.J1() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find order-one Bessel function of the first kind with the help of J1() function provided by the math package. So, you need to add a math package in your program with the help of the impo
2 min read
math.Jn() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the order-n Bessel function of the first kind with the help of Jn() function provided by the math package. So, you need to add a math package in your program with the help of the im
2 min read
math.Gamma() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the Gamma function the given value with the help of the Gamma() function provided by the math package. So, you need to add a math package in your program with the help of the import
2 min read
math.Atan2() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the arc tangent of a/b, using the signs of the two to identify the quadrant of the return value with the help of Atan2() function provided by the math package. So, you need to add a
2 min read
math.Ilogb() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can find the binary exponent of the specified number as an integer with the help of ILogb() function provided by the math package. So, you need to add a math package in your program with the
2 min read
math.Float32bits() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. This package provides Float32bits() function which returns the IEEE 754 binary representation of a with the sign bit of a and the result in the same bit position. So, you need to add a math pack
2 min read
math.Float32frombits() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. This package provides Float32frombits() function which returns the floating-point number corresponding to the IEEE 754 binary representation a, with the sign bit of a and the result in the same
2 min read
math.Float64frombits() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. This package provides Float64frombits() function which returns the floating-point number corresponding to the IEEE 754 binary representation a, with the sign bit of a and the result in the same
2 min read
math.IsNaN() Function in Golang with Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. This package provides IsNaN() function which is used to check whether x is an IEEE 754 “not-a-number” value or not. This function return true if x is an IEEE 754 "not-a-number" value. Otherwise,
2 min read
math.Ldexp() Function in Golang with Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. This package provides Ldexp() function which is used to find the inverse of Frexp. Or in other words, this function return frac × 2**exp. So, you need to add a math package in your program with
2 min read
math Package in Golang
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. FunctionDescriptionAbsThis function is used to return the absolute value of the specified number.AcosThis function returns the arccosine, in radians of the specified number.AcoshThis function re
7 min read
atomic.AddInt64() Function in Golang With Examples
In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The AddInt64() function in Go language is used to automatically add delta to the *addr. This function is defined under the atomic package. Here, you need to import "sync/atomic" package in order to use these functions. Syntax
3 min read
atomic.StoreInt64() Function in Golang With Examples
In Go language, atomic packages supply lower-level atomic memory that is helpful is implementing synchronization algorithms. The StoreInt64() function in Go language is used to atomically store val into *addr. This function is defined under the atomic package. Here, you need to import "sync/atomic" package in order to use these functions. Syntax: f
2 min read
reflect.FieldByIndex() Function in Golang with Examples
Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.FieldByIndex() Function in Golang is used to get the nested field corresponding to index. To access this function, one needs to imports the reflect package in the
2 min read
strings.Contains Function in Golang with Examples
strings.Contains Function in Golang is used to check the given letters present in the given string or not. If the letter is present in the given string, then it will return true, otherwise, return false. Syntax: func Contains(str, substr string) bool Here, str is the original string and substr is the string that you want to check. Let us discuss th
2 min read
Article Tags :
three90RightbarBannerImg