ruby-changes:33134
From: nobu <ko1@a...>
Date: Fri, 28 Feb 2014 14:11:49 +0900 (JST)
Subject: [ruby-changes:33134] nobu:r45213 (trunk): numeric.c: float overflow
nobu 2014-02-28 14:11:44 +0900 (Fri, 28 Feb 2014) New Revision: 45213 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45213 Log: numeric.c: float overflow * numeric.c (ruby_num_interval_step_size): get rid of float conversion overflow. Modified files: trunk/numeric.c trunk/test/ruby/test_numeric.rb Index: numeric.c =================================================================== --- numeric.c (revision 45212) +++ numeric.c (revision 45213) @@ -1836,7 +1836,8 @@ ruby_num_interval_step_size(VALUE from, https://github.com/ruby/ruby/blob/trunk/numeric.c#L1836 double n = ruby_float_step_size(NUM2DBL(from), NUM2DBL(to), NUM2DBL(step), excl); if (isinf(n)) return DBL2NUM(n); - return LONG2FIX(n); + if (POSFIXABLE(n)) return LONG2FIX(n); + return rb_dbl2big(n); } else { VALUE result; Index: test/ruby/test_numeric.rb =================================================================== --- test/ruby/test_numeric.rb (revision 45212) +++ test/ruby/test_numeric.rb (revision 45213) @@ -271,6 +271,14 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L271 assert_equal(bignum*2+1, (-bignum).step(bignum, 1).size) assert_equal(bignum*2, (-bignum).step(bignum-1, 1).size) + assert_equal(10+1, (0.0).step(10.0, 1.0).size) + + i, bigflo = 1, bignum.to_f + i <<= 1 until (bigflo - i).to_i < bignum + bigflo -= i >> 1 + assert_equal(bigflo.to_i, (0.0).step(bigflo-1.0, 1.0).size) + assert_operator((0.0).step(bignum.to_f, 1.0).size, :>=, bignum) # may loose precision + assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 10] assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, to: 10] assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, to: 10, by: nil] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/