shithub: libmujs

Download patch

ref: 6ecb4e7a4eda61860545ddff31fded249f536ebd
parent: 7573f4238e582ec4a5fb04faf6fd913d90722352
author: Tor Andersson <[email protected]>
date: Wed Feb 5 00:40:35 EST 2014

Calculate exponent the same way as fractions for symmetry in the lexer.

"3E-1" should have the same rounding error as "0.3"

--- a/jslex.c
+++ b/jslex.c
@@ -283,6 +283,7 @@
 static inline int lexnumber(js_State *J)
 {
 	double n;
+	double e;
 
 	if (ACCEPT('0')) {
 		if (ACCEPT('x') || ACCEPT('X')) {
@@ -294,18 +295,21 @@
 		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");