Try this as a properly working version:
Save as isnan.h:
And the test code to check for NaN and Inf:
Notice the output is:
0 / 0 is NaN but is *not* INF.
1 / 0 is NaN and is also INF.
0 / 1 is neither NaN, nor is it INF.
Save as isnan.h:
Code: (Select All)
#include <stdio.h>
#include <math.h>
#include <float.h>
int IsNan (long double n);
int IsInf (long double n);
IsNan (long double n) { return -isnan(n); }
IsInf (long double n) { return -isinf(n); }
Code: (Select All)
DECLARE LIBRARY "isnan"
FUNCTION IsNan% (BYVAL n AS _FLOAT)
FUNCTION IsInf% (BYVAL n AS _FLOAT)
END DECLARE
PRINT IsNan(0 / 0), IsInf(0 / 0)
PRINT IsInf(1 / 0), IsInf(1 / 0)
PRINT IsInf(0 / 1), IsInf(0 / 1)
Notice the output is:
0 / 0 is NaN but is *not* INF.
1 / 0 is NaN and is also INF.
0 / 1 is neither NaN, nor is it INF.