literal: round-half-even tie for normal-range float/complex repr#8243
Open
youknowone wants to merge 1 commit into
Open
literal: round-half-even tie for normal-range float/complex repr#8243youknowone wants to merge 1 commit into
youknowone wants to merge 1 commit into
Conversation
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughFloat and complex ChangesCPython-compatible tie repr formatting
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
youknowone
commented
Jul 9, 2026
| } | ||
|
|
||
| #[test] | ||
| fn repr_normal_range_uses_cpython_tie_digit() { |
21114e5 to
374d562
Compare
to_string's normal-magnitude branch and complex::component_to_string returned Rust's shortest formatting directly, which can pick the odd-digit neighbour of a rounding tie where repr() picks the even one (e.g. bits 0x42e26687db6b9b04 formats as 161852602146008.13 vs repr's ...08.12). Route both through prefer_cpython_tie_repr, generalized to fixed-notation strings. Add unit tests and float/complex repr snippet tests. Assisted-by: Claude
374d562 to
e526090
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
float::to_string's normal-magnitude branch andcomplex::component_to_stringreturned Rust's shortest formatting directly. Rust's formatter can land on the odd-digit neighbour of a rounding tie whererepr()'s round-half-to-even picks the even one, e.g. bits0x42e26687db6b9b04format as161852602146008.13but CPythonreprgives161852602146008.12(both round-trip).The scientific branch of
float::to_stringalready ran throughprefer_cpython_tie_repr; this extends that helper to fixed-notation strings and applies it to the normal-magnitude float branch and to both complex branches.Verified against CPython 3.14 over a differential battery (20k floats, 280k complex pairs incl. subnormals / powers of ten / ties): 0 divergences after the fix. Added a normal-range tie unit test.
— assisted by Claude
Summary by CodeRabbit
repr()/str()formatting for floating-point values in round-half-to-even tie cases, including normal-range and scientific-notation outputs.repr()assertions for built-in float and complex edge cases covering positive/negative components and tie behavior.