-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Improve document for std::fmt
to format float type
#112760
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
3a1cdd6
to
194d318
Compare
This comment has been minimized.
This comment has been minimized.
format!
Precision description for float typeformat!
Precision description for float type
format!
Precision description for float typeformat!
Precision description for float type
This comment has been minimized.
This comment has been minimized.
1d2ab77
to
194d318
Compare
format!
Precision description for float typestd::fmt
to format float type
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Eval EXEC <execvy@gmail.com>
194d318
to
c4b0980
Compare
r? libs-api since it seems like this is a new guarantee, which I'm not sure if we want to make. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
I think it would be all right to document a rounding behavior.
//! println!("{:.0}", 12.5f64); // 12 | ||
//! println!("{:.0}", 12.3f64); // 12 | ||
//! println!("{:.0}", 11.6f64); // 12 | ||
//! println!("{:.0}", 11.5f64); // 12 | ||
//! println!("{:.0}", 11.4f64); // 11 | ||
//! println!("{:.0}", 10.5f64); // 10 | ||
//! println!("{:.0}", 9.5f64); // 10 | ||
//! println!("{:.0}", 8.5f64); // 8 | ||
//! println!("{:.0}", 7.5f64); // 8 | ||
//! println!("{:.0}", -7.5f64); // -8 | ||
//! println!("{:.0}", -8.5f64); // -8 | ||
//! println!("{:.0}", -9.5f64); // -10 | ||
//! println!("{:.0}", -10.5f64);// -10 | ||
//! println!("{:.0}", -11.4f64);// -11 | ||
//! println!("{:.0}", -11.5f64);// -12 | ||
//! println!("{:.0}", -11.6f64);// -12 | ||
//! println!("{:.0}", -12.5f64);// -12 | ||
//! println!("{:.0}", -12.6f64);// -13 | ||
//! | ||
//! println!("{:.1}", 3.33f64); // 3.3 | ||
//! println!("{:.1}", -3.33f64);// -3.3 | ||
//! println!("{:.1}", -3.55f64);// -3.5 | ||
//! println!("{:.1}", 4.54f64); // 4.5 | ||
//! println!("{:.1}", 4.55f64); // 4.5 | ||
//! println!("{:.1}", 4.56f64); // 4.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an extremely excessive number of examples. Can {:.1}
with 1.25 and 1.75 be sufficient to illustrate what you mean?
@@ -273,6 +273,37 @@ | |||
//! Hello, ` 123` has 3 right-aligned characters | |||
//! ``` | |||
//! | |||
//! For the floating-point type, it employs the | |||
//! [roundTiesToEven](https://en.m.wikipedia.org/wiki/Rounding#Rounding_half_to_even) convention: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the name "roundTiesToEven" refer to exactly? I did not find that anywhere in the link.
//! For the floating-point type, it employs the | ||
//! [roundTiesToEven](https://en.m.wikipedia.org/wiki/Rounding#Rounding_half_to_even) convention: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unlikely to be the most appropriate link because the subsection you linked to is describing the operation of rounding a float to an integer, which is different in general from formatting a float to a particular precision. The text even calls this out: a "more sophisticated mode [is] used when rounding to significant figures".
//! println!("{:.1}", 4.55f64); // 4.5 | ||
//! println!("{:.1}", 4.56f64); // 4.6 | ||
//! ``` | ||
//! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a paragraph above which describes how precision applies to floating point types. It would make more sense to me to explain the rounding directly in that paragraph.
Lines 209 to 210 in bf0e22b
//! For floating-point types, this indicates how many digits after the decimal point should be | |
//! printed. |
@eval-exec any updates on this? |
Closing this as inactive. Feel free to reöpen this pr or create a new pr if you get the time to work on this. Thanks |
This PR want to close #112742