There is a define for checking if a number is nan inf etc in math.h (you can use it without import I think).
isnan(myValue)
if you follow the define you will end up with
(x!=x)
there are also some other useful defines like isinf, isnormal , isfinite , ...