Math.gamma(x) â float
Class Public methods
Calculates the gamma function of x.
Note that gamma(n) is same as fact(n-1) for integer n > 0. However
gamma(n) returns float and can be an approximation.
def fact(n) (1..n).inject(1) {|r,i| r*i } end
1.upto(26) {|i| p [i, Math.gamma(i), fact(i-1)] }
#=> [1, 1.0, 1]
# [2, 1.0, 1]
# [3, 2.0, 2]
# [4, 6.0, 6]
# [5, 24.0, 24]
# [6, 120.0, 120]
# [7, 720.0, 720]
# [8, 5040.0, 5040]
# [9, 40320.0, 40320]
# [10, 362880.