shithub: libmujs

Download patch

ref: 3c58fa90c8fd063c7ccb00a85a7e238ae2788a73
parent: fea397f56b55e62f1ed1182adb9c74d45a4a4db9
author: Tor Andersson <[email protected]>
date: Sun Jan 19 11:20:59 EST 2014

Fix bug in toFixed, toPrecision and toExponential.

--- a/jsbnumber.c
+++ b/jsbnumber.c
@@ -37,7 +37,7 @@
 	js_Object *self = js_toobject(J, 0);
 	int width = js_tonumber(J, 1);
 	if (self->type != JS_CNUMBER) jsR_error(J, "TypeError");
-	sprintf(buf, "%*f", width, self->u.number);
+	sprintf(buf, "%.*f", width, self->u.number);
 	js_pushstring(J, buf);
 	return 1;
 }
@@ -48,7 +48,7 @@
 	js_Object *self = js_toobject(J, 0);
 	int width = js_tonumber(J, 1);
 	if (self->type != JS_CNUMBER) jsR_error(J, "TypeError");
-	sprintf(buf, "%*e", width, self->u.number);
+	sprintf(buf, "%.*e", width, self->u.number);
 	js_pushstring(J, buf);
 	return 1;
 }
@@ -59,7 +59,7 @@
 	js_Object *self = js_toobject(J, 0);
 	int width = js_tonumber(J, 1);
 	if (self->type != JS_CNUMBER) jsR_error(J, "TypeError");
-	sprintf(buf, "%*g", width, self->u.number);
+	sprintf(buf, "%.*g", width, self->u.number);
 	js_pushstring(J, buf);
 	return 1;
 }