cc [ flags ] -I/usr/local/include file(s) -L/usr/local/lib -lmcw [ ... ] #include <mathcw.h> #include <cvticw.h> extern float cvtnanf (const char *s, char **endptr); extern double cvtnan (const char *s, char **endptr); extern long double cvtnanl (const char *s, char **endptr); extern __float80 cvtnanw (const char *s, char **endptr); extern __float128 cvtnanq (const char *s, char **endptr); extern long_long_double cvtnanll (const char *s, char **endptr); extern decimal_float cvtnandf (const char *s, char **endptr); extern decimal_double cvtnand (const char *s, char **endptr); extern decimal_long_double cvtnandl (const char *s, char **endptr); extern decimal_long_long_double cvtnandll (const char *s, char **endptr);
NB: Functions with prototypes containing underscores in type names may be available only with certain extended compilers.
NaNs have the unique property that they are unequal to anything, including themselves. Thus, the test expression x != x is true (1) if, and only if, x is a NaN. Regrettably, some compilers botch this simple code, so NaN tests should be handled by the isnan(3CW) functions.
Quiet NaNs in arithmetic operations never raise exceptions, and are therefore not detectable, or trappable, until explicit NaN tests on results are made.
Signaling NaNs in arithmetic operations raise exceptions, but those exceptions may be masked or ignored. The results of such operations are normally quiet NaNs, so the signaling property is lost.
The payloads can be used to identify NaNs produced in particular program locations, but it is necessary to use a bitwise comparison function, such as that provided by memcmp(3), to distinguish between such NaNs.
A common practical use of NaNs in floating-point programs is to distinguish missing data from valid data. For example, a spreadsheet program might ignore NaN cells in computing functions on columns of numbers.
Some compilers provide an option to store NaNs in otherwise-uninitialized floating-point variables, to help catch use-before-definition errors.
If the payload is not followed by a close parenthesis, the payload is silently discarded without any error indication, but the specified NaN is still recognized.
If endptr is not NULL, set the pointer to which it points to the address of the character following the last character successfully converted. With suitable conventions for value delimiters, it is then possible to determine whether the value is erroneous or not.
Conversion of NaN strings does not set errno.