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

Fix #7420 #7421

Closed
wants to merge 1 commit into from
Closed

Fix #7420 #7421

wants to merge 1 commit into from

Conversation

ivarne
Copy link
Sponsor Member

@ivarne ivarne commented Jun 26, 2014

When indexing a FloatRange with a OrdinalRange, you have to be careful to use the actual r.step, instead of step(r) = r.step/r.divisor.

When indexing a FloatRange with a OrdinalRange, you have to be careful to use the actual r.step, instead of step(r) = r.step/r.divisor.
@ivarne
Copy link
Sponsor Member Author

ivarne commented Jun 26, 2014

This should definitely have some tests, but I don't have time to write them now.

@Jutho
Copy link
Contributor

Jutho commented Jun 26, 2014

A quick test learns that you should also not use r[first(s)] but probably r[first(s)]*r.divisor, although I would need to look better into range.jl to be sure.

@ivarne
Copy link
Sponsor Member Author

ivarne commented Jun 26, 2014

Seems like you are right range.jl#197

I would probably rather use r.start to not have the rounding error from a multiply and divide.

@ivarne
Copy link
Sponsor Member Author

ivarne commented Jun 26, 2014

How about?

FloatRange(r.start + r.step*(first(s)-1), r.step*step(s),length(s),r.divisor)

Or maybe everything gets inlined and the extra /r.divisor * r.divisor gets translated into nothing.

@simonster
Copy link
Member

The compiler cannot safely optimize out /r.divisor * r.divisor since, as you note above, this may change the result due to rounding (or if r.divisor is 0. or Inf).

@StefanKarpinski
Copy link
Sponsor Member

It was slightly trickier than this because the start value is also lifted by the divisor; there was also some fussiness with bounds checking.

@ivarne ivarne deleted the patch-4 branch June 28, 2014 20:44
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

4 participants