mirror of
https://github.com/ccxvii/mujs.git
synced 2026-02-06 01:41:37 +08:00
Calculate exponent the same way as fractions for symmetry in the lexer.
"3E-1" should have the same rounding error as "0.3"
This commit is contained in:
10
jslex.c
10
jslex.c
@@ -283,6 +283,7 @@ static inline double lexexponent(js_State *J)
|
||||
static inline int lexnumber(js_State *J)
|
||||
{
|
||||
double n;
|
||||
double e;
|
||||
|
||||
if (ACCEPT('0')) {
|
||||
if (ACCEPT('x') || ACCEPT('X')) {
|
||||
@@ -294,19 +295,22 @@ static inline int lexnumber(js_State *J)
|
||||
n = 0;
|
||||
if (ACCEPT('.'))
|
||||
n += lexfraction(J);
|
||||
n *= pow(10, lexexponent(J));
|
||||
} else if (ACCEPT('.')) {
|
||||
if (!isdec(PEEK))
|
||||
return '.';
|
||||
n = lexfraction(J);
|
||||
n *= pow(10, lexexponent(J));
|
||||
} else {
|
||||
n = lexinteger(J);
|
||||
if (ACCEPT('.'))
|
||||
n += lexfraction(J);
|
||||
n *= pow(10, lexexponent(J));
|
||||
}
|
||||
|
||||
e = lexexponent(J);
|
||||
if (e < 0)
|
||||
n /= pow(10, -e);
|
||||
else if (e > 0)
|
||||
n *= pow(10, e);
|
||||
|
||||
if (isidentifierstart(PEEK))
|
||||
jsY_error(J, "number with letter suffix");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user