Next: wcstol, Previous: wcsrtombs, Up: Stdlib [Contents][Index]

### 2.43 `wcstod`, `wcstof`, `wcstold`, `wcstod_l`, `wcstof_l`, `wcstold_l`—wide char string to double or float

Synopsis

    #include <stdlib.h>
    double wcstod(const wchar_t *__restrict str,
        wchar_t **__restrict tail);
    float wcstof(const wchar_t *__restrict str,
        wchar_t **__restrict tail);
    long double wcstold(const wchar_t *__restrict str,
        wchar_t **__restrict tail);

    #include <stdlib.h>
    double wcstod_l(const wchar_t *__restrict str,
        wchar_t **__restrict tail, locale_t locale);
    float wcstof_l(const wchar_t *__restrict str,
        wchar_t **__restrict tail, locale_t locale);
    long double wcstold_l(const wchar_t *__restrict str,
        wchar_t **__restrict tail,
        locale_t locale);

    double _wcstod_r(void *reent,
        const wchar_t *str, wchar_t **tail);
    float _wcstof_r(void *reent,
        const wchar_t *str, wchar_t **tail);

Description
`wcstod`, `wcstof`, `wcstold` parse the wide-character string str, producing a substring which can be converted to a double, float, or long double value. The substring converted is the longest initial subsequence of str, beginning with the first non-whitespace character, that has one of these formats:

    [+|-]digits[.[digits]][(e|E)[+|-]digits]
    [+|-].digits[(e|E)[+|-]digits]
    [+|-](i|I)(n|N)(f|F)[(i|I)(n|N)(i|I)(t|T)(y|Y)]
    [+|-](n|N)(a|A)(n|N)[<(>[hexdigits]<)>]
    [+|-]0(x|X)hexdigits[.[hexdigits]][(p|P)[+|-]digits]
    [+|-]0(x|X).hexdigits[(p|P)[+|-]digits]

The substring contains no characters if str is empty, consists entirely of whitespace, or if the first non-whitespace character is something other than `+`, `-`, `.`, or a digit, and cannot be parsed as infinity or NaN. If the platform does not support NaN, then NaN is treated as an empty substring. If the substring is empty, no conversion is done, and the value of str is stored in `*tail`. Otherwise, the substring is converted, and a pointer to the final string (which will contain at least the terminating null character of str) is stored in `*tail`. If you want no assignment to `*tail`, pass a null pointer as tail.

This implementation returns the nearest machine number to the input decimal string. Ties are broken by using the IEEE round-even rule. However, `wcstof` is currently subject to double rounding errors.

`wcstod_l`, `wcstof_l`, `wcstold_l` are like `wcstod`, `wcstof`, `wcstold` but perform the conversion based on the locale specified by the locale object locale. If locale is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined.

The alternate functions `_wcstod_r` and `_wcstof_r` are reentrant versions of `wcstod` and `wcstof`, respectively. The extra argument reent is a pointer to a reentrancy structure.

Returns
Return the converted substring value, if any. If no conversion could be performed, 0 is returned. If the correct value is out of the range of representable values, plus or minus `HUGE_VAL` is returned, and `ERANGE` is stored in errno. If the correct value would cause underflow, 0 is returned and `ERANGE` is stored in errno.

Portability
`wcstod` is ANSI. `wcstof`, `wcstold` are C99. `wcstod_l`, `wcstof_l`, `wcstold_l` are GNU extensions.

Supporting OS subroutines required: `close`, `fstat`, `isatty`, `lseek`, `read`, `sbrk`, `write`.

Next: wcstol, Previous: wcsrtombs, Up: Stdlib [Contents][Index]