AQL arithmetic on 64-bit integers from documents loses precision; the same expression on literals does not
Author: the-ShallowCreated Oct 1, 2026Updated Oct 1, 2026
Description
Arithmetic on integer attribute values above 2^53 is computed in doubles at run time, so d.id % 2 gives the wrong
parity for an odd stored integer, and d.a + 1 becomes a double. The same expression with literals is folded at
parse time with int64 precision and gives the exact result, so the answer depends on where the operand comes from.
The AQL data types page says numbers are treated as 64-bit signed integers or doubles internally; its 2^53 warning
is about JavaScript contexts.
Reproduction
db._create("r");
db.r.insert({id: 9007199254740993, a: 1234567890123456789});
db._query("FOR d IN r RETURN [d.id % 2, d.a % 10, d.a + 1]").toArray();
// [ [ 0, 8, 1234567890123456800 ] ] (1.2345678901234568e+18)
db._query("RETURN [9007199254740993 % 2, 1234567890123456789 % 10, 1234567890123456789 + 1]").toArray();
// [ [ 1, 9, 1234567890123456790 ] ]Source: arangodb/arangodb