Extended the result of to_f32/to_f64 with infinity#163
Conversation
Author
|
This PR attempts to solve #161. |
cuviper
added a commit
to cuviper/num-traits
that referenced
this pull request
Aug 28, 2020
The implementation of `<f64 as ToPrimitive>::to_f32` was written at a time when float-to-float overflow was though to be undefined behavior, per rust-lang/rust#15536, but this was later determined to be fine. Casting a large `f64` to `f32` just results in an infinity with the matching sign. The sign gives more information than if `to_f32` just returns `None`, so now we let these infinities through as a result. See also rust-num/num-bigint#163 and rust-num/num-rational#83.
bors Bot
added a commit
to rust-num/num-traits
that referenced
this pull request
Oct 29, 2020
185: Trust the "i128" feature r=cuviper a=cuviper If the "i128" feature is explicity requested, don't bother probing for it. It will still cause a build error if that was set improperly. 186: Allow large f64-to-f32 to saturate to infinity r=cuviper a=cuviper The implementation of `<f64 as ToPrimitive>::to_f32` was written at a time when float-to-float overflow was though to be undefined behavior, per rust-lang/rust#15536, but this was later determined to be fine. Casting a large `f64` to `f32` just results in an infinity with the matching sign. The sign gives more information than if `to_f32` just returns `None`, so now we let these infinities through as a result. See also rust-num/num-bigint#163 and rust-num/num-rational#83. 190: Normalize the comment style r=cuviper a=cuviper Co-authored-by: Josh Stone <cuviper@gmail.com>
Closed
Member
|
Thanks! bors r+ |
Contributor
|
This isn't a complaint on my part, but this change broke some of our code because we relied on "numbers that are too big to be an f32/f64" returning |
ltratt
added a commit
to ltratt/yksom
that referenced
this pull request
Nov 16, 2020
Other SOMs that I've tried error (whether deliberately or not) when a big integer is too big to be represented as a floating point number. The `BigInt::to_f64()` function used to return `None` in such cases but now they always return `Some::(f64::INFINITY)` (see rust-num/num-bigint#163). This PR handles that explicitly. On the plus side, we can simplify our code a little bit; on the downside we'll also probably be a tiny bit slower in the common case.
ltratt
added a commit
to ltratt/yksom
that referenced
this pull request
Nov 16, 2020
Other SOMs that I've tried error (whether deliberately or not) when a big integer is too big to be represented as a floating point number. The `BigInt::to_f64()` function used to return `None` in such cases but now they always return `Some::(f64::INFINITY)` (see rust-num/num-bigint#163). This PR handles that explicitly. On the plus side, we can simplify our code a little bit; on the downside we'll also probably be a tiny bit slower in the common case.
Member
|
@ltratt Sorry for the trouble! I debated about the change in behavior myself, but I decided that the sign preservation makes this better than |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.