Skip to content

Favor decimal notation over scientific notation for floats #800

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

Merged
merged 1 commit into from
May 10, 2025

Conversation

byroot
Copy link
Member

@byroot byroot commented May 10, 2025

e.g.

JSON.dump(1746861937.7842371)

master:

"1.7468619377842371e+9"

This branch and older json versions:

1746861937.7842371

In the end it's shorter, and according to canada.json benchmark performance is the same.

@radiospiel any objections?

For reference, sidekiq was using a bad regexp to parse JSON and was broken by this change: sidekiq/sidekiq#6700. I'm not considering using scientific notation to workaround that bug, but I think it's better overall.

@radiospiel
Copy link
Contributor

This looks good to me, thanks for taking care of it.

@byroot
Copy link
Member Author

byroot commented May 10, 2025

Interestingly, JRuby always has been using scientific notation for this.

@byroot byroot force-pushed the fpconv-scientific branch from 6a406c3 to d9f8299 Compare May 10, 2025 09:49
e.g.
```
JSON.dump(1746861937.7842371)
```

master:
```
"1.7468619377842371e+9"
```

This branch and older json versions:
```
1746861937.7842371
```

In the end it's shorter, and according to `canada.json` benchmark
performance is the same.
@byroot byroot force-pushed the fpconv-scientific branch from d9f8299 to 866f72a Compare May 10, 2025 09:57
@byroot byroot merged commit f042622 into ruby:master May 10, 2025
33 of 34 checks passed
byroot added a commit to byroot/json that referenced this pull request May 23, 2025
…floats.

Fix: ruby#807

Since ruby#800, `fpconv_dtoa` can actually
generate up to 27 chars.
byroot added a commit to byroot/json that referenced this pull request May 23, 2025
…floats.

Fix: ruby#807

Since ruby#800, `fpconv_dtoa` can actually
generate up to 27 chars.
byroot added a commit to byroot/json that referenced this pull request May 23, 2025
…floats.

Fix: ruby#807

Since ruby#800, `fpconv_dtoa` can actually
generate up to 27 chars.
byroot added a commit to byroot/json that referenced this pull request May 23, 2025
…floats.

Fix: ruby#807

Since ruby#800, `fpconv_dtoa` can actually
generate up to 28 chars.
matzbot pushed a commit to ruby/ruby that referenced this pull request May 26, 2025
…ge negative floats.

Fix: ruby/json#807

Since ruby/json#800, `fpconv_dtoa` can actually
generate up to 28 chars.

ruby/json@d73ae93d3c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants