-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking Issue for round_ties_even
#96710
Comments
I think |
From the perspective of maintaining a crate that implements a custom floating point type that tries to provide a similar API to the built-in My suspicion for why away-from-zero was chosen is that it matches how
I definitely think having a function with the round ties to even mode should be available though. My preference would be |
…=pnkfelix,m-ou-se,scottmcm Add `round_ties_even` to `f32` and `f64` Tracking issue: rust-lang#96710 Redux of rust-lang#82273. See also rust-lang#55107 Adds a new method, `round_ties_even`, to `f32` and `f64`, that rounds the float to the nearest integer , rounding halfway cases to the number with an even least significant bit. Uses the `roundeven` LLVM intrinsic to do this. Of the five IEEE 754 rounding modes, this is the only one that doesn't already have a round-to-integer function exposed by Rust (others are `round`, `floor`, `ceil`, and `trunc`). Ties-to-even is also the rounding mode used for int-to-float and float-to-float `as` casts, as well as float arithmentic operations. So not having an explicit rounding method for it seems like an oversight. Bikeshed: this PR currently uses `round_ties_even` for the name of the method. But maybe `round_ties_to_even` is better, or `round_even`, or `round_to_even`?
…=pnkfelix,m-ou-se,scottmcm Add `round_ties_even` to `f32` and `f64` Tracking issue: rust-lang#96710 Redux of rust-lang#82273. See also rust-lang#55107 Adds a new method, `round_ties_even`, to `f32` and `f64`, that rounds the float to the nearest integer , rounding halfway cases to the number with an even least significant bit. Uses the `roundeven` LLVM intrinsic to do this. Of the five IEEE 754 rounding modes, this is the only one that doesn't already have a round-to-integer function exposed by Rust (others are `round`, `floor`, `ceil`, and `trunc`). Ties-to-even is also the rounding mode used for int-to-float and float-to-float `as` casts, as well as float arithmentic operations. So not having an explicit rounding method for it seems like an oversight. Bikeshed: this PR currently uses `round_ties_even` for the name of the method. But maybe `round_ties_to_even` is better, or `round_even`, or `round_to_even`?
…=pnkfelix,m-ou-se,scottmcm Add `round_ties_even` to `f32` and `f64` Tracking issue: rust-lang#96710 Redux of rust-lang#82273. See also rust-lang#55107 Adds a new method, `round_ties_even`, to `f32` and `f64`, that rounds the float to the nearest integer , rounding halfway cases to the number with an even least significant bit. Uses the `roundeven` LLVM intrinsic to do this. Of the five IEEE 754 rounding modes, this is the only one that doesn't already have a round-to-integer function exposed by Rust (others are `round`, `floor`, `ceil`, and `trunc`). Ties-to-even is also the rounding mode used for int-to-float and float-to-float `as` casts, as well as float arithmentic operations. So not having an explicit rounding method for it seems like an oversight. Bikeshed: this PR currently uses `round_ties_even` for the name of the method. But maybe `round_ties_to_even` is better, or `round_even`, or `round_to_even`?
Could this do something like use |
I hope this is appropriate/helpful, I would like this feature stabilized so I will attempt a stabilization report. Request for StabilizationI think the Implementation historyThese methods have been added in #95317 (merged 7 March, 2023) which corresponds to the 1.70 timeframe (branched on 14 April, 2023). API SummaryThe impl f32 {
fn round_ties_even(self) -> f32;
}
impl f64 {
fn round_ties_even(self) -> f64;
} Experience reportsThese methods are used in several projects:
There are also references to this feature/tracking issue on manual implementations of
DocumentationBoth methods have been documented in the
Unresolved questionsThe following questions are still unresolved:
I will try to answer these questions 1. NamingNo further comments have been made about the naming of these method. 2. Changing
|
I'm not sure the previous post will be seen by anyone without a ping/mention. |
I've nominated this for libs-api discussion, so the team should take a look as part of their triage.
Correct; as far as Rust is concerned, these two are equivalent. |
EDIT: no I'm completely wrong, float2int rounds towards zero, it doesn't even use "nearest" semantics. oops |
We discussed this in the libs-api meeting today. This function exposes the last IEEE 754 rounding mode that isn't yet accessible through other functions on floats. We decided against changing the behavior of the existing @rfcbot fcp merge |
Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
I do think it would be nice for the simple |
@scottmcm I do wish we had an obvious short name we could give this, because it's unfortunate that the thing you probably should use most of the time (since among other things it's supported in hardware) has a name that's more than twice the length. But it's not obvious what name we could use for that that wouldn't be obfuscating. |
Agreed, Josh. But I don't have any smart ideas for anything better than the current proposal 🙁 |
What do you claim to be the "obvious" behavior that people should expect? Round-ties-to-even is the default IEEE-754 rounding mode and is used by Python which is the most popular programming language by some metrics. Other popular languages like Javascript and C++ do not even agree on how negative numbers should be rounded. Would it be possible to change the behavior of |
Rounding ties away from zero is the rounding method that's generally taught in primary school, due to its simplicity (it only ever needs to consider 1 digit). |
While rounding away from zero is what I learned in elementary school, I don't think that what young children are taught is generally what people (engineers) would expect. |
In my totally representative survey of 2 CS PhD students, neither of them knew why "round ties to even" would be preferable over "round away from zero". I think it's not just elementary school children that are surprised by the seemingly unnecessarily complicated "ties to even" semantics. |
Changing the behavior of If it’s better to change the function to correct behavior, I propose to fully remove We can introduce |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
Rollup merge of rust-lang#120150 - Jules-Bertholet:stabilize-round-ties-even, r=cuviper Stabilize `round_ties_even` Closes rust-lang#96710 `@rustbot` label -T-libs T-libs-api
Feature gate:
#![feature(round_ties_even)]
This is a tracking issue for the
round_ties_even
feature, which adds a new method tof32
andf64
for rounding to the nearest integer, with ties rounded to the nearest even number.Public API
Steps / History
round_ties_even
tof32
andf64
#95317Unresolved Questions
round_ties_even
,round_even
,round_to_even
,round_banker
... many ways to paint this bikeshedround
function be changed to this?rint
in the implementaton? (see Addround_ties_even
tof32
andf64
#95317 (comment))The text was updated successfully, but these errors were encountered: