Skip to content

jq: reindex bridge re-parses a computed double past 2^53 as an integer literal, so sort/unique/min/max compare it exactly #2938

Description

@newhoggy

Severity: Low

sort, unique, min, max, group_by take document (StandardJson) input, so an
array built in the filter reaches them through the reindex bridge (to_json_for_reindex
→ re-index → from_number_bytes). A computed double whose shortest spelling looks
integral (869389897822472000, i.e. 869389897822471936.0) comes back as
NumberLiteral(Int(869389897822472000), …), and from then on compares exactly against a
real literal instead of equal (jq keeps it a double, and #2906's comparator treats the
literal 869389897822472004 as equal to it):

$ jq  -n -c '[869389897822472004, (869389897822472000+0), 5] | sort'   # [5,869389897822472004,869389897822472000]
$ sjq -n -c '[869389897822472004, (869389897822472000+0), 5] | sort'   # [5,869389897822472000,869389897822472004]
$ jq  -n -c '[5, 869389897822472004, (869389897822472000+0)] | max'    # 869389897822472000
$ sjq -n -c '[5, 869389897822472004, (869389897822472000+0)] | max'    # 869389897822472004

Identical before and after #2906 (the comparator is right; the bridge changes the
operand). Binary ==/< on the same values are correct because they never cross the
bridge. Recorded in docs/compliance/jq/limitations.md under the #2906 entry.

Possible fix directions: have the bridge re-bake an integral Float past 2^53 as a
Float-repr NumberLiteral (the text is still what jq would print, so display is
unchanged), or extend reindex_bridge_is_identity's bypass to jq-mode Floats whose
spelling is not mode-forked.

Activity

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

    OpusSuitable for an Opus-class model to implement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions