summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-07 07:03:50 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-07 07:03:50 +0000
commit172d8f9b6eb3d0af7f451e505fd3a5c2e438215e (patch)
tree561a74deefa3392657bacb05e11df25d99795775 /numeric.c
parent043c0eaac0e63eacc5da6624432420a903e8f2d6 (diff)
* 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
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/numeric.c b/numeric.c
index bbe86a1708..aab049490d 100644
--- a/numeric.c
+++ b/numeric.c
@@ -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;
}