On Mo, 2011-01-17 at 13:34 -0800, Moritz Lenz via RT wrote: > On 01/16/2011 07:47 PM, Gilbert R. Roehrbein (via RT) wrote: > > fixes the problem which you encounter when you try to evaluate > > +(23..2300000000) > > ... and creates others. Consider > > (0..^3.3).Numeric > > Where you patch makes it return 3, but 4 is the correct answer.
shame :( but fixed it ^^
> Maybe checking for ~~ Int instead of ~~ Numeric helps, but we also need
> to more tests.
does now work for following ranges
for $(^3.3), $(0..3), $(-2..0), $(-2.9..3.1), $(1.9..3.1) {
my $a := +$_;
my $b := .elems;
say "{.perl}\t\t$a != $b" if $a != $b;
}
diff --git a/src/core/Range.pm b/src/core/Range.pm
index fc1395b..baffe3f 100644
--- a/src/core/Range.pm
+++ b/src/core/Range.pm
@@ -103,6 +103,16 @@ class Range is Iterable does Positional {
multi method roll(Whatever) {
self.roll(Inf);
}
+
+ # to optimize the calculation of the size of a big range
+ # +(42..$big) doesnt take too much time now
+ multi method Numeric () {
+ nextsame unless $.max ~~ Numeric and $.min ~~ Numeric;
+ my $lo := $.min + $.excludes_min;
+ return 0 if $.max < $lo;
+ my $ret := ($.max - $lo + 1).floor;
+ return $ret - ($.excludes_max and $.max == $lo + $ret);
+ }
}
signature.asc
Description: This is a digitally signed message part
