Skip to content

refactor: Replace _isnan and _finite with std::isnan and std::isfinite - #3686

Open
CryoTheRenegade wants to merge 5 commits into
TheSuperHackers:mainfrom
CryoTheRenegade:refactor/isnan-isfinite
Open

CryoTheRenegade wants to merge 5 commits into
TheSuperHackers:mainfrom
CryoTheRenegade:refactor/isnan-isfinite

Conversation

@CryoTheRenegade

@CryoTheRenegade CryoTheRenegade commented Nov 14, 2026 •

Copy link
Copy Markdown

The NaN checks call _isnan and _finite, which are MSVC-only CRT functions from <float.h>. This PR replaces them with the standard std::isnan and std::isfinite, in the same way #3532 and #3652 added standard functions for VC6 through the adapters.

+Dependencies/Utility/Utility/cmath_adapter.h
+  VC6: std::isnan, std::isfinite      // float and double overloads that call _isnan / _finite from <float.h>
+  modern compilers: #include <cmath>
 Core/GameEngine/Include/Precompiled/PreRTS.h
+  #include <Utility/cmath_adapter.h>  // covers the GameEngine call sites
 Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp, sortingrenderer.cpp, streakRender.cpp
+  #include <Utility/cmath_adapter.h>  // each WW3D2 call site includes it, as these files do for bit_adapter.h
-if (_isnan(force->x) || _isnan(force->y) || _isnan(force->z))
+if (std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z))
  • Adapter: it is named after <cmath>, the header it stands in for, like bit_adapter.h for <bit>. Neither VC6 nor STLport 4.5.3 declares isnan or isfinite. The header comment lists how the VC6 functions differ: they have only float and double overloads, and a float is converted to double before the check. That conversion keeps NaN and infinity, so the result is the same.
  • Call sites: 103 calls on 38 lines in 14 files:
    • PhysicsUpdate.cpp, Thing.cpp, AIUpdate.cpp, Object.cpp and Drawable.cpp in both games.
    • GameCommon.cpp, motchan.cpp, sortingrenderer.cpp and streakRender.cpp in Core.
    • 18 of the calls are in 6 commented-out asserts. They are replaced too, so no _isnan is left.
  • Types: every argument is a float, and every result is used as a condition, never as a number. The return type changing from int to bool therefore changes nothing.
  • How the names were found before: the call sites got them from <float.h>, through PreRTS.h and wwmath.h. There was no compat shim to remove.

Evidence

  • Disassembly: ClangCL and VC6 Release objects of all changed sources, for both games, compared function by function against main.

    Function ClangCL VC6
    normalizeAngle cvtss2sd + call __imp___isnan becomes an inline ucomiss x, x; jp (43 → 35 instructions) unchanged
    Object::reactToTransformChange the same for 3 checks (131 → 115) unchanged
    PhysicsBehavior::applyForce the same for 3 checks (91 → 80) unchanged
    PhysicsBehavior::update the same for 3 checks; in Zero Hour 4 dtor$ cleanup funclets change only their frame offsets unchanged
    PhysicsBehavior::applyRandomRotation (Zero Hour) the __LINE__ arguments to GameLogicRandomValueReal go up by 1, because a brace moved to its own line above the same
    Object::updateObjValuesFromMapProperties (Generals) unchanged two independent stack loads swap order; it has no NaN check, and the diff persists without the brace commit
    all other functions in the 18 objects unchanged unchanged

    ucomiss x, x sets the parity flag exactly when x is NaN, so each check returns the same value as before. All other float arithmetic in these functions is the same as main. The __LINE__ argument of GetGameLogicRandomValueReal is used only in its DEBUG_LOG. Apart from the two rows above, VC6 generates identical code in every object.

Claude Opus 5.5 was used to aid in implementation and disassembly

Council review

Rounds: 2

Delegate Round 1 Round 2
Claude Opus 5.5 9/10 9.5/10
GPT-6.1 Sol 9/10 10/10
Gemini 4 Carbon 9/10 no score

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The change adds a compatibility header for standard NaN and finite checks. It replaces platform-specific checks in core engine, WW3D2, Generals, and GeneralsMD code. Existing validation responses remain unchanged.

Changes

Math compatibility and validation

Layer / File(s) Summary
Add and wire the math compatibility header
Dependencies/Utility/Utility/cmath_adapter.h, Dependencies/Utility/CMakeLists.txt, Core/GameEngine/Include/Precompiled/PreRTS.h, Core/Libraries/Source/WWVegas/WWMath/wwmath.h
The new header provides std::isnan and std::isfinite overloads for MSVC versions below 1300 and includes <cmath> for other compiler configurations. The utility build list and engine headers include the adapter.
Update core engine math checks
Core/GameEngine/Source/Common/System/GameCommon.cpp, Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp, Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp, Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp
Angle handling and WW3D2 validation use std::isnan and std::isfinite instead of platform-specific functions. Existing filtering, assertions, and diagnostics remain unchanged.
Update game position and physics checks
Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp, Generals/Code/GameEngine/Source/GameClient/Drawable.cpp, Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp, Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp, Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp, GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp, GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp, GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp, GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp, GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp
Position, locomotor, and physics checks in both game variants use std::isnan. Existing assertions, early returns, and object-handling responses remain unchanged.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Refactor

Suggested reviewers: xezon

Merge Risk: Minimal · up to 910c3

This refactor swaps platform-specific NaN and finite checks for standard calls, and a compatibility header covers the older compiler. No behavior change is expected, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: replacing MSVC-specific _isnan and _finite calls with standard std::isnan and std::isfinite. The raw summary and objectives confirm this is the central change across t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is specific and related to the changeset. It states that the PR replaces MSVC-only _isnan and _finite calls with std::isnan and std::isfinite. It describes the new adapter head…
Full details: Title check

Explanation

The title names the main change: replacing MSVC-specific _isnan and _finite calls with standard std::isnan and std::isfinite. The raw summary and objectives confirm this is the central change across the GameEngine, WW3D2, and adapter files. The title uses the refactor: prefix and is specific.

Full details: Description check

Explanation

The description is specific and related to the changeset. It states that the PR replaces MSVC-only _isnan and _finite calls with std::isnan and std::isfinite. It describes the new adapter header cmath_adapter.h, the include changes in PreRTS.h and wwmath.h, the 103 call sites across 14 files, and the disassembly evidence used to check behavior. The description is detailed and matches the raw summary.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c44b387d-52d5-4b05-8f36-339552a6c38d
Commits

Reviewing files that changed from the base of the PR and between de7fbee and 910c365.

Files selected for processing: 1

  • Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@CryoTheRenegade
CryoTheRenegade marked this pull request as ready for review November 16, 2026 19:38
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T08:33:26.948037Z d9851f1 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues remain from this review.

Summary

Replaces _isnan and _finite with std::isnan and std::isfinite across both games and shared rendering code.

  • Game and renderer checks use standard names for invalid floats.

Reviews (4) · Last reviewed commit: "style(motchan): Add a blank line after t..." · Reviewed by Greptile

CryoTheRenegade and others added 2 commits November 16, 2026 20:38
_isnan and _finite are MSVC CRT functions from <float.h>. Use the standard
functions instead. The new cmath_adapter.h gives VC6 std::isnan and
std::isfinite built on _isnan and _finite, because neither VC6 nor
STLport 4.5.3 has them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CryoTheRenegade and others added 3 commits November 17, 2026 01:11
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…isnan

wwmath.h does not call std::isnan or std::isfinite, so it should not include the adapter. The three WW3D2 files that do now include it themselves, as they do for bit_adapter.h.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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