Why does GCC implement isnan() more efficiently for C++ <cmath> than C <math.h>?
问题 Here's my code: int f(double x) { return isnan(x); } If I #include <cmath> I get this assembly: xorl %eax, %eax ucomisd %xmm0, %xmm0 setp %al This is reasonably clever: ucomisd sets the parity flag if the comparison of x with itself is unordered, meaning x is NAN. Then setp copies the parity flag into the result (only a single byte, hence the initial clear of %eax ). But if I #include <math.h> I get this assembly: jmp __isnan Now the code is not inline, and the __isnan function is certainly