/*
 * call-seq:
 *    Math.lgamma(x)  => [float, -1 or 1]
 *
 *  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.
 */

static VALUE
math_lgamma(VALUE obj, VALUE x)
{
    double d;
    int sign;
    VALUE v;
    Need_Float(x);
    errno = 0;
    d = lgamma_r(RFLOAT_VALUE(x), &sign);
    domain_check(d, "lgamma");
    v = DOUBLE2NUM(d);
    return rb_assoc_new(v, INT2FIX(sign));
}