Skip to content

JSON.SET rounds 0.9999999999999999 to 1.0, changing strict numeric filter results #1690

Open

Description

@yzxxxx888

Environment

  • Redis: 7.4.7
  • RedisJSON / ReJSON: 2.8.9 (module version 20809)
  • RediSearch: 2.10.20 (module version 21020)
  • Deployment: Redis Stack in Docker on a Windows host
  • The current development branch has not been tested.

Current behavior

Writing the following document with JSON.SET succeeds:

{"amount":0.9999999999999999}

However, immediately reading it with JSON.GET returns:

{"amount":1.0}

JSON.RESP also returns the numeric value 1.0.

The expected nearest binary64 value for the submitted literal is the representable value immediately below 1.0. It should remain distinct from 1.0.

This change affects strict numeric filtering. With three documents, I observed:

ID Submitted amount Amount returned by JSON.GET
0 0.5 0.5
1 0.9999999999999999 1.0
2 1.0 1.0

The numeric filter @amount:[0 (1], representing 0 <= amount < 1, returns only ID 0.

As a control, storing the same decimal strings in HASH fields and creating a separate NUMERIC index returns IDs 0 and 1 for the identical filter.

Steps to reproduce

  1. Start Redis Stack with the versions listed above.
  2. Create a fresh RediSearch index ON JSON, indexing $.amount as an alias named amount with type NUMERIC.
  3. Create three JSON documents with amounts 0.5, 0.9999999999999999, and 1.0. Send those decimal literals directly in the JSON text using JSON.SET.
  4. Read the second document using JSON.GET and JSON.RESP. Observe that its amount is returned as 1.0.
  5. Query the JSON index with @amount:[0 (1]. Observe that only the document containing 0.5 is returned.
  6. Create a separate index ON HASH with an amount NUMERIC field.
  7. Use HSET to store the same three decimal strings in separate HASH records.
  8. Execute the identical range query against the HASH index. Observe that the records containing 0.5 and 0.9999999999999999 are both returned.

Expected behavior

The submitted literal 0.9999999999999999 should round to the binary64 value immediately below 1.0 and remain distinct from 1.0 after storage and retrieval.

Both ID 0 and ID 1 should satisfy 0 <= amount < 1.

Verification

The behavior was reproduced in independent runs using fresh keys.

Observed results:

  • JSON index: count = 1, IDs = [0]
  • HASH control: count = 2, IDs = [0, 1]
  • JSON readback amounts: [0.5, 1.0, 1.0]

The value change is already observable through JSON.GET before evaluating a numeric filter. No vector search, concurrent writes, or approximate index is required for this reduced reproduction.

Activity

  1. aradalvand commented on Nov 11, 2026

    @aradalvand

    I second this. We hit this case as well. 64-bit floating-point numbers are NOT roundtripped precisely.

  2. aradalvand commented on Nov 11, 2026

    @aradalvand

    The root cause appears to be that serde_json is built without its float_roundtrip feature, so floats are parsed with its default best-effort precision, which is sometimes off by one ULP. This affects far more than this one value.

    Reproduced on Redis 8.10.2 by round-tripping 3,999 random doubles through JSON.SET/JSON.GET. Both builds below are from the same master commit (19c96e8):

    Module Doubles changed 0.9999999999999999 comes back as
    Stock (8.1.0) 814 1.0
    master, unchanged 814 1.0
    master + float_roundtrip 0 0.9999999999999999

    The fix is adding "float_roundtrip" to the serde_json features in the root Cargo.toml. I'll open a PR.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions