红宝石 |数学 lgamma()函数
Ruby 中的lgamma()函数返回两个数字,一个表示value 的对数 gamma,而另一个表示 value的gamma 的符号。
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.
示例 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)
输出:
511.00802266523596
1
Infinity
1
Infinity
1
0.0
1
示例 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)
输出:
Infinity
1
0.0
1
Infinity
1
Infinity
1
参考:https://devdocs.io/ruby~2.5/math#method-c-lgamma