#13986·neo4j

Constant folding changes the result of `9007199254740993 = 9007199254740992.0` (`true` when folded, `false` at runtime)

Author: ting668Created Sep 21, 2026Updated Sep 22, 2026
Labelsbugteam-cypherGithub Issue

Reporter: ting668

Neo4j Version: 2026.08.1 (Community edition; also checked on 5.26.30, the current 5.26 LTS patch) Operating System: Linux (WSL2), inside a Docker container Installation Method: Docker image neo4j:2026.08.1 API/Driver: cypher-shell (Bolt, in-container)

Description

While testing Neo4j using an intuitive approach inspired by attribute constraints, I found that constant folding changes the result of an integer/float equality: the folded literal comparison returns TRUE while the same comparison evaluated at runtime returns FALSE.

Cypher compares numbers exactly across INTEGER and FLOAT: 9007199254740993 is the integer 2^53+1 and cannot be represented in binary64, so it is not equal to the FLOAT 9007199254740992.0 (2^53). The runtime path returns FALSE for the equality (consistent with exact comparison), but the constant-folded literal form returns TRUE — consistent with the integer literal being rounded to double before the comparison during folding. Folding must preserve runtime semantics; here the same expression gives different truth values depending on whether it is folded, and the folded form silently changes which rows a WHERE clause accepts.

Steps to reproduce

Note: The queries below are a minimized, simplified example reproducing the bug.

Buggy query (no data needed) — first the folded literal form, then the same comparison materialized through variables so it is evaluated at runtime:

cypher
RETURN 9007199254740993 = 9007199254740992.0 AS folded;

WITH 9007199254740993 AS i, 9007199254740992.0 AS f
RETURN i = f AS runtime;

Expected behavior

Both forms should return false, since the integer 9007199254740993 (2^53+1) is not equal to the float 9007199254740992.0 (2^53):

folded = FALSE
runtime = FALSE

Actual behavior

The folded form and the runtime form of the same comparison disagree (observed on 2026.08.1 and 5.26.30 via cypher-shell):

folded = TRUE
runtime = FALSE

As a control, the individual pieces behave correctly — with exact comparison across INTEGER and FLOAT, 2^53+1 is not less than 2^53, so both forms of the less-than comparison should agree:

cypher
WITH 9007199254740993 AS i, 9007199254740992.0 AS f
RETURN i < f AS runtime_lt;

RETURN 9007199254740993 < 9007199254740992.0 AS folded_lt;
runtime_lt = FALSE
folded_lt = FALSE

This also affects queries over stored data. Setup and buggy query:

cypher
CREATE (:N {uid:'bad'});
CREATE (:N {uid:'keep'});

MATCH (n:N)
WHERE 9007199254740993 = 9007199254740992.0 OR n.uid = 'keep'
RETURN n.uid AS uid ORDER BY uid;

Expected behavior: only the row with uid = 'keep' is returned, since the constant disjunct 9007199254740993 = 9007199254740992.0 is false and only the second disjunct admits a row:

uid = "keep"

Actual behavior: both rows are returned, since the folded constant predicate evaluates TRUE and admits the row it should reject:

uid = "bad"
uid = "keep"

This suggests that during constant folding the integer literal is rounded to a double before its equality with the float literal is evaluated (so 2^53+1 compares equal to 2^53), while the runtime comparison keeps the values in their exact types — so the same expression can yield different truth values depending on whether it is folded. This is consistent with the literal-comparison folding path introduced by #8276 (which rewrites comparisons between literals into boolean constants) evaluating the integer literal as a double before the comparison.