diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-19 15:18:50 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-19 15:18:50 +0000 |
commit | 7f95eed19e22cb9a4867819355fe4ab99f85fd16 (patch) | |
tree | 988295914fd4e93cf415ec614a9f0a9923e71299 /numeric.c | |
parent | 3a5d1e4b775deee8c8731a97048b752a33b35922 (diff) |
Introduce endless range [Feature#12912]
Typical usages:
```
p ary[1..] # drop the first element; identical to ary[1..-1]
(1..).each {|n|...} # iterate forever from 1; identical to 1.step{...}
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -2469,11 +2469,11 @@ ruby_float_step_size(double beg, double end, double unit, int excl) } int -ruby_float_step(VALUE from, VALUE to, VALUE step, int excl) +ruby_float_step(VALUE from, VALUE to, VALUE step, int excl, int allow_endless) { if (RB_TYPE_P(from, T_FLOAT) || RB_TYPE_P(to, T_FLOAT) || RB_TYPE_P(step, T_FLOAT)) { double beg = NUM2DBL(from); - double end = NUM2DBL(to); + double end = (allow_endless && NIL_P(to)) ? HUGE_VAL : NUM2DBL(to); double unit = NUM2DBL(step); double n = ruby_float_step_size(beg, end, unit, excl); long i; @@ -2712,7 +2712,7 @@ num_step(int argc, VALUE *argv, VALUE from) } } } - else if (!ruby_float_step(from, to, step, FALSE)) { + else if (!ruby_float_step(from, to, step, FALSE, FALSE)) { VALUE i = from; if (inf) { |