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

ruby-changes:45616

From: nobu <ko1@a...>
Date: Thu, 23 Feb 2017 08:49:45 +0900 (JST)
Subject: [ruby-changes:45616] nobu:r57689 (trunk): rational.c: infinity in power

nobu	2017-02-23 08:49:40 +0900 (Thu, 23 Feb 2017)

  New Revision: 57689

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

  Log:
    rational.c: infinity in power
    
    * rational.c (nurat_expt): return 0 due to overflow.
      [ruby-core:79686] [Bug #13242]:

  Modified files:
    trunk/rational.c
    trunk/test/ruby/test_rational.rb
Index: test/ruby/test_rational.rb
===================================================================
--- test/ruby/test_rational.rb	(revision 57688)
+++ test/ruby/test_rational.rb	(revision 57689)
@@ -959,6 +959,8 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L959
     bug = '[ruby-core:79686] [Bug #13242]: Infinity due to overflow'
     x = EnvUtil.suppress_warning {4r**40000000}
     assert_predicate x, :infinite?, bug
+    x = EnvUtil.suppress_warning {(1/4r)**40000000}
+    assert_equal 0, x, bug
   end
 
   def test_positive_p
Index: rational.c
===================================================================
--- rational.c	(revision 57688)
+++ rational.c	(revision 57689)
@@ -1046,6 +1046,10 @@ nurat_expt(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/rational.c#L1046
 		if (RB_FLOAT_TYPE_P(den)) return DBL2NUM(NAN);
 		return num;
 	    }
+	    if (RB_FLOAT_TYPE_P(den)) { /* infinity due to overflow */
+		num = ZERO;
+		den = ONE;
+	    }
 	    return f_rational_new2(CLASS_OF(self), num, den);
 	}
     }

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

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