In C you can test to see if a double if NaN using isnan(x). However many places online, including for example this SO answer say that you can simply use x!=x
Please refer to the normative section Annex F: IEC 60559 floating-point arithmetic of the C standard:
F.1 Introduction
An implementation that defines
__STDC_IEC_559__shall conform to the specifications in this annex.Implementations that do not define
__STDC_IEC_559__are not required to conform to these specifications.
F.9.3 Relational operators
The expression
x ≠ xis true ifxis aNaN.The expression
x = xis false ifXis aNan.
F.3 Operators and functions
The
isnanmacro inprovides theisnanfunction recommended in the Appendix to IEC 60559.