fixed parsef, exponent can now follow integer part

master
Tibor Bizjak 2023-07-17 12:44:19 +02:00
parent bcff42f74d
commit e6de3d1193
1 changed files with 18 additions and 20 deletions

View File

@ -188,27 +188,25 @@ char * parsef(char s[], double *x)
int sign = SIGN(s); int sign = SIGN(s);
ATOI(s, *x); ATOI(s, *x);
#define X(sep) *s != sep && int exp = 0;
if (DEC_SEP 1) { /* fractional part */
*x *= sign; #define X(sep) *s == sep ||
return s; if (DEC_SEP 0) {
s++;
ATOI(s, *x, exp--);
*x *= pow(10, exp);
}
*x *= sign;
#undef X
/* exponent part */
#define X(sep) *s == sep ||
if (EXP_SEP 0) {
s++;
sign = SIGN(s);
exp = 0;
ATOI(s, exp);
*x *= pow(10, sign * exp);
} }
#undef X #undef X
s++;
/* fractional part */
int exp = 0;
ATOI(s, *x, exp--);
*x *= sign * pow(10, exp);
#define X(sep) *s != sep &&
if (EXP_SEP 1)
return s;
#undef X
s++;
/* exponent */
sign = SIGN(s);
exp = 0;
ATOI(s, exp);
*x *= pow(10, sign * exp);
return s; return s;
} }