diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | numeric.c | 14 | ||||
-rw-r--r-- | test/ruby/test_float.rb | 4 |
3 files changed, 19 insertions, 4 deletions
@@ -1,3 +1,8 @@ +Wed Nov 7 15:22:37 2012 NARUSE, Yui <naruse@ruby-lang.org> + + * numeric.c (ruby_float_step): fix r37514: it yielded with NaN + if the unit is infinity. + Wed Nov 7 15:46:12 2012 Ayumu AIZAWA <ayumu.aizawa@gmail.com> * lib/webrick.rb: fix typo. reported by Rohit Arondekar. @@ -1755,10 +1755,16 @@ ruby_float_step(VALUE from, VALUE to, VALUE step, int excl) double n = ruby_float_step_size(beg, end, unit, excl); long i; - for (i=0; i<n; i++) { - double d = i*unit+beg; - if (unit >= 0 ? end < d : d < end) d = end; - rb_yield(DBL2NUM(d)); + if (isinf(unit)) { + /* if unit is infinity, i*unit+beg is NaN */ + if (n) rb_yield(DBL2NUM(beg)); + } + else { + for (i=0; i<n; i++) { + double d = i*unit+beg; + if (unit >= 0 ? end < d : d < end) d = end; + rb_yield(DBL2NUM(d)); + } } return TRUE; } diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index 2ac394465f..288101f129 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -585,6 +585,10 @@ class TestFloat < Test::Unit::TestCase assert_equal([5.0, 4.0, 3.0, 2.0], 5.0.step(1.5, -1).to_a) end + def test_step2 + assert_equal([0.0], 0.0.step(1.0, Float::INFINITY).to_a) + end + def test_step_excl 1000.times do a = rand |