rational number literal reads exact integer if possible

This commit is contained in:
Yuichi Nishiwaki 2014-07-15 17:58:46 +09:00
parent 6c68955dee
commit d85801e396
1 changed files with 5 additions and 1 deletions

View File

@ -208,7 +208,11 @@ read_number(pic_state *pic, struct pic_port *port, char c)
n = atoi(buf); n = atoi(buf);
next(port); next(port);
read_uinteger(pic, port, next(port), buf); read_uinteger(pic, port, next(port), buf);
return pic_float_value(n / (double)atoi(buf)); if (n == n / atoi(buf) * atoi(buf)) {
return pic_int_value(n / atoi(buf)); /* exact */
} else {
return pic_float_value(n / (double)atoi(buf));
}
default: default:
return pic_int_value(atoi(buf)); return pic_int_value(atoi(buf));