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

Range cannot be inclusive for floats #394

Closed
vks opened this issue Apr 12, 2018 · 3 comments
Closed

Range cannot be inclusive for floats #394

vks opened this issue Apr 12, 2018 · 3 comments

Comments

@vks
Copy link
Collaborator

vks commented Apr 12, 2018

Range::new and Range::new_inclusive are currently identical for f32 and f64.

@vks
Copy link
Collaborator Author

vks commented Apr 12, 2018

It is not clear whether this can be corrected (see dhardy#85 (comment)), but we should at least document it or even panic on RangeFloat::new_inclusive.

@pitdicker
Copy link
Contributor

We already have the following documentation:

Types should attempt to sample in [low, high) for Range::new(low, high), i.e., excluding high, but this may be very difficult. All the primitive integer types satisfy this property, and the float types normally satisfy it, but rounding may mean high can occur.

So we already say sampling from floating point ranges might be fuzzy at the boundaries (as users probably expect as rounding errors are part of the deal with fp). Do you think we really need to spell things out even more? We could turn the comment from that method into a doc comment...

We should definitely not panic. There is no programmer error here and no incorrect results. And we don't want to make using RangeFloat::new_inclusive hard to use generically.

Of course, trying to reduce the rounding error to be more accurate at the boundaries can always be good, but I suspect there is no silver bullet that does not decrease the accuracy in other places.

@dhardy
Copy link
Member

dhardy commented Apr 16, 2018

Indeed, I don't think there's much we can do here.

@vks if you want to make a PR improving doc please do, or we can also reopen this, but I don't see anything constructive here.

@dhardy dhardy closed this as completed Apr 16, 2018
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

No branches or pull requests

3 participants