CKTIS / C
isnan — C23 floating-point classification macro
`isnan(x)` from `<math.h>` is a classification macro that returns nonzero exactly when its real floating argument is NaN. Finite values and both infinities produce zero.
Version: C23
Syntax
isnan(x)isnan(x) from <math.h> is a classification macro that returns nonzero exactly when its real floating argument is NaN. Finite values and both infinities produce zero.
The example tests NAN, INFINITY, 0.0, and -NAN, normalizing with != 0. Output 1 0 0 1 shows that changing a NaN’s sign does not make it numeric, while infinity is not NaN.
Do not compare with NAN using ==, because NaN is unequal to itself; use isnan. The NAN macro is available when the implementation supports quiet NaNs for float, as the example environment does. isnan classifies an already computed result: it neither prevents a domain error nor explains its cause, so validate inputs earlier. Before classification, a value represented with greater precision or range is converted to the semantic type determined by the argument type.
Examples
#include <math.h>
#include <stdio.h>
int main(void){double values[]={NAN,INFINITY,0.0,-NAN};printf("%d %d %d %d\n",isnan(values[0])!=0,isnan(values[1])!=0,isnan(values[2])!=0,isnan(values[3])!=0);return 0;}
Result
1 0 0 1
The example tests `NAN`, `INFINITY`, `0.0`, and `-NAN`, normalizing with `!= 0`. Output `1 0 0 1` shows that changing a NaN’s sign does not make it numeric, while infinity is not NaN.