Repository navigation
fix: Replace fast_float_trunc, fast_float_floor, fast_float_ceil with standard or deterministic equivalents for all configurations except retail compatible Zero Hour - #3645
Conversation
|
No actionable comments were generated in the recent review. WalkthroughThe ChangesMath rounding configuration
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Possibly related PRs
Suggested reviewers: Merge Risk:
|
[High impact] The PR appears safe to merge; no blocking issues were found.
|
bobtista
left a comment
There was a problem hiding this comment.
More progress towards standard / deterministic :) -1 no longer turns into -2, which is nice, and retail compat is untouched. I had my agents double check it too, it's good to go once 3644 merges
… standard or gamemath equivalents for all configurations except retail compatible Zero Hour fast_float_floor and fast_float_ceil subtract or add almost 1 before truncating, which only gives the right result if the FPU rounds toward zero. The game sets the FPU to round to nearest, so floor returns n-1 for negative whole numbers, ceil returns n+1 for positive whole numbers, and values closer to zero than about 3e-8 return 0. fast_float_trunc also loses bits that are not fractional for magnitudes of 2^32 and larger. REAL_TO_INT_FLOOR and REAL_TO_INT_CEIL, which about 270 places use, carried these errors into all configurations except a retail compatible Generals. A retail compatible Zero Hour keeps the fast functions, because its replays depend on their results. The functions are now only available there and document their errors. All other configurations use gm_floorf and gm_ceilf with deterministic math, or floorf and ceilf otherwise. For example REAL_TO_INT_CEIL(2.0f) is now 2 instead of 3 there. A retail compatible Generals keeps floorf and ceilf as before. gmath.h is now included and detected with angle brackets, because it is found through the include path and not next to the including file.
f1f5986 to
7f1e78d
Compare
This change gets rid of
fast_float_trunc,fast_float_floor,fast_float_ceilexcept for retail compatible Zero Hour. Reason: The function results are fundamental flawed and are best abandoned. See explanations below.AI Summary
fast_float_floorandfast_float_ceilsubtract or add almost 1 before truncating. That only gives the right result if the FPU rounds toward zero. The game sets the FPU to round to nearest (setFPMode), so:fast_float_floorreturns n-1 for negative whole numbers above -2^24, for example -2 returns -3.fast_float_ceilreturns n+1 for positive whole numbers below 2^24, for example 2 returns 3.fast_float_truncloses bits that are not fractional for magnitudes of 2^32 and larger, and turns NaN into infinity.REAL_TO_INT_FLOORandREAL_TO_INT_CEILare used at about 270 places. They carried these errors into every configuration except retail compatible Generals.Changes
gm_floorf/gm_ceilfwith deterministic math, orfloorf/ceilfwithout it. Retail compatible Generals keepsfloorf/ceilfas before.gmath.his now included and detected with angle brackets, because it is found through the include path and not next to the including file.Retail compatible builds of both games keep their results. Non retail builds of both games now floor and ceil correctly, so
REAL_TO_INT_*results change for whole numbers and for tiny values.Depends on #3644, which removes the
FAST_REAL_*macros and the last direct use offast_float_flooroutside retail compatible Zero Hour.