Skip to content

Fix cross-platform math determinism (Mac/Linux)#217

Draft
fbraz3 wants to merge 6 commits into
mainfrom
fix-mac-linux-math-determinism
Draft

Fix cross-platform math determinism (Mac/Linux)#217
fbraz3 wants to merge 6 commits into
mainfrom
fix-mac-linux-math-determinism

Conversation

@fbraz3

@fbraz3 fbraz3 commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Description

Fixes cross-platform math determinism between Mac (ARM64), Linux (x86_64) and Windows.
This addresses the math precision and ambiguity issues related to SqrtOrigin, Atan2Origin, and PowOrigin.

Changes

  • Added explicit float overloads for deterministic math wrappers in wwmath.h.
  • Added explicit (float) casts to resolve ambiguous math function calls (e.g. in AIPathfind.cpp).
  • Checked and validated integer casting after division to prevent Inf/NaN propagating into integers.
  • Synchronized logic between GeneralsMD and Generals to ensure backport parity.

fbraz3 added 3 commits July 14, 2026 23:17
…determinism fixes

- Replaced division by zero traps in float logic with Div_FixNaN
- Included Div_FixNaN helper in wwmath.h
- Added deterministic BezierMath (D3DXVec4Transform & D3DXVec4Dot)
- Downcasted Atan2 double arguments to float
- Backported PR #3 and #4 from Zero Hour to the base Generals game

Ref: TheSuperHackers#3
Ref: TheSuperHackers#4
@fbraz3 fbraz3 force-pushed the fix-mac-linux-math-determinism branch from 47f292e to 23f9aa6 Compare July 15, 2026 22:22
fbraz3 added 3 commits July 15, 2026 20:32
…_availableOnFrame fix to Generals

Missed during PR #3 backport: Remove RETAIL_COMPATIBLE_CRC guard
around m_availableOnFrame initialization. Always set to 0 to prevent
special powers from being stuck when RETAIL_COMPATIBLE_CRC is off.
- Force double-precision variants of SqrtOrigin and PowOrigin to downcast and use single-precision gm_*f implementations.
- This prevents a known 1-ULP drift on ARM64 NEON vs x86 x87 FPU when evaluating double-precision transcendentals.
- Documented NaN and double-precision determinism guidelines in AGENTS.md.
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.

1 participant