[前][次][番号順一覧][スレッド一覧]

ruby-changes:42569

From: nagachika <ko1@a...>
Date: Tue, 19 Apr 2016 01:49:30 +0900 (JST)
Subject: [ruby-changes:42569] nagachika:r54643 (ruby_2_3): merge revision(s) 54492, 54494, 54495, 54496, 54499, 54503: [Backport #12249]

nagachika	2016-04-19 02:46:05 +0900 (Tue, 19 Apr 2016)

  New Revision: 54643

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54643

  Log:
    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]

  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/ChangeLog
    branches/ruby_2_3/configure.in
    branches/ruby_2_3/math.c
    branches/ruby_2_3/missing/lgamma_r.c
    branches/ruby_2_3/test/ruby/test_math.rb
    branches/ruby_2_3/version.h
Index: ruby_2_3/ChangeLog
===================================================================
--- ruby_2_3/ChangeLog	(revision 54642)
+++ ruby_2_3/ChangeLog	(revision 54643)
@@ -1,3 +1,33 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1
+Tue Apr 19 02:32:50 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* configure.in (rb_cv_lgamma_r_m0): fix the condition for
+	  lgamma_r(-0.0).  [Bug #12249]
+
+Tue Apr 19 02:32:50 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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.
+
+Tue Apr 19 02:32:50 2016  cremno phobia  <cremno@m...>
+
+	* 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]
+
+Tue Apr 19 02:32:50 2016  NAKAMURA Usaku  <usa@r...>
+
+	* math.c (ruby_lgamma_r): mswin's lgamma_r also seems to be wrong.
+	  cf. [Bug #12249]
+
+Tue Apr 19 02:32:50 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* math.c (ruby_tgamma): fix tgamma(-0.0) on mingw.
+	  [ruby-core:74817] [Bug #12249]
+
 Tue Apr 19 01:53:32 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* defs/keywords (alias, undef): symbol literals are allowed.
Index: ruby_2_3/test/ruby/test_math.rb
===================================================================
--- ruby_2_3/test/ruby/test_math.rb	(revision 54642)
+++ ruby_2_3/test/ruby/test_math.rb	(revision 54643)
@@ -255,6 +255,10 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_math.rb#L255
     end
 
     assert_raise(Math::DomainError) { Math.gamma(-Float::INFINITY) }
+    x = Math.gamma(-0.0)
+    mesg = "Math.gamma(-0.0) should be -INF"
+    assert_infinity(x, mesg)
+    assert_predicate(x, :negative?, mesg)
   end
 
   def test_lgamma
@@ -271,6 +275,11 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_math.rb#L275
     assert_float_and_int([Math.log(6),                1], Math.lgamma(4))
 
     assert_raise(Math::DomainError) { Math.lgamma(-Float::INFINITY) }
+    x, sign = Math.lgamma(-0.0)
+    mesg = "Math.lgamma(-0.0) should be [INF, -1]"
+    assert_infinity(x, mesg)
+    assert_predicate(x, :positive?, mesg)
+    assert_equal(-1, sign, mesg)
   end
 
   def test_fixnum_to_f
Index: ruby_2_3/configure.in
===================================================================
--- ruby_2_3/configure.in	(revision 54642)
+++ ruby_2_3/configure.in	(revision 54643)
@@ -2438,6 +2438,41 @@ main(int argc, char **argv) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/configure.in#L2438
 ])
 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_TRY_RUN([
+@%:@include <math.h>
+@%:@ifdef HAVE_UNISTD_H
+@%:@include <unistd.h>
+@%:@endif
+@%:@ifndef EXIT_SUCCESS
+@%:@define EXIT_SUCCESS 0
+@%:@endif
+@%:@ifndef EXIT_FAILURE
+@%:@define EXIT_FAILURE 1
+@%:@endif
+
+int
+main(int argc, char **argv)
+{
+    int sign;
+    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;
+    return EXIT_SUCCESS;
+}
+],
+	[rb_cv_lgamma_r_m0=yes],
+	[rb_cv_lgamma_r_m0=no],
+	[rb_cv_lgamma_r_m0=yes]
+	)
+    ])
+    AS_IF([test "x$rb_cv_lgamma_r_m0" = xno], [AC_DEFINE(LGAMMA_R_M0_FIX)])
+])
+
 # Some platform need -lrt for clock_gettime, but the other don't.
 if test x"$ac_cv_func_clock_gettime" != xyes; then
     # glibc 2.17 moves clock_* functions from librt to the main C library.
Index: ruby_2_3/missing/lgamma_r.c
===================================================================
--- ruby_2_3/missing/lgamma_r.c	(revision 54642)
+++ ruby_2_3/missing/lgamma_r.c	(revision 54643)
@@ -66,7 +66,7 @@ lgamma_r(double x, int *signp) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/missing/lgamma_r.c#L66
         double i, f, s;
         f = modf(-x, &i);
         if (f == 0.0) { /* pole error */
-            *signp = 1;
+            *signp = signbit(x) ? -1 : 1;
             errno = ERANGE;
             return HUGE_VAL;
         }
Index: ruby_2_3/math.c
===================================================================
--- ruby_2_3/math.c	(revision 54642)
+++ ruby_2_3/math.c	(revision 54643)
@@ -734,14 +734,36 @@ math_erfc(VALUE obj, VALUE x) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/math.c#L734
     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) mingw_tgamma(d)
+#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
 
 /*
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 54642)
+++ ruby_2_3/version.h	(revision 54643)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.0"
 #define RUBY_RELEASE_DATE "2016-04-19"
-#define RUBY_PATCHLEVEL 94
+#define RUBY_PATCHLEVEL 95
 
 #define RUBY_RELEASE_YEAR 2016
 #define RUBY_RELEASE_MONTH 4

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r54492,54494-54496,54499,54503


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]