Hasty Briefsbeta

Bilingual

Eisenstein– exact hexagonal arithmetic for Rust (zero drift after 10k rotations)

16 hours ago
  • #exact arithmetic
  • #hex grid
  • #numerical stability
  • Floating-point arithmetic introduces errors that accumulate over repeated operations, causing drift in navigation, game desync, and simulation divergence.
  • Eisenstein integers provide exact arithmetic for hex grids using integer pairs (a, b), avoiding floating-point approximations.
  • The norm a² - ab + b² is always an integer, eliminating sqrt-based distance calculations and enabling exact distance comparisons.
  • Rotation by 60° is performed via a simple integer transformation (a, b) → (-b, a - b), ensuring results stay on the lattice without trig functions.
  • Eisenstein integers outperform floats in benchmarks: norm calculation is 3.3× faster, rotation is 6× faster, and equality checks are simpler.
  • Data efficiency: E12 uses 4 bytes per coordinate (1×), compared to 8 bytes for F32 (2×) and 16 bytes for F64 (4×), reducing bandwidth costs.
  • Applications include autopilot navigation (no heading drift), multiplayer games (no desync), and sensor fusion (exact arithmetic across devices).
  • The library supports Rust, Python, and JavaScript, with low dependencies and options for embedded systems, WASM, and GPU benchmarks.