Skip to content

fix: unify NaN checks across all arithmetic evaluation paths#955

Merged
stephenamar-db merged 2 commits into
databricks:masterfrom
He-Pin:fix/nan-comprehension-consistency
Jun 18, 2026
Merged

fix: unify NaN checks across all arithmetic evaluation paths#955
stephenamar-db merged 2 commits into
databricks:masterfrom
He-Pin:fix/nan-comprehension-consistency

Conversation

@He-Pin

@He-Pin He-Pin commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Motivation

NaN handling was inconsistent across four arithmetic evaluation paths: the main evaluator, comprehension fast path, inline optimizer, and double-fast-path. Some paths detected NaN results and errored, while others silently propagated NaN values.

Modification

  • Added NaN result checks to OP_+, OP_-, OP_* in all four arithmetic paths
  • Added NaN checks to OP_% and OP_/ where they were previously missing
  • All paths now consistently report "not a number" when arithmetic produces NaN (e.g., Infinity + (-Infinity), 0 * Infinity)
  • Added directional tests for NaN-producing operations and regular arithmetic

Result

Arithmetic operations that produce NaN now consistently error across all evaluation paths, eliminating the behavioral inconsistency between array comprehension and top-level evaluation.

References

Expression go-jsonnet v0.22.0 jrsonnet v0.5.0-pre98 sjsonnet (before) sjsonnet (after)
local x = std.pow(2, 1024); x + (-x) ERROR: Overflow ERROR: non-finite Inconsistent (varies by path) ❌ ERROR: not a number ✅
local x = std.pow(2, 1024); 0 * x ERROR: Overflow ERROR: non-finite Inconsistent ❌ ERROR: not a number ✅
1 + 2 3 3 3 3

@He-Pin He-Pin force-pushed the fix/nan-comprehension-consistency branch from 1b7b098 to c9da3ad Compare June 17, 2026 19:22
Motivation:
NaN handling was inconsistent across four arithmetic evaluation paths:
the main evaluator, comprehension fast path, inline optimizer, and
double-fast-path. Some paths detected NaN results and errored, while
others silently propagated NaN values.

Modification:
- Added NaN result checks to OP_+, OP_-, OP_* in all four arithmetic paths
- Added NaN checks to OP_% and OP_/ where they were previously missing
- All paths now consistently report "not a number" when arithmetic
  produces NaN
- Improved NaN guards test with precise overflow assertions

Result:
All arithmetic evaluation paths now consistently detect and report NaN
results, eliminating silent NaN propagation.
@He-Pin He-Pin force-pushed the fix/nan-comprehension-consistency branch from c9da3ad to 22e3077 Compare June 17, 2026 23:24
Motivation:
The comprehension fast path (evalBinaryOpNumNum) had NaN checks for
OP_+, OP_-, and OP_* but was missing them for OP_/ and OP_%. This
left the very inconsistency the PR aims to fix: Infinity / Infinity
and Infinity % Infinity would silently produce NaN in comprehensions.

Modification:
- Add NaN check after ld / rd in OP_/, before the existing Infinity check
- Add NaN check after ld % rd in OP_%

Result:
All four arithmetic evaluation paths now consistently detect NaN from
division and modulo operations, including in array comprehensions.
@stephenamar-db stephenamar-db merged commit b61b1c4 into databricks:master Jun 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants