1 #include "lib.h"
2 #include "allocate.h"
3 
4 #include "compat/mmap-blob.c"
5 
6 #include <floatingpoint.h>
7 #include <limits.h>
8 #include <errno.h>
9 
string_to_ld(const char * str,char ** endptr)10 long double string_to_ld(const char *str, char **endptr)
11 {
12 	long double res;
13 	decimal_record dr;
14 	enum decimal_string_form form;
15 	decimal_mode dm;
16 	fp_exception_field_type excp;
17 	char *echar;
18 
19 	string_to_decimal ((char **)&str, INT_MAX, 0,
20 			   &dr, &form, &echar);
21 	if (endptr) *endptr = (char *)str;
22 
23 	if (form == invalid_form) {
24 		errno = EINVAL;
25 		return 0.0;
26 	}
27 
28 	dm.rd = fp_nearest;
29 	decimal_to_quadruple (&res, &dm, &dr, &excp);
30         if (excp & ((1 << fp_overflow) | (1 << fp_underflow)))
31                 errno = ERANGE;
32 	return res;
33 }
34