Ruby Tutorial Ruby References

Ruby - Math.gamma() Method



The Ruby Math.gamma() method returns the gamma function of the argument. The gamma function of x is defined as:

gamma
Gamma Function

Syntax

Math.gamma(x)

Parameters

x Specify the value.

Return Value

Returns the gamma function of the argument.

Example:

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

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

The output of the above code will be:

Math.gamma(-2.5) = -0.9453087204829418
Math.gamma(-1.5) = 2.363271801207355
Math.gamma(-0.5) = -3.5449077018110318
Math.gamma(0.5) = 1.772453850905516
Math.gamma(1.5) = 0.886226925452758
Math.gamma(2.5) = 1.329340388179137

❮ Ruby Math Module