Node:Parsing of Floats, Previous:Parsing of Integers, Up:Parsing of Numbers
The str functions are declared in stdlib.h and those
beginning with wcs are declared in wchar.h. One might
wonder about the use of restrict in the prototypes of the
functions in this section. It is seemingly useless but the ISO C
standard uses it (for the functions defined there) so we have to do it
as well.
| double strtod (const char *restrict string, char **restrict tailptr) | Function |
The strtod ("string-to-double") function converts the initial
part of string to a floating-point number, which is returned as a
value of type double.
This function attempts to decompose string as follows:
If the string is empty, contains only whitespace, or does not contain an
initial substring that has the expected syntax for a floating-point
number, no conversion is performed. In this case, In a locale other than the standard If the string has valid syntax for a floating-point number but the value
is outside the range of a
The strings Since zero is a valid result as well as the value returned on error, you
should check for errors in the same way as for |
| float strtof (const char *string, char **tailptr) | Function |
| long double strtold (const char *string, char **tailptr) | Function |
These functions are analogous to strtod, but return float
and long double values respectively. They report errors in the
same way as strtod. strtof can be substantially faster
than strtod, but has less precision; conversely, strtold
can be much slower but has more precision (on systems where long
double is a separate type).
These functions have been GNU extensions and are new to ISO C99. |
| double wcstod (const wchar_t *restrict string, wchar_t **restrict tailptr) | Function |
| float wcstof (const wchar_t *string, wchar_t **tailptr) | Function |
| long double wcstold (const wchar_t *string, wchar_t **tailptr) | Function |
The wcstod, wcstof, and wcstol functions are
equivalent in nearly all aspect to the strtod, strtof, and
strtold functions but it handles wide character string.
The |
| double atof (const char *string) | Function |
This function is similar to the strtod function, except that it
need not detect overflow and underflow errors. The atof function
is provided mostly for compatibility with existing code; using
strtod is more robust.
|
The GNU C library also provides _l versions of these functions,
which take an additional argument, the locale to use in conversion.
See Parsing of Integers.