Repository navigation
Parse JSON floats exactly with serde_json's float_roundtrip - #1694
Open
aradalvand wants to merge 1 commit into
Open
aradalvand wants to merge 1 commit into
aradalvand wants to merge 1 commit into
Conversation
serde_json parses floats with best-effort precision by default, which stores some values as an adjacent double: `0.9999999999999999` became `1.0`, and about one in five random doubles changed in their last digit between `JSON.SET` and `JSON.GET`. Enabling `float_roundtrip` makes parsing exact. The new test covers values that changed before, and `pass-jsonsl-yelp.json`, previously skipped for float precision, now round-trips too. Fixes RedisJSON#1690. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XUNs4unCWEtK5q25xYbvgz
This branch has not been deployed
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.
Fixes #1690.
serde_jsonparses floats with best-effort precision unless itsfloat_roundtripfeature is on, soJSON.SETsometimes stores an adjacent double instead of the one it was given. This affects far more than0.9999999999999999: round-tripping 3,999 random doubles throughJSON.SET/JSON.GETon Redis 8.10.2, both builds from the samemastercommit:0.9999999999999999comes back as1.0master, unchanged1.0master+float_roundtrip0.9999999999999999Every change was in the last digit, e.g.
0.36995516654807925→0.3699551665480793.Changes
Cargo.toml: addfloat_roundtripto theserde_jsonfeatures. Cargo unifies features, so this also coversijson's use ofserde_json.tests/pytest/test.py:test_json_set_stores_doubles_exactly: JSON.SET rounds 0.9999999999999999 to 1.0, changing strict numeric filter results #1690's value and five more that changed before.pass-jsonsl-yelp.jsonis no longer skipped. It was ignored for "float precision", and now round-trips equal; it doesn't without the fix.Trade-off
Per
serde_json's docs,float_roundtripcosts about 2× on float parsing, in exchange for exact values.Testing
Built in a Debian trixie container and loaded into
redis:8.10.2. The new test and the Yelp fixture pass with the fix and fail without it.cargo test -p json_pathandcargo test -p redis_jsonpass.🤖 Generated with Claude Code
https://claude.ai/code/session_01XUNs4unCWEtK5q25xYbvgz