Repository navigation
refactor: Replace _isnan and _finite with std::isnan and std::isfinite - #3686
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. WalkthroughThe 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. ChangesMath compatibility and validation
Estimated code review effort: 2 (Simple) | ~15 minutes Change: Refactor Suggested reviewers: Merge Risk:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Low impact] The PR appears safe to merge.
|
_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>
de7fbee to
910c365
Compare
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>
xezon
left a comment
There was a problem hiding this comment.
Makes sense.
Does this cover all source files? I see no tools.
…Float and Is_Valid_Double Both functions read the value through an unsigned long pointer, which breaks the strict aliasing rule. std::bit_cast copies the bits instead. std::isfinite would also do, but it needs <cmath> in wwmath.h, and MSVC's <cmath> adds float overloads of sin and fabs that change the math of WW3D2 files that do not include it today. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yes, no tool calls |
The NaN checks call
_isnanand_finite, which are MSVC-only CRT functions from<float.h>. This PR replaces them with the standardstd::isnanandstd::isfinite, in the same way #3532 and #3652 added standard functions for VC6 through the adapters.<cmath>, the header it stands in for, likebit_adapter.hfor<bit>. Neither VC6 nor STLport 4.5.3 declaresisnanorisfinite. The header comment lists how the VC6 functions differ: they have onlyfloatanddoubleoverloads, and afloatis converted todoublebefore the check. That conversion keeps NaN and infinity, so the result is the same.PhysicsUpdate.cpp,Thing.cpp,AIUpdate.cpp,Object.cppandDrawable.cppin both games.GameCommon.cpp,motchan.cpp,sortingrenderer.cppandstreakRender.cppin Core._isnanis left.float, and every result is used as a condition, never as a number. The return type changing frominttobooltherefore changes nothing.<float.h>, throughPreRTS.handwwmath.h. There was no compat shim to remove.WWMath::Is_Valid_FloatandIs_Valid_Double(from review): they test the exponent bits by hand and read the value through anunsigned long*, which breaks the strict aliasing rule. They now read the bits withstd::bit_cast.std::isfinitewould also do, butwwmath.hwould need<cmath>, and MSVC's<cmath>addsfloatoverloads ofsinandfabs. On ClangCL that turnsdoublemath intofloatmath inmapper.cpp,dazzle.cppandprojector.cpp, which do not include<cmath>today. Release code has no callers; only aWWASSERTinanimobj.cppuses them.Evidence
Disassembly: ClangCL and VC6 Release objects of all changed sources, for both games, compared function by function against
main.normalizeAnglecvtss2sd+call __imp___isnanbecomes an inlineucomiss x, x; jp(43 → 35 instructions)Object::reactToTransformChangePhysicsBehavior::applyForcePhysicsBehavior::updatedtor$cleanup funclets change only their frame offsetsPhysicsBehavior::applyRandomRotation(Zero Hour)__LINE__arguments toGameLogicRandomValueRealgo up by 1, because a brace moved to its own line aboveObject::updateObjValuesFromMapProperties(Generals)ucomiss x, xsets the parity flag exactly whenxis NaN, so each check returns the same value as before. All other float arithmetic in these functions is the same asmain. The__LINE__argument ofGetGameLogicRandomValueRealis used only in itsDEBUG_LOG. Apart from the two rows above, VC6 generates identical code in every object.Whole build: every ClangCL and VC6 Release object of both games, built from the PR base and from this branch, compared the same way.
__TIME__string ofWinMain. So adding<cmath>toPreRTS.hchanges nothing else, because the GameEngine files already got it through the STL headers.BinkLoader.cppandDbgHelpLoader.cpp, which include none of the changed files.Claude Opus 5.5 was used to aid in implementation and disassembly
Council review
Rounds: 2