From c8aa30a95806939cc1d65e74895f2b57e6419d6c Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 9 Feb 2008 02:47:50 +0000 Subject: [PATCH] * math.c (math_gamma): add error check. (math_lgamma): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ math.c | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) 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)); }