-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
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).
library/core/src/time.rs
Outdated
| } 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?
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot label -S-waiting-on-author +S-waiting-on-review |
|
@bors r+ rollup |
Implement round-ties-to-even for Duration Debug for consistency with f64 ## Summary This PR proposes a fix for rust-lang#103747 implementing IEEE-754 S4.3 roundTiesToEven for Duration Debug implementation. ## Testing Added new test in `time.rs` for validating roundTiesToEven behavior in Duration formatting. Reran all debug formatting tests in `time.rs` with `./x test library/coretests --test-args time::debug_formatting`.
…uwer Rollup of 5 pull requests Successful merges: - #147499 (Implement round-ties-to-even for Duration Debug for consistency with f64) - #149447 (Rewrite `String::replace_range`) - #149469 (Leverage &mut in OnceLock when possible) - #149921 (Add new source component that includes GPL-licensed source) - #150460 (fix ManuallyDrop::into_inner aliasing (Miri) issues) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #147499 - josh-kaplan:master, r=Mark-Simulacrum Implement round-ties-to-even for Duration Debug for consistency with f64 ## Summary This PR proposes a fix for #103747 implementing IEEE-754 S4.3 roundTiesToEven for Duration Debug implementation. ## Testing Added new test in `time.rs` for validating roundTiesToEven behavior in Duration formatting. Reran all debug formatting tests in `time.rs` with `./x test library/coretests --test-args time::debug_formatting`.
…uwer Rollup of 5 pull requests Successful merges: - rust-lang/rust#147499 (Implement round-ties-to-even for Duration Debug for consistency with f64) - rust-lang/rust#149447 (Rewrite `String::replace_range`) - rust-lang/rust#149469 (Leverage &mut in OnceLock when possible) - rust-lang/rust#149921 (Add new source component that includes GPL-licensed source) - rust-lang/rust#150460 (fix ManuallyDrop::into_inner aliasing (Miri) issues) r? `@ghost` `@rustbot` modify labels: rollup
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.