From f3844ccf44060801c7ceed331efa025d73e8f718 Mon Sep 17 00:00:00 2001 From: matz Date: Sun, 4 Jan 2009 23:20:39 +0000 Subject: * range.c (range_step): should not add up errors on loops. [ruby-dev:37691] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21330 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- range.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'range.c') diff --git a/range.c b/range.c index 32c0024a34..74f9e569f5 100644 --- a/range.c +++ b/range.c @@ -343,10 +343,13 @@ range_step(int argc, VALUE *argv, VALUE range) !NIL_P(rb_check_to_integer(b, "to_int")) || !NIL_P(rb_check_to_integer(e, "to_int"))) { ID op = EXCL(range) ? '<' : rb_intern("<="); + VALUE v = b; + int i = 0; - while (RTEST(rb_funcall(b, op, 1, e))) { - rb_yield(b); - b = rb_funcall(b, '+', 1, step); + while (RTEST(rb_funcall(v, op, 1, e))) { + rb_yield(v); + i++; + v = rb_funcall(b, '+', 1, rb_funcall(INT2NUM(i), '*', 1, step)); } } else { -- cgit v1.2.3