Skip to content
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

Implement rounding in length(::StepRange) #18744

Closed
wants to merge 2 commits into from
Closed

Conversation

timholy
Copy link
Sponsor Member

@timholy timholy commented Sep 30, 2016

StepRange is the only range object currently in Base that's suitable for non-Integer, non-AbstractFloat objects; among possibly-other places, it's used to construct ranges with physical units in Unitful. I noticed an off-by-one bug in length with such ranges, which this fixes. CC @ajkeller34.

@timholy
Copy link
Sponsor Member Author

timholy commented Oct 1, 2016

I made a change to range that also makes it more robust against roundoff error. I did this as a deliberately-conservative change, aka this implementation is not very efficient but it's guaranteed not to break unless we were already getting the wrong answer (and many cases where we were getting the wrong answer will be handled correctly).

Looking it over the first commit again I noticed that this change would be breaking for a type that implements div but not /. While I suspect this would be unusual, it seems possible. (I think Dates might be an example, although Dates "rolls its own" when it comes to length which is why this change passes our tests.) Before merging, is it possible to find out whether whether this PR would break anything with a PkgEval run?

@tkelman
Copy link
Contributor

tkelman commented Oct 2, 2016

yes. the process for that is.described at #17165 (comment)

@timholy
Copy link
Sponsor Member Author

timholy commented Feb 3, 2017

Now that we have generic LinSpace and StepRangeLen, I think this isn't so necessary anymore.

@timholy timholy closed this Feb 3, 2017
@timholy timholy deleted the teh/steprange branch February 3, 2017 08:58
@tkelman
Copy link
Contributor

tkelman commented Mar 1, 2017

relevant for release-0.5 or not?

is there any overlap with #20396 ?

@timholy
Copy link
Sponsor Member Author

timholy commented Mar 1, 2017

Seems like it should be OK on 0.5; the only thing I can see to be concerned about is whether the constructor might take longer to run than it used to.

There's no overlap with #20396, because that only affects FloatRange whereas this is about StepRange. In 0.5, StepRange is the only type you can use to create, e.g., Unitful ranges. Those don't get caught by the complain-if-you-throw-me-an-AbstractFloat test, either, yet you can get corruption in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants