wcstod32, wcstod64, or wcstod128 Subroutine

Purpose

Converts a wide character string to a decimal floating-point number.

Library

Standard C Library (libc.a)

Syntax

#include <stdlib.h>
#include <wchar.h>

_Decimal32 wcstod32 (nptr, endptr)
const wchar_t *nptr;
wchar_t **endptr;

_Decimal64 wcstod64 (nptr, endptr)
const wchar_t *nptr;
wchar_t **endptr;

_Decimal128 wcstod128 (nptr, endptr)
const wchar_t *nptr;
wchar_t **endptr;

Description

The wcstod32, wcstod64, and wcstod128 subroutines convert the initial portion of the wide-character string pointed to by the nptr parameter to _Decimal32, _Decimal64, and _Decimal128 representation, respectively. First, these subroutines decompose the input wide-character string into three parts:
  • An initial and possibly empty sequence of white-space and wide-character codes
  • A subject sequence interpreted as a floating-point constant or represents infinity or NaN
  • A final wide-character string of one or more unrecognized wide-character codes, including the terminating null wide-character code of the input wide-character string
Then, wcstod32, wcstod64, and wcstod128 subroutines attempt to convert the subject sequence to a floating-point number, and return the result.
The expected form of the subject sequence is an optional plus or minus sign and one of the following:
  • A non-empty sequence of decimal digits that might contains a radix character and an exponent part
  • INF, INFINITY, or any other wide string equivalent except for case
  • NAN or NAN (n-wchar-sequence opt), ignoring case in the NAN, where:
    n-wchar-sequence:
                   digit
                   n-wchar-sequence digit

The subject sequence is defined as the longest initial subsequence of the input wide string, starting with the first non-white-space wide character that is of the expected form. The subject sequence contains no wide characters if the input wide string is not of the expected form.

If the subject sequence has the expected form for a floating-point number, the sequence of wide characters starting with the first digit or the radix character (whichever occurs first) are interpreted as a floating constant according to the rules of the C language, except that the sequence is not a hexadecimal floating number, or that the radix character is used in place of a period. If neither an exponent part nor a radix character appears in a decimal floating-point number, an exponent part of the appropriate type with a value of 0 is assumed to follow the last digit in the string.

If the subject sequence begins with a minus sign, the sequence is interpreted as negated. A wide-character sequence INF or INFINITY is interpreted as infinity. A wide-character sequence NAN or NAN(n-wchar-sequence opt) is interpreted as a quiet NaN. The meaning of the n-wchar sequences is implementation-defined. A pointer to the final wide string is stored in the object pointed to by the endptr parameter, provided that the endptr parameter is not a null pointer.

The radix character is as defined in the locale of the program (category LC_NUMERIC). In the POSIX locale, or in a locale where the radix character is not defined, the radix character defaults to a period.

In locales other than the C or POSIX locale, other implementation-defined subject sequences can be accepted.

If the subject sequence is empty or does not have the expected form, no conversion is performed. The value of the nptr parameter is stored in the object pointed to by the endptr parameter, provided that the endptr parameter is not a null pointer.

The wcstod32, wcstod64, and wcstod128 subroutines do not change the setting of the errno global variable if successful.

A value of 0 is returned on error and is also a valid return on success. Therefore, an application wishing to check for error situations should set the errno global variable to the value of 0, call the wcstod32, wcstod64, or wcstod128 subroutine, and check the errno global variable.

Parameters

Item Description
nptr Contains a pointer to the string to be converted to a decimal floating point value.
endpr Contains a pointer to the position in the string specified by the nptr parameter where a wide character is found that is not a valid character for the conversion.

Return Values

Upon successful completion, the wcstod32, wcstod64, and wcstod128 subroutines return the converted value. If no conversion can be performed, the value of 0 is returned and the errno global variable might be set to EINVAL.

If the correct value is outside the range of representable values, ±HUGE_VAL_D32, ±HUGE_VAL_D64, or ±HUGE_VAL_D128 is returned (according to the return type and sign of the value), and the errno global variable is set to ERANGE.

If the correct value causes underflow, a value whose magnitude is no greater than the smallest normalized positive number in the return type is returned, and the errno global variable is set to ERANGE.