summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-13 01:05:30 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-13 01:05:30 (GMT)
commitd3ca0b29a6954432a3b8a3f0de17eacf1bd0f1d3 (patch)
tree8adef82b237f5126bc0879cad6f8832a4b96da34 /math.c
parent1a4a536247c3542ed13fd823026066a5149e40ef (diff)
math.c: check argument to lgamma_r
* math.c (math_lgamma): check the argument before calling math function `lgamma_r` for edge cases. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58698 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
-rw-r--r--math.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/math.c b/math.c
index 6a55966..ce49879 100644
--- a/math.c
+++ b/math.c
@@ -778,22 +778,6 @@ math_erfc(VALUE unused_obj, VALUE x)
return DBL2NUM(erfc(Get_Double(x)));
}
-#if defined LGAMMA_R_PM0_FIX
-static inline double
-ruby_lgamma_r(const double d, int *sign)
-{
- const double g = lgamma_r(d, sign);
- if (isinf(g)) {
- if (d == 0.0) {
- *sign = signbit(d) ? -1 : +1;
- return INFINITY;
- }
- }
- return g;
-}
-#define lgamma_r(d, sign) ruby_lgamma_r(d, sign)
-#endif
-
/*
* call-seq:
* Math.gamma(x) -> Float
@@ -911,6 +895,10 @@ math_lgamma(VALUE unused_obj, VALUE x)
if (signbit(d)) domain_error("lgamma");
return rb_assoc_new(DBL2NUM(INFINITY), INT2FIX(1));
}
+ if (d == 0.0) {
+ VALUE vsign = signbit(d) ? INT2FIX(-1) : INT2FIX(+1);
+ return rb_assoc_new(DBL2NUM(INFINITY), vsign);
+ }
v = DBL2NUM(lgamma_r(d, &sign));
return rb_assoc_new(v, INT2FIX(sign));
}