Is fpclassify(x) == FP_NAN
functionally equivalent to isnan(x)
?
The same question goes for:
fpclassify(x) == FP_INFINITE
vs.isinf(x)
fpclassify(x) == FP_NORMAL
vs.isnormal(x)
fpclassify(x) == FP_SUBNORMAL
vs.issubnormal(x)
fpclassify(x) == FP_ZERO
vs.iszero(x)
If they are functionally equivalent, then why need of duplicates?
They're functionally equivalent. But
fpclassify
allows you to perform a single test and use aswitch
statement, which may be slightly faster and/or produce simpler code than the chainedif
/else if
/else
blocks would use to perform type by type checks (assumingfpclassify
itself has efficient ways to differentiate itself; won't swear to that), e.g. per the cppreference example: