reads number as accurate as possible
This commit is contained in:
parent
b2a14ca0f1
commit
5d3c59fc98
12
src/read.c
12
src/read.c
|
@ -178,14 +178,18 @@ read_uinteger(pic_state *pic, struct pic_port *port, char c)
|
||||||
static pic_value
|
static pic_value
|
||||||
read_number(pic_state *pic, struct pic_port *port, char c)
|
read_number(pic_state *pic, struct pic_port *port, char c)
|
||||||
{
|
{
|
||||||
int64_t i, j;
|
char buf[256], *cur;
|
||||||
|
int64_t i;
|
||||||
|
|
||||||
i = read_uinteger(pic, port, c);
|
i = read_uinteger(pic, port, c);
|
||||||
|
|
||||||
if (peek(port) == '.') {
|
if (peek(port) == '.') {
|
||||||
next(port);
|
cur = buf + snprintf(buf, sizeof buf, "%lld", i);
|
||||||
j = read_uinteger(pic, port, next(port));
|
do {
|
||||||
return pic_float_value(i + (double)j * pow(10, -snprintf(NULL, 0, "%lld", j)));
|
*cur++ = next(port);
|
||||||
|
} while (isdigit(peek(port)));
|
||||||
|
*cur = '\0';
|
||||||
|
return pic_float_value(atof(buf));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return pic_int_value(i);
|
return pic_int_value(i);
|
||||||
|
|
Loading…
Reference in New Issue