Skip to content

Align arbitrary_precision number strings with zmij’s formatting - #1306

Merged
dtolnay merged 1 commit into
serde-rs:masterfrom
b41sh:fix-float-number-display
Jan 6, 2026
Merged

dtolnay merged 1 commit into
serde-rs:masterfrom
b41sh:fix-float-number-display

Conversation

@b41sh

@b41sh b41sh commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

When serde_json switched float formatting from ryu to zmij, serialized floats always include an explicit + in positive exponents (e.g. 1.23e+45). However, numbers parsed via the arbitrary_precision feature keep the literal source text, so 1.23e45 stayed without the +. That meant the same numeric value round-tripped to different strings depending on whether it flowed through zmij Value::from(1.23e45) or through the arbitrary_precision parser, which was especially noticeable in code that mixes both paths or compares serialized JSON for equality.

This PR normalizes exponents as soon as we parse a string-based number: if an exponent lacks an explicit sign we insert a +. Now the canonical representation is consistent everywhere arbitrary_precision values serialize identically to zmij-emitted floats.

@dtolnay dtolnay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants