Skip to content

castComparableNumber (and BinaryComparator) still lose precision for a Long/Float pair above 2^53 #7628

Closed

Description

@lvca

Follow-up from PR #7627 / issue #7614, found by CodeRabbit's review of that PR.

The remaining defect

#7614 fixed Type.castComparableNumber narrowing an Integer/Long to Float (losing precision above 2^24) by
promoting both operands to double instead - matching BinaryComparator.compareWideningLong's own widening, which
was the explicit goal (the two entry points must agree, per #7609).

That widening is itself lossy above 2^53 (Double's exact integer range): 10_000_000_000_000_001L.doubleValue()
rounds to the same double that widenFloat(1.0E16f) parses to, so castComparableNumber(10_000_000_000_000_001L, 1.0E16f) reports the pair equal via couple[0].equals(couple[1]) even though they are not. The symmetric
Float/Long branch has the same defect.

This is narrower than the #7614 band (2^24 vs 2^53 - a long has to be quite large) but is the same shape.

Why it's a separate issue rather than a quick fix inside #7614's PR

Fixing only castComparableNumber (e.g. routing this specific band through BigDecimal) would reintroduce exactly
the divergence #7609/#7614 were about: BinaryComparator.compareWideningLong/compareNarrowIntegral would still
report ordering via lossy double, while equality would be exact - two entry points disagreeing on the same pair,
which is the failure mode this whole family of issues (#7609, #7613, #7614) exists to close. A correct fix has to
touch BinaryComparator too, and deserves its own regression test across the 2^53 boundary - the existing
49-pair sweep from PR #7612 covers precision loss above 2^24, not above 2^53.

Suggested fix

When a Long outside [-2^53, 2^53] meets a Float/Double, promote both to BigDecimal (via widenFloat's
decimal form for the float side) instead of double, in both Type.castComparableNumber and
BinaryComparator.compareWideningLong/compareNarrowIntegral, so ordering and equality keep agreeing at every
magnitude.

cc @lvca

Activity

  1. added
    engine
    on Sep 15, 2026
  2. added a commit that references this issue on Sep 15, 2026
  3. added this to the 26.10.1 milestone on Sep 15, 2026
  4. added
    in progress
    on Sep 16, 2026
  5. self-assigned this
    on Sep 16, 2026
  6. added 5 commits that reference this issue on Sep 16, 2026
  7. added a commit that references this issue on Sep 17, 2026
  8. lvca commented on Sep 17, 2026

    @lvca
    MemberAuthor

    Fixed in #7750.

    Comparing a very large whole number against a FLOAT or DOUBLE could report them as equal when they are not. Both values were converted to double first, which stops being exact above 2^53, so a band of distinct numbers collapsed onto the same value. Such a pair is now compared exactly.

    Three related problems in the same comparator turned up while fixing it, and are fixed too:

    • comparing a number against a DECIMAL could give contradictory answers depending on which side came first;
    • comparing a number against a DATETIME with second, microsecond or nanosecond precision always answered "less than", whatever the values were;
    • comparing a number against any date or timestamp column could throw an error instead of answering, depending on which Java date type the database was configured to return.

    One related case is deliberately left for later and tracked in #7754: comparing a boolean against a date or timestamp still fails in one direction.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  9. removed
    in progress
    on Sep 17, 2026
  10. added a commit that references this issue on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugenginesql

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions