Method: Math#lgamma

Defined in:
math.c

#lgamma(x) ⇒ Array, ... (private)

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

Math.lgamma(x) is same as
 [Math.log(Math.gamma(x).abs), Math.gamma(x) < 0 ? -1 : 1]
but avoid overflow by Math.gamma(x) for large x.

  Math.lgamma(0) #=> [Infinity, 1]

Returns ].

Returns:



880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
# File 'math.c', line 880

static VALUE
math_lgamma(VALUE obj, VALUE x)
{
    double d0, d;
    int sign=1;
    VALUE v;
    Need_Float(x);
    d0 = RFLOAT_VALUE(x);
    /* check for domain error */
    if (isinf(d0)) {
	if (signbit(d0)) domain_error("lgamma");
	return rb_assoc_new(DBL2NUM(INFINITY), INT2FIX(1));
    }
    d = lgamma_r(d0, &sign);
    v = DBL2NUM(d);
    return rb_assoc_new(v, INT2FIX(sign));
}