Skip to content
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

Format f64 in error messages using ryu #1107

Merged
merged 1 commit into from
Jan 26, 2024
Merged

Format f64 in error messages using ryu #1107

merged 1 commit into from
Jan 26, 2024

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Jan 26, 2024

This produces a more readable representation using exponential notation for values that might be hundreds of digits when formatted by std::fmt.

It also includes trailing .0 on integer values (serde-rs/serde#2679).

@dtolnay dtolnay merged commit 6a6d2bb into master Jan 26, 2024
26 checks passed
@dtolnay dtolnay deleted the unexpectedfloat branch January 26, 2024 21:19
Comment on lines +469 to +476
match self.0 {
de::Unexpected::Unit => formatter.write_str("null"),
de::Unexpected::Float(value) => write!(
formatter,
"floating point `{}`",
ryu::Buffer::new().format(value),
),
unexp => Display::fmt(&unexp, formatter),
Copy link

Choose a reason for hiding this comment

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

I think, it would be good to add a comment why Float is processed differently to reduce count of WTF/min from readers

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