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

Allow large f64-to-f32 to saturate to infinity #186

Merged
merged 1 commit into from
Oct 29, 2020

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented 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.

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.
@cuviper
Copy link
Member Author

cuviper commented Oct 29, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Oct 29, 2020

@bors bors bot merged commit f0a980b into rust-num:master Oct 29, 2020
@cuviper cuviper deleted the buzz-lightyear branch February 8, 2024 01:02
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

1 participant