wcstod32() - wcstod64() - wcstod128() — Convert Wide-Character String to Decimal Floating-Point
Format
#define __STDC_WANT_DEC_FP__
#include <wchar.h>
_Decimal32 wcstod32(const wchar_t *nptr, wchar_t **endptr);
_Decimal64 wcstod64(const wchar_t *nptr, wchar_t **endptr);
_Decimal128 wcstod128(const wchar_t *nptr, wchar_t **endptr);
Language Level
XPG4
Threadsafe
Yes
Locale Sensitive
The behavior of these functions might be affected by the LC_CTYPE and LC_NUMERIC categories of the current locale if LOCALETYPE(*LOCALE) is specified on the compilation command. The behavior of these functions might also be affected by the LC_UNI_CTYPE and LC_UNI_NUMERIC categories of the current locale if LOCALETYPE(*LOCALEUCS2) or LOCALETYPE(*LOCALEUTF) is specified on the compilation command. These functions are not available when LOCALETYPE(*CLD) is specified on the compilation command. For more information, see Understanding CCSIDs and Locales.
Wide Character Function
See Wide Characters for more information.
Description
The wcstod32()
, wcstod64()
,
and wcstod128()
functions convert the initial portion
of the wide-character string pointed to by nptr to
a single-precision, double-precision, or quad-precision decimal floating-point
value. The parameter nptr points to a sequence
of characters that can be interpreted as a numeric decimal floating-point
value. The wcstod32()
, wcstod64()
,
and wcstod128()
functions stop reading the string
at the first character that is not recognized as part of a number.
This character can be the wchar_t null character at the end of the
string. The endptr parameter is updated
to point to this character, provided that endptr is
not a NULL pointer.
The first character that does not fit this form stops the scan. In addition, a sequence of INFINITY or NAN (ignoring case) is allowed.
Return Value
The wcstod32()
, wcstod64()
,
and wcstod128()
functions return the value of the
floating-point number, except when the representation causes an underflow
or overflow. For an overflow, wcstod32()
returns HUGE_VAL_D32 or -HUGE_VAL_D32; wcstod64()
returns HUGE_VAL_D64 or -HUGE_VAL_D64; wcstod128()
returns HUGE_VAL_D128 or -HUGE_VAL_D128.
For an underflow, all functions return +0.E0.
In both the overflow and underflow cases, errno is set to ERANGE. If the string pointed to by nptr does not have the expected form, a value of +0.E0 is returned and the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a NULL pointer.
The wcstod32()
, wcstod64()
,
and wcstod128()
functions do not fail if a character
other than a digit follows an E or e that is read
as an exponent. For example, 100elf is converted to the floating-point
value 100.0.
A character sequence of INFINITY (ignoring case) yields a value of INFINITY. A character value of NAN (ignoring case) yields a Quiet Not-A-Number (NaN) value.
If necessary, the return value is rounded using the rounding mode Round to Nearest, Ties to Even.
Example
This example converts the string wcs to single-precision, double-precision, and quad-precision decimal floating-point values.
#define __STDC_WANT_DEC_FP__
#include <stdio.h>
#include <wchar.h>
int main(void)
{
wchar_t *wcs = L"3.1415926This stopped it";
wchar_t *stopwcs;
printf("wcs = \"%ls\"\n", wcs);
printf("wcstod32 = %Hf\n", wcstod32(wcs, &stopwcs));
printf(" Stopped scan at \"%ls\"\n", stopwcs);
printf("wcs = \"%ls\"\n", wcs);
printf("wcstod64 = %Df\n", wcstod64(wcs, &stopwcs));
printf(" Stopped scan at \"%ls\"\n", stopwcs);
printf("wcs = \"%ls\"\n", wcs);
printf("wcstod128 = %DDf\n", wcstod128(wcs, &stopwcs));
printf(" Stopped scan at \"%ls\"\n", stopwcs);
}
/***************** Output should be similar to: *****************
wcs = "3.1415926This stopped it"
wcstod32 = 3.141593
Stopped scan at "This stopped it"
wcs = "3.1415926This stopped it"
wcstod64 = 3.141593
Stopped scan at "This stopped it"
wcs = "3.1415926This stopped it"
wcstod128 = 3.141593
Stopped scan at "This stopped it"
*/
Related Information
- strtod() - strtof() - strtold() — Convert Character String to Double, Float, and Long Double
- strtod32() - strtod64() - strtod128() — Convert Character String to Decimal Floating-Point
- strtol() – strtoll() — Convert Character String to Long and Long Long Integer
- wcstod() - wcstof() - wcstold() — Convert Wide-Character String to Double, Float, and Long Double
- wcstol() – wcstoll() — Convert Wide Character String to Long and Long Long Integer
- wcstoul() – wcstoull() — Convert Wide Character String to Unsigned Long and Unsigned Long Long Integer
- <wchar.h>