Skip to content

eliminate warnings when compiling with -ffast-math - #561

Open
Jamiras wants to merge 2 commits into
RetroAchievements:developfrom
Jamiras:feature/fast_math
Open

Jamiras wants to merge 2 commits into
RetroAchievements:developfrom
Jamiras:feature/fast_math

Conversation

@Jamiras

@Jamiras Jamiras commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

An upstream consumer has voiced concerned on compiling with -ffast-math generating a warning that is then turned into an error by -Werror

This is because -ffast-math assumes the code never will generate or use the NAN and INFINITY float values, and the internal converter knows how to convert MBF32 and DOUBLE32 NaN and infinities.

Since we can't prevent the emulated memory from having NaN and infinity values, the best course of action is to still initialize the internal variables with the converted NaN and infinity values and rely on the fact that they're outside the range of all valid floating point numbers so range and equality comparisons will still work.

As best as I can tell, the only behavioral change is comparing NaN always returns false with -ffast-math off, but works like comparing infinity with -ffast-math on. (i.e. NaN > 3.0 is now true, but NaN < 3.0 is still false). As long as the achievement logic is checking both upper and lower bounds, or direct equality, there shouldn't be any problems.

Note that warning is there for a reason. Using NaN and infinity with -ffast-math is undefined behavior. The only reason I even agreed to silence the warning is because of it's interaction with -Werror and the reasonable assumption that achievement logic isn't reliant on supporting those values.

@Jamiras Jamiras added this to the 13.0 milestone Oct 11, 2026
Comment thread src/runtime/rc_memref.c
dbl = NAN;
/* An exponent above 127 is a special number: infinity when the mantissa is zero, NaN otherwise. */

#if FLT_RADIX == 2 && FLT_MANT_DIG == 24 && FLT_MAX_EXP == 128

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-ffast_math doesn't prevent defining INFINITY or NAN, so we can't detect when it's being applied. Instead, look for the definition of the deconstruction of a float (which also works in c89) and define the constants ourself, avoiding the real constants which would trigger the compiler warning.

This branch has not been deployed

No deployments
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