6.23.50 wcstold Function

Convert wide string to a long double precision floating-point value.

Attention: This function is implemented only by MPLAB XC32 C compilers.

Include

<wchar.h>

Prototype

long double wcstold(const wchar_t * restrict nptr, wchar_t ** restrict endptr);

Arguments

nptr
the wide string to attempt to convert
endptr
pointer to store the address of the remainder of the wide string that was not converted

Return Value

The converted value, or 0 if the conversion could not be performed. If the correct value of the conversion is outside the range of representable values, HUGE_VAL is returned with a sign being that of the correct value. If the result underflows, the function returns a value whose magnitude is no greater than the smallest normalized positive number in the return type.

Remarks

The wcstold function attempts to convert a portion of the wide string pointed to by nptr to a long double floating-point value.

The initial section consists of any white-space wide characters.

The subject section represents the floating-point constant to convert and consists of an optional plus or minus sign then one of the following.
  • Decimal digits optionally containing a decimal-point wide character, then an optional exponent part, being e or E followed by an option sign and decimal digits
  • A 0x or 0X, then a nonempty sequence of hexadecimal digits optionally containing a decimal-point wide character, then an optional binary exponent part, being p or P, and option sign, and decimal digits.
  • one of INF or INFINITY, ignoring case
  • NAN, ignoring case, optionally followed by any sequence contain digits or non-digits:
Conversion stops once an unrecognized wide character is encountered, thus the subject sequence is defined as the longest subsequence of the input wide string after the initial section and that is of the expected form. A pointer to the position of the first unrecognizable wide character in the wide string is stored in the object pointed to by endptr, provided that endptr is not a null pointer.

The final section consists of wide characters in the wide string that were unrecognized in the subject section and which will include the terminating null wide character of the wide string. This section of the wide string will be accessible via the address stored to endptr, provided endptr is not a null pointer.

The value of the macro ERANGE is stored in errno if the correct value of the conversion is outside the range of representable values. The errno variable is not set to ERANGE if the result underflows.

Example

#include <wchar.h>

int main(void)
{
  wchar_t ws[] = L"2000.5 -6.0E-3 0x70FF INFINITY";
  wchar_t * pEnd;
  long double d1, d2, d3, d4;

  d1 = wcstold(ws, &pEnd);
  d2 = wcstold(pEnd, &pEnd);
  d3 = wcstold(pEnd, &pEnd);
  d4 = wcstold(pEnd, NULL);
  wprintf(L"The converted string values are: %Lg, %Lg, %Lg, and %Lg.\n", d1, d2, d3, d4);
}

Example Output

The converted string values are: 2000.5, -0.006, 28927, and inf.