The printf family of functions includes the functions printf, fprintf, sprintf, vfprintf, vprintf, and vsprintf. These functions convert floating-point values of INFINITY and NaN to the strings "INFINITY" or "infinity" and "NAN" or "nan".

The case is determined by the format specification, as is the sign (positive or negative). When converting these values, the printf functions ignore the precision width given by the format specification.

Example: In the following example, printf converts the NaN and INFINITY values and prints the corresponding string.

#include <stdio.h>
#include <float.h>

int main(void)
{
   double infval = -(_INF);
   float nanval = _NANF;

   printf("-_INF is the same as %-15.30f\n", infval);
   printf("_NANF is the same as %-15.30F\n", nanval);

   return 0;

   /* The expected output is:

      -_INF is the same as -infinity
      _NANF is the same as NAN        */

}

For more information on the printf, fprintf, sprintf, vfprintf, vprintf, and vsprintf functions, see the entries for each function in Library Functions.


[Back] [Next]