ruby-changes:34941
From: nobu <ko1@a...>
Date: Fri, 1 Aug 2014 16:35:56 +0900 (JST)
Subject: [ruby-changes:34941] nobu:r47024 (trunk): numeric.c: 0 % Float::NAN returns Float::NAN
nobu 2014-08-01 16:35:48 +0900 (Fri, 01 Aug 2014) New Revision: 47024 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47024 Log: numeric.c: 0 % Float::NAN returns Float::NAN * numeric.c (flodivmod): all results are NaN if divisor is NaN. [fix GH-692] Modified files: trunk/ChangeLog trunk/numeric.c trunk/test/ruby/test_float.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 47023) +++ ChangeLog (revision 47024) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Aug 1 16:35:32 2014 Evan Miller <evan@s...> + + * numeric.c (flodivmod): all results are NaN if divisor is NaN. + [fix GH-692] + Thu Aug 01 07:28:12 2014 Kenta Murata <mrkn@m...> * ext/bigdecimal/bigdecimal.c: [DOC] Add description of Index: numeric.c =================================================================== --- numeric.c (revision 47023) +++ numeric.c (revision 47024) @@ -890,6 +890,12 @@ flodivmod(double x, double y, double *di https://github.com/ruby/ruby/blob/trunk/numeric.c#L890 { double div, mod; + if (isnan(y)) { + /* y is NaN so all results are NaN */ + if (modp) *modp = y; + if (divp) *divp = y; + return; + } if (y == 0.0) rb_num_zerodiv(); if ((x == 0.0) || (isinf(y) && !isinf(x))) mod = x; @@ -903,7 +909,7 @@ flodivmod(double x, double y, double *di https://github.com/ruby/ruby/blob/trunk/numeric.c#L909 mod = x - z * y; #endif } - if (isinf(x) && !isinf(y) && !isnan(y)) + if (isinf(x) && !isinf(y)) div = x; else div = (x - mod) / y; Index: test/ruby/test_float.rb =================================================================== --- test/ruby/test_float.rb (revision 47023) +++ test/ruby/test_float.rb (revision 47024) @@ -271,6 +271,12 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L271 assert_raise(ZeroDivisionError, bug6048) { 42 % 0 } end + def test_modulo4 + assert_predicate((0.0).modulo(Float::NAN), :nan?) + assert_predicate((1.0).modulo(Float::NAN), :nan?) + assert_predicate(Float::INFINITY.modulo(1), :nan?) + end + def test_divmod2 assert_equal([1.0, 0.0], 2.0.divmod(2)) assert_equal([1.0, 0.0], 2.0.divmod((2**32).coerce(2).first)) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/