#include <float.h>
#include <limits.h>
#include <errno.h>
+#include <ctype.h>
#include "shgetc.h"
#include "floatscan.h"
#define LD_B1B_MAX 9007199, 254740991
#define KMAX 128
-#else /* LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 */
+#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
#define LD_B1B_DIG 3
#define LD_B1B_MAX 18, 446744073, 709551615
#define KMAX 2048
+#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
+
+#define LD_B1B_DIG 4
+#define LD_B1B_MAX 10384593, 717069655, 257060992, 658440191
+#define KMAX 2048
+
+#else
+#error Unsupported long double representation
#endif
#define MASK (KMAX-1)
gotdig=1;
} else {
dc++;
- if (c!='0') x[KMAX-4] |= 1;
+ if (c!='0') {
+ lnz = (KMAX-4)*9;
+ x[KMAX-4] |= 1;
+ }
}
}
if (!gotrad) lrp=dc;
return sign * (long double)x[0] * p10s[rp-10];
}
+ /* Drop trailing zeros */
+ for (; !x[z-1]; z--);
+
/* Align radix point to B1B digit boundary */
if (rp % 9) {
int rpm9 = rp>=0 ? rp%9 : rp%9+9;
long double __floatscan(FILE *f, int prec, int pok)
{
int sign = 1;
- int i;
+ size_t i;
int bits;
int emin;
int c;
if (!i) for (i=0; i<3 && (c|32)=="nan"[i]; i++)
if (i<2) c = shgetc(f);
if (i==3) {
+ if (shgetc(f) != '(') {
+ shunget(f);
+ return NAN;
+ }
+ for (i=1; ; i++) {
+ c = shgetc(f);
+ if (c-'0'<10U || c-'A'<26U || c-'a'<26U || c=='_')
+ continue;
+ if (c==')') return NAN;
+ shunget(f);
+ if (!pok) {
+ errno = EINVAL;
+ shlim(f, 0);
+ return 0;
+ }
+ while (i--) shunget(f);
+ return NAN;
+ }
return NAN;
}