Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Math.lgamma

Math.lgamma(x) → [float, -1 or 1]

Calculates the logarithmic gamma of x and the sign of gamma of x.

Math.lgamma(x) is the same as

Example
[Math.log(Math.gamma(x).abs), Math.gamma(x) < 0 ? -1 : 1]

but avoids overflow by Math.gamma(x) for large x.

Example
Math.lgamma(0) #=> [Infinity, 1]
See also .ldexp .log .hypot .log10 also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0