-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Implement round-ties-to-even for Duration Debug for consistency with f64 #147499
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
base: main
Are you sure you want to change the base?
Conversation
|
Maybe also add a test-case for |
Fair! It looks like it already exists on line 330 in I also updated the comment above the new rounding behavior to accurately reflect the behavior change. |
|
r? libs |
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.
Hm, I hadn't realized how complex the logic already is for Duration's Debug impl. I'm not convinced that there's a strong use case for being this careful in a Debug impl for Duration -- no one should be parsing those outputs, IMO, or relying on particular rounding there. This differs from Display/Debug for floats which are much more likely to be in the critical path for correctness.
That said, the diff here doesn't seem too complicated, so maybe it's OK, especially if we can simplify it a bit (per my inline comment).
| } else { | ||
| Some(integer_part) | ||
| } | ||
| } else if fractional_part > 0 && fractional_part > divisor * 5 { |
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.
It would be nice to merge this code with the below - in particular to not duplicate or miss having the useful comments. It seems to me that if we modified is_last_digit_odd in the if here to be or'd with fractional_part > divisor * 5 that would work out? Or am I missing some case?
Summary
This PR proposes a fix for #103747 implementing IEEE-754 S4.3 roundTiesToEven for Duration Debug implementation.
Testing
Added new test in
time.rsfor validating roundTiesToEven behavior in Duration formatting. Reran all debug formatting tests intime.rswith./x test library/coretests --test-args time::debug_formatting.