summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-18 17:46:05 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-18 17:46:05 +0000
commite824b05b3e0c01905d38af7d9c669ddc55cfcfb3 (patch)
treefa7d3e0e89bc9a638258607e3cdb2e6f937a545a /math.c
parentb7c90baf074156456e2ba5216c492e8b79b8bc3c (diff)
merge revision(s) 54492,54494,54495,54496,54499,54503: [Backport #12249]
* math.c (ruby_tgamma): fix tgamma(-0.0) on mingw. [ruby-core:74817] [Bug #12249] * math.c (ruby_lgamma_r): fix lgamma(-0.0) on mingw and OSX. * math.c (ruby_lgamma_r): mswin's lgamma_r also seems to be wrong. cf. [Bug #12249] * math.c (ruby_lgamma_r): missing/lgamma_r.c is used on Windows, since msvcrt does not provide it. * missing/lgamma_r.c (lgamma_r): fix lgamma(-0.0). [ruby-core:74823] [Bug #12249] * configure.in (rb_cv_lgamma_r_m0): check if lgamma_r(-0.0) returns negative infinity. [Bug #12249] * math.c (ruby_lgamma_r): define by the configured result. * configure.in (rb_cv_lgamma_r_m0): fix the condition for lgamma_r(-0.0). [Bug #12249] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@54643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
-rw-r--r--math.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/math.c b/math.c
index 591d6ae2f2..9ac898f0ba 100644
--- a/math.c
+++ b/math.c
@@ -734,14 +734,36 @@ math_erfc(VALUE obj, VALUE x)
return DBL2NUM(erfc(Get_Double(x)));
}
-#ifdef __MINGW32__
+#if defined __MINGW32__
static inline double
-mingw_tgamma(const double d)
+ruby_tgamma(const double d)
{
const double g = tgamma(d);
- return (isnan(g) && !signbit(d)) ? INFINITY : g;
+ if (isinf(g)) {
+ if (d == 0.0 && signbit(d)) return -INFINITY;
+ }
+ if (isnan(g)) {
+ if (!signbit(d)) return INFINITY;
+ }
+ return g;
+}
+#define tgamma(d) ruby_tgamma(d)
+#endif
+
+#if defined LGAMMA_R_M0_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 && signbit(d)) {
+ *sign = -1;
+ return INFINITY;
+ }
+ }
+ return g;
}
-#define tgamma(d) mingw_tgamma(d)
+#define lgamma_r(d, sign) ruby_lgamma_r(d, sign)
#endif
/*