Enable #x-1_2_3 syntax and get rid of -0x123

This commit is contained in:
Lassi Kortela 2019-08-10 16:13:26 +03:00
parent d5bb6b3116
commit b441573bde
1 changed files with 6 additions and 5 deletions

View File

@ -85,7 +85,6 @@ static int read_digits(char *token, char **out_end, unsigned int radix,
int isnumtok_base(char *tok, value_t *pval, int base) int isnumtok_base(char *tok, value_t *pval, int base)
{ {
char *end; char *end;
int64_t i64;
uint64_t ui64; uint64_t ui64;
double d; double d;
@ -130,12 +129,14 @@ int isnumtok_base(char *tok, value_t *pval, int base)
*pval = mk_double(D_NINF); *pval = mk_double(D_NINF);
return 1; return 1;
} }
errno = 0; if (!read_digits(tok + 1, &end, base, &ui64)) {
i64 = strtoll(tok, &end, base);
if (errno)
return 0; return 0;
}
if (ui64 >= 0x8000000000000000ULL) {
lerror(ArgError, "Number too negative");
}
if (pval) if (pval)
*pval = return_from_int64(i64); *pval = return_from_int64(-(int64_t)ui64);
return (*end == '\0'); return (*end == '\0');
} }
if (tok[0] == '_') { if (tok[0] == '_') {