shithub: libmujs

Download patch

ref: 43de5a093fc40fd64180910427316b475a75d4d4
parent: 46aca3b4f8a71cda713b1619d83cd4fa9881b55b
author: Tor Andersson <tor.andersson@artifex.com>
date: Wed Oct 15 09:12:45 EDT 2014

Implement Math.round according to the (stupid) specification.

Thanks to nsz for pointing out this implementation.

--- a/jsmath.c
+++ b/jsmath.c
@@ -64,7 +64,12 @@
 
 static void Math_round(js_State *J)
 {
-	js_pushnumber(J, round(js_tonumber(J, 1)));
+	double x = js_tonumber(J, 1);
+	double r = round(x);
+	if (r - x == -0.5)
+		js_pushnumber(J, x == -0.5 ? -0.0 : r + 1.0);
+	else
+		js_pushnumber(J, r);
 }
 
 static void Math_sin(js_State *J)