Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

Math.gamma

(::Math::double x) -> ::Float
Math.gamma(x) → float

Returns the value of the gamma function for x.

  • Domain: (-INFINITY, INFINITY] excluding negative integers.

  • Range: [-INFINITY, INFINITY].

Examples:

Example
gamma(-2.5)      # => -0.9453087204829431
gamma(-1.5)      # => 2.3632718012073513
gamma(-0.5)      # => -3.5449077018110375
gamma(0.0)      # => Infinity
gamma(1.0)      # => 1.0
gamma(2.0)      # => 1.0
gamma(3.0)      # => 2.0
gamma(4.0)      # => 6.0
gamma(5.0)      # => 24.0

Related: Math.lgamma.

See also .frexp .hypot .expm1 .ldexp also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0