Skip to content

Conversation

@josh-kaplan
Copy link

@josh-kaplan josh-kaplan commented Oct 8, 2025

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.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 8, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 8, 2025

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@hkBst
Copy link
Member

hkBst commented Oct 12, 2025

Maybe also add a test-case for println!("{:.0?}", Duration::MAX);, unless it is already there?

@josh-kaplan
Copy link
Author

Maybe also add a test-case for println!("{:.0?}", Duration::MAX);, unless it is already there?

Fair! It looks like it already exists on line 330 in debug_formatting_extreme_values.

I also updated the comment above the new rounding behavior to accurately reflect the behavior change.

@scottmcm
Copy link
Member

scottmcm commented Dec 6, 2025

r? libs

@rustbot rustbot assigned Mark-Simulacrum and unassigned scottmcm Dec 6, 2025
Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a 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).

View changes since this review

} else {
Some(integer_part)
}
} else if fractional_part > 0 && fractional_part > divisor * 5 {
Copy link
Member

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?

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants