Open In App

Ruby | Math lgamma() function

Last Updated : 07 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The lgamma() function in Ruby returns two numbers, one represents the logarithmic gamma of value while the other signifies the sign of gamma of value.

Syntax: Math.lgamma(value)

Parameter: The function takes one mandatory parameter value whose logarithmic gamma is returned and its sign.

Return Value: The function returns two numbers, where one represents the logarithmic gamma of value while the other signifies the sign of gamma of value.

Example 1:




# Ruby program for lgamma() function 
  
# Assigning values
val1 = 132 
val2 = 0 
val3 = -23
val4 = 1
  
# Prints the value returned by lgamma() 
puts Math.lgamma(val1)
puts
  
puts Math.lgamma(val2)
puts
  
puts Math.lgamma(val3)
puts
  
puts Math.lgamma(val4)


Output:

511.00802266523596
1

Infinity
1

Infinity
1

0.0
1

Example 2:




# Ruby program for lgamma() function 
  
# Assigning values
val1 = -1
val2 = 2 
val3 = -2
val4 = -9
  
# Prints the value returned by lgamma() 
puts Math.lgamma(val1)
puts
  
puts Math.lgamma(val2)
puts
  
puts Math.lgamma(val3)
puts
  
puts Math.lgamma(val4)


Output:

Infinity
1

0.0
1

Infinity
1

Infinity
1

Reference: https://devdocs.io/ruby~2.5/math#method-c-lgamma



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads