Ejemplo n.º 1
0
long double
wcstold(const wchar_t *cp, wchar_t **ptr)
{
	long double	x;
	decimal_mode	mr;
	decimal_record	dr;
	fp_exception_field_type fs;
	int		form;

	wstring_to_decimal(&cp, 1, &dr, &form);
	if (ptr != NULL)
		*ptr = (wchar_t *)cp;
	if (form == 0)
		return (0.0L);
#if defined(__i386) || defined(__amd64)
	mr.rd = __xgetRD();
	if (form < 0)
		__hex_to_extended(&dr, mr.rd, (extended *)&x, &fs);
	else
		decimal_to_extended((extended *)&x, &mr, &dr, &fs);
#elif defined(__sparc)
	mr.rd = _QgetRD();
	if (form < 0)
		__hex_to_quadruple(&dr, mr.rd, &x, &fs);
	else
		decimal_to_quadruple(&x, &mr, &dr, &fs);
#else
#error Unknown architecture!
#endif
	if (fs & ((1 << fp_overflow) | (1 << fp_underflow)))
		errno = ERANGE;
	return (x);
}
Ejemplo n.º 2
0
long double string_to_ld(const char *str, char **endptr)
{
	long double res;
	decimal_record dr;
	enum decimal_string_form form;
	decimal_mode dm;
	fp_exception_field_type excp;
	char *echar;

	string_to_decimal ((char **)&str, INT_MAX, 0,
			   &dr, &form, &echar);
	if (endptr) *endptr = (char *)str;

	if (form == invalid_form) {
		errno = EINVAL;
		return 0.0;
	}

	dm.rd = fp_nearest;
	decimal_to_quadruple (&res, &dm, &dr, &excp);
        if (excp & ((1 << fp_overflow) | (1 << fp_underflow)))
                errno = ERANGE;
	return res;
}