Skip to content

add min_pos_value constant for floats #13735

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

Merged
merged 1 commit into from
Apr 25, 2014

Conversation

aturon
Copy link
Member

@aturon aturon commented Apr 25, 2014

Follow-up on issue #13297 and PR #13710. Instead of following the (confusing) C/C++ approach
of using MIN_VALUE for the smallest positive number, we introduce MIN_POS_VALUE (and
in the Float trait, min_pos_value) to represent this number.

This patch also removes a few remaining redundantly-defined constants that were missed last
time around.

Follow-up on issue rust-lang#13297 and PR rust-lang#13710.  Instead of following the (confusing) C/C++ approach
of using `MIN_VALUE` for the smallest *positive* number, we introduce `MIN_POS_VALUE` (and
in the Float trait, `min_pos_value`) to represent this number.

This patch also removes a few remaining redundantly-defined constants that were missed last
time around.
@aturon
Copy link
Member Author

aturon commented Apr 25, 2014

/cc @bjz

pub static MIN_VALUE: f32 = 1.17549435e-38_f32;
/// Maximum f32 value
/// Smallest finite f32 value
pub static MIN_VALUE: f32 = -3.40282347e+38_f32;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a different but still reasonable name for this? It may be confusing for someone who's used to C's weird definition and tries to use this constant without looking at the value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't shock me since Rust tries to fix the C/C++ legacy in various domains... plus I would expect a newcomer to at least lookup the function name/doc on rustdoc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++11 introduced numeric_limits::lowest, but that's an ugly backwards compatibility workaround. So long as we document this, I think it is good to get this right from the start.

@brendanzab
Copy link
Member

Looks good! r+ from me. @brson?

bors added a commit that referenced this pull request Apr 25, 2014
Follow-up on issue #13297 and PR #13710.  Instead of following the (confusing) C/C++ approach
of using `MIN_VALUE` for the smallest *positive* number, we introduce `MIN_POS_VALUE` (and
in the Float trait, `min_pos_value`) to represent this number.

This patch also removes a few remaining redundantly-defined constants that were missed last
time around.
@bors bors closed this Apr 25, 2014
@bors bors merged commit b8da4d7 into rust-lang:master Apr 25, 2014
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.

6 participants