aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-19 15:18:50 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-19 15:18:50 +0000
commit7f95eed19e22cb9a4867819355fe4ab99f85fd16 (patch)
tree988295914fd4e93cf415ec614a9f0a9923e71299 /numeric.c
parent3a5d1e4b775deee8c8731a97048b752a33b35922 (diff)
downloadruby-7f95eed19e22cb9a4867819355fe4ab99f85fd16.tar.gz
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.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/numeric.c b/numeric.c
index 1af74a94f5..569d558425 100644
--- a/numeric.c
+++ b/numeric.c
@@ -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) {