Ruby Tutorial Ruby References

Ruby - Math.lgamma() Method



The Ruby Math.lgamma() method returns the natural logarithm of the absolute value of the gamma function (log gamma function) of the argument and the sign of gamma function of the argument. The log gamma function of x is defined as:

lgamma
Log-gamma Function

Syntax

Math.lgamma(x)

Parameters

x Specify the value.

Return Value

Returns the natural logarithm of the absolute value of the gamma function of the argument and the sign of gamma function of the argument.

Example:

The example below shows the usage of Math.lgamma() function.

puts "Math.lgamma(-2.5) = #{Math.lgamma(-2.5)}"
puts "Math.lgamma(-1.5) = #{Math.lgamma(-1.5)}"
puts "Math.lgamma(-0.5) = #{Math.lgamma(-0.5)}"
puts "Math.lgamma(0.5) = #{Math.lgamma(0.5)}"
puts "Math.lgamma(1.5) = #{Math.lgamma(1.5)}"
puts "Math.lgamma(2.5) = #{Math.lgamma(2.5)}"

The output of the above code will be:

Math.lgamma(-2.5) = [-0.05624371649767407, -1]
Math.lgamma(-1.5) = [0.8600470153764809, 1]
Math.lgamma(-0.5) = [1.2655121234846454, -1]
Math.lgamma(0.5) = [0.5723649429247001, 1]
Math.lgamma(1.5) = [-0.12078223763524522, 1]
Math.lgamma(2.5) = [0.2846828704729192, 1]

❮ Ruby Math Module