diff --git a/ChangeLog b/ChangeLog index 90ecdf6311..b16c96f7ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Feb 9 11:47:03 2008 Tanaka Akira + + * math.c (math_gamma): add error check. + (math_lgamma): ditto. + Sat Feb 9 11:09:26 2008 Tanaka Akira * missing/lgamma_r.c (lgamma_r): return HUGE_VAL for non-positive diff --git a/math.c b/math.c index e457716345..fd10e97008 100644 --- a/math.c +++ b/math.c @@ -530,8 +530,12 @@ math_erfc(VALUE obj, VALUE x) static VALUE math_gamma(VALUE obj, VALUE x) { + double d; Need_Float(x); - return DOUBLE2NUM(tgamma(RFLOAT_VALUE(x))); + errno = 0; + d = tgamma(RFLOAT_VALUE(x)); + domain_check(d, "gamma"); + return DOUBLE2NUM(d); } /* @@ -549,10 +553,14 @@ math_gamma(VALUE obj, VALUE x) static VALUE math_lgamma(VALUE obj, VALUE x) { + double d; int sign; VALUE v; Need_Float(x); - v = DOUBLE2NUM(lgamma_r(RFLOAT_VALUE(x), &sign)); + errno = 0; + d = lgamma_r(RFLOAT_VALUE(x), &sign); + domain_check(d, "lgamma"); + v = DOUBLE2NUM(d); return rb_assoc_new(v, INT2FIX(sign)); }