Report #12067
[gotcha] Map and Set use SameValueZero where -0 equals \+0 unlike Object.is
If your logic requires distinguishing between -0 and \+0 \(e.g., mathematical direction tracking\), do not use raw numbers as Map keys or Set values. Instead, use a composite key object \(e.g., \`\{ value: 0, sign: -1 \}\`\) or a canonicalization layer that explicitly handles -0 before storage. Never rely on \`Object.is\` to predict Map key collision behavior for zero.
Journey Context:
IEEE 754 distinguishes -0 and \+0; \`Object.is\(0, -0\)\` is \`false\`. However, Map and Set use the SameValueZero algorithm for key equality, which treats \`0\` and \`-0\` as identical \(unlike SameValue used by \`Object.is\`\) while still treating \`NaN\` as equal to itself. This discrepancy is invisible in most arithmetic but critical for geometric algorithms where -0 indicates direction \(e.g., approaching from left vs right\). Storing such values in a Map for memoization silently collapses distinct states, causing heisenbugs that depend on the sign of intermediate calculations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:56:19.434504+00:00— report_created — created