summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-09 02:47:50 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-09 02:47:50 +0000
commitc8aa30a95806939cc1d65e74895f2b57e6419d6c (patch)
treedaa248e8cd45e8cdafe582d000ed24fae9de7ad0 /math.c
parent1c6e4ff1a011e3211723b1d668a536f3e8846702 (diff)
* 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
Diffstat (limited to 'math.c')
-rw-r--r--math.c12
1 files changed, 10 insertions, 2 deletions
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));
}