summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--configure.in18
-rw-r--r--math.c5
3 files changed, 24 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index e91aaf7..5cf25f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Apr 28 04:49:07 2016 Rei Odaira <Rei.Odaira@gmail.com>
+
+ * configure.in (rb_cv_lgamma_r_pm0): check if lgamma_r(+0.0)
+ returns positive infinity, in addition to lgamma_r(-0.0).
+ AIX returns an incorrect result of negative infinity.
+
+ * math.c (ruby_lgamma_r): handle +0.0, in addition to -0.0.
+
Thu Apr 28 01:11:14 2016 NARUSE, Yui <naruse@ruby-lang.org>
* time.c: define _DEFAULT_SOURCE because glibc 2.20 depracates
diff --git a/configure.in b/configure.in
index 292e40c..1042b03 100644
--- a/configure.in
+++ b/configure.in
@@ -2503,7 +2503,7 @@ main(int argc, char **argv)
AS_IF([test "x$rb_cv_atan2_inf_c99" = xyes], [AC_DEFINE(ATAN2_INF_C99)])
AS_IF([test "x$ac_cv_func_lgamma_r" = xyes], [
- AC_CACHE_CHECK(whether lgamma_r handles -0.0, rb_cv_lgamma_r_m0, [
+ AC_CACHE_CHECK(whether lgamma_r handles +0.0 and -0.0, rb_cv_lgamma_r_pm0, [
AC_TRY_RUN([
@%:@include <math.h>
@%:@ifdef HAVE_UNISTD_H
@@ -2519,22 +2519,28 @@ AS_IF([test "x$ac_cv_func_lgamma_r" = xyes], [
int
main(int argc, char **argv)
{
- int sign;
+ int sign = 0;
double x = lgamma_r(-0.0, &sign);
/* should be [+inf, -1] */
if (x <= 0) return EXIT_FAILURE;
if (!isinf(x)) return EXIT_FAILURE;
if (sign != -1) return EXIT_FAILURE;
+
+ /* should be [+inf, 1] */
+ x = lgamma_r(+0.0, &sign);
+ if (x <= 0) return EXIT_FAILURE;
+ if (!isinf(x)) return EXIT_FAILURE;
+ if (sign != 1) return EXIT_FAILURE;
return EXIT_SUCCESS;
}
],
- [rb_cv_lgamma_r_m0=yes],
- [rb_cv_lgamma_r_m0=no],
- [rb_cv_lgamma_r_m0=yes]
+ [rb_cv_lgamma_r_pm0=yes],
+ [rb_cv_lgamma_r_pm0=no],
+ [rb_cv_lgamma_r_pm0=yes]
)
])
- AS_IF([test "x$rb_cv_lgamma_r_m0" = xno], [AC_DEFINE(LGAMMA_R_M0_FIX)])
+ AS_IF([test "x$rb_cv_lgamma_r_pm0" = xno], [AC_DEFINE(LGAMMA_R_PM0_FIX)])
])
# Some platform need -lrt for clock_gettime, but the other don't.
diff --git a/math.c b/math.c
index 9ac898f..c3fe7db 100644
--- a/math.c
+++ b/math.c
@@ -750,7 +750,7 @@ ruby_tgamma(const double d)
#define tgamma(d) ruby_tgamma(d)
#endif
-#if defined LGAMMA_R_M0_FIX
+#if defined LGAMMA_R_PM0_FIX
static inline double
ruby_lgamma_r(const double d, int *sign)
{
@@ -759,6 +759,9 @@ ruby_lgamma_r(const double d, int *sign)
if (d == 0.0 && signbit(d)) {
*sign = -1;
return INFINITY;
+ } else if (d == 0.0 && !signbit(d)) {
+ *sign = 1;
+ return INFINITY;
}
}
return g;