summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
Diffstat (limited to 'math.c')
-rw-r--r--math.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/math.c b/math.c
index 9aff66333a..0028577340 100644
--- a/math.c
+++ b/math.c
@@ -774,6 +774,38 @@ math_erfc(VALUE obj, VALUE x)
return DBL2NUM(erfc(RFLOAT_VALUE(x)));
}
+#if defined __MINGW32__
+static inline double
+ruby_tgamma(const double d)
+{
+ const double g = tgamma(d);
+ 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 lgamma_r(d, sign) ruby_lgamma_r(d, sign)
+#endif
+
/*
* call-seq:
* Math.gamma(x) -> Float