-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ordinal range implementation, fixes #5585 #6326
Conversation
$fn(r::Range ) = Range($fn(r.start), $fn(r.step), r.len) | ||
$fn(r::Range1) = Range1($fn(r.start), r.len) | ||
$fn(r::StepRange) = $fn(r.start):$fn(r.step):$fn(last(r)) | ||
$fn(r::Range1) = $fn(r.start):$fn(last(r)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still using Range1
?
Glad this is coming along. This branch could stand a rebase or something to get rid of all the merges. |
if D<:FloatingPoint || S<:FloatingPoint | ||
error("StepRange should not be used with floating point") | ||
end | ||
step == 0 && error("step cannot be zero") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally got around to trying these out with Dates. The one hiccup I ran into for getting Date/Period ranges to automatically work was the step == 0
, step>0
lines in the constructor, and the step(r) == 0
in the show
method for Range
. I changed them to step == zero(S)
and step>zero(S)
, along with step(r) == zero(typeof(step(r0)))
in the show
method and everything works like a charm!
The reason is Date/Real and Period/Real comparisons aren't allowed in the Dates code.
I'll pull out the old range tests I use to have for DateTimes and Periods and play with this some more.
still not clear what to do with floating point in StepRange
It turns out there are many cases that are drastically easier this way. Tests not passing yet, but getting there.
rename Range1 to UnitRange allow constructing a larger class of ranges, leaving overflow to length()
export UnitRange NEWS for range changes remove random test for BigInt ranges, since they now have BigInt lengths, for which we can't yet generate random numbers.
this is likely to cause too much breakage; e.g. arrays of UnitRange{Int} are common.
it expressed a degree of freedom that was not really there, since it really depended on the first two parameters.
ordinal range implementation, fixes #5585
Adds
OrdinalRange
,StepRange
,UnitRange
, andrange
.length
, and aside from that large ranges work, except for iterating overtypemin(Int):typemax(Int)
.The requirements on an ordinal type
T
areD=T-T
,T+D
,T<T
,D%D
, anddiv(D,D)
(D
is the type of the difference between elements).