Floats Don't Agree with Themselves

· coding math · Source ↗

A polygon-overlap test passed locally and failed on the server — same code, same input — because LLVM emitted FMA on x86 but not WASM, flipping one sign bit and forking the entire convex decomposition.

What Matters

  • LLVM’s FMA contraction, x87 80-bit registers, reassociation, and denormal flush-to-zero are four independent paths to float non-reproducibility across ISAs.
  • Convex decomposition is discrete: a flipped cross-product sign changes which vertex is reflex, cascading into a completely different decomposition graph.
  • exact-poly uses i64 coordinates and i128 cross products; sum(twice_area(parts)) == twice_area(original_ring) holds as exact integer equality, not epsilon comparison.
  • SCALE is hardcoded at compile time — runtime configurability would let two processes silently disagree about what a meter is, recreating the original failure.
  • Shewchuk’s 1996 adaptive-precision predicates paper underlies both Triangle and CGAL; exact-poly skips the filtered fallback and computes i128 directly every call.

Original | Discuss on HN