summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-13 00:50:20 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-13 00:50:20 (GMT)
commit1a4a536247c3542ed13fd823026066a5149e40ef (patch)
tree456d976cd1d742383510ffbf391ea9060a7c957f /math.c
parent94a7a4e908f3020045d1ae64c7ee4e70b14f2a5e (diff)
math.c: check argument to tgamma
* math.c (math_gamma): check the argument before calling math function `tgamma` for edge cases. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
-rw-r--r--math.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/math.c b/math.c
index 570776b..6a55966 100644
--- a/math.c
+++ b/math.c
@@ -869,7 +869,13 @@ math_gamma(VALUE unused_obj, VALUE x)
double d;
d = Get_Double(x);
/* check for domain error */
- if (isinf(d) && signbit(d)) domain_error("gamma");
+ if (isinf(d)) {
+ if (signbit(d)) domain_error("gamma");
+ return DBL2NUM(INFINITY);
+ }
+ if (d == 0.0) {
+ return signbit(d) ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY);
+ }
if (d == floor(d)) {
if (d < 0.0) domain_error("gamma");
if (1.0 <= d && d <= (double)NFACT_TABLE) {