C standard library have: isgreater,isgreaterequal,isless,islessequal,islessgreater, isunordered. And why the C standard library haven't isequal? It should be easy to implement like that:
bool isequal(float x, float y)
{
return !isunordered(x, y) && isgreaterequal(x, y) && !isgreater(x, y);
}
The C99 rationale V5.10 explains that these macros were added to the language for the sole purpose of being safe and not raising floating point exceptions, like their corresponding operators might do:
The relational operators (
<
,<=
,>=
,>
), but not the equality operators (==
and!=
), may raise floating-point exceptions when one of the operands is aNaN
(as an error indicator for programs written without consideration of NaNs). There is a need for comparisons that are guareented [sic] not to raise any floating-point exceptions; this also is a requirment [sic] of IEC-60559. That is why theisgreater
,isgreaterequal
,isless
,islessequal
,islessgreater
andisunordered
function-like macros were invented.