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

ruby-changes:42418

From: nobu <ko1@a...>
Date: Tue, 5 Apr 2016 23:55:25 +0900 (JST)
Subject: [ruby-changes:42418] nobu:r54492 (trunk): math.c: fix tgamma

nobu	2016-04-06 00:52:02 +0900 (Wed, 06 Apr 2016)

  New Revision: 54492

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

  Log:
    math.c: fix tgamma
    
    * math.c (ruby_tgamma): fix tgamma(-0.0) on mingw.
      [ruby-core:74817] [Bug #12249]

  Modified files:
    trunk/ChangeLog
    trunk/math.c
    trunk/test/ruby/test_math.rb
Index: math.c
===================================================================
--- math.c	(revision 54491)
+++ math.c	(revision 54492)
@@ -734,14 +734,20 @@ math_erfc(VALUE obj, VALUE x) https://github.com/ruby/ruby/blob/trunk/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
 
 /*
Index: test/ruby/test_math.rb
===================================================================
--- test/ruby/test_math.rb	(revision 54491)
+++ test/ruby/test_math.rb	(revision 54492)
@@ -255,6 +255,10 @@ class TestMath < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/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
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54491)
+++ ChangeLog	(revision 54492)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Apr  6 00:52:00 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* math.c (ruby_tgamma): fix tgamma(-0.0) on mingw.
+	  [ruby-core:74817] [Bug #12249]
+
 Tue Apr  5 14:50:28 2016  NARUSE, Yui  <naruse@r...>
 
 	* ext/nkf/nkf-utf8/nkf.c (mime_putc): fix typo.

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

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