1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
akr 2008-02-09 02:47:50 +00:00
parent 1c6e4ff1a0
commit c8aa30a958
2 changed files with 15 additions and 2 deletions

View file

@ -1,3 +1,8 @@
Sat Feb 9 11:47:03 2008 Tanaka Akira <akr@fsij.org>
* math.c (math_gamma): add error check.
(math_lgamma): ditto.
Sat Feb 9 11:09:26 2008 Tanaka Akira <akr@fsij.org> Sat Feb 9 11:09:26 2008 Tanaka Akira <akr@fsij.org>
* missing/lgamma_r.c (lgamma_r): return HUGE_VAL for non-positive * missing/lgamma_r.c (lgamma_r): return HUGE_VAL for non-positive

12
math.c
View file

@ -530,8 +530,12 @@ math_erfc(VALUE obj, VALUE x)
static VALUE static VALUE
math_gamma(VALUE obj, VALUE x) math_gamma(VALUE obj, VALUE x)
{ {
double d;
Need_Float(x); 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 static VALUE
math_lgamma(VALUE obj, VALUE x) math_lgamma(VALUE obj, VALUE x)
{ {
double d;
int sign; int sign;
VALUE v; VALUE v;
Need_Float(x); 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)); return rb_assoc_new(v, INT2FIX(sign));
} }