The string conversion functions that support infinity and NaN representations include the functions: atof, _atold, _ecvt, _fcvt, _gcvt, strtod, strtold, and wcstod.
The atof, _atold, strtod, strtold, and wcstod functions accept the strings INFINITY, INF, and NAN (in uppercase, lowercase, or mixed case) as input, and convert these strings to the corresponding macro value defined in <float.h>. The _ecvt, _fcvt, and _gcvt functions convert infinity and NaN values to the strings INFINITY and NAN, respectively.
Note: If a signaling NaN string is passed to a string conversion function, a quiet NaN value is returned, and no signal is raised.
Example: The following example uses atof to convert the strings "naN" and "inf" to the corresponding macro value.
#include <stdlib.h> #include <stdio.h> int main(void) { char *nanstr; char *infstr; nanstr = "naN"; printf( "Result of atof = %.10e\n", atof(nanstr) ); infstr = "inf"; printf( "Result of atof = %.10E\n", atof(infstr) ); return 0; /* The expected output is: Result of atof = nan Result of atof = INFINITY */ }
For more information on the individual string conversion functions, refer to the entries for them in Library Functions.