1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* numeric.c (ruby_float_step): fix r37514: it yielded with NaN

if the unit is infinity.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2012-11-07 07:03:50 +00:00
parent 043c0eaac0
commit 172d8f9b6e
3 changed files with 19 additions and 4 deletions

View file

@ -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.

View file

@ -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;
}

View file

@ -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