Math.round() fixes

Harri Porten porten at froglogic.com
Thu Sep 30 09:27:22 CEST 2004


Hi,

here are some fixes for Math.round(). I see that the latest JSC snapshot I
have is just using ::floor(). This will probably miss out those cases
tested in khtmltests/regression/tests/js/math.js.

Harri.

---------- Forwarded message ----------
Date: Thu, 30 Sep 2004 08:47:33 +0200 (CEST)
From: Harri Porten <porten at kde.org>
Reply-To: kde-cvs at kde.org
To: kde-cvs at kde.org
Cc: khtml-cvs at kde.org
Subject: KDE_3_3_BRANCH: kdelibs/kjs

CVS commit by porten:

fixed Math.round() for very large numbers (bug discovered by Pascal)
and negative numbers with a .5 decimal.


  M +5 -0      ChangeLog   1.45.2.2
  M +5 -13     math_object.cpp   1.36.2.1


--- kdelibs/kjs/ChangeLog  #1.45.2.1:1.45.2.2
@@ -1,2 +1,7 @@
+2004-09-30  Harri Porten  <porten at kde.org>
+
+        * math_object.cpp: fixed Math.round() for very large numbers (bug
+        discovered by Pascal) and negative numbers with a .5 decimal.
+
 2004-09-29  Harri Porten  <porten at kde.org>


--- kdelibs/kjs/math_object.cpp  #1.36:1.36.2.1
@@ -237,18 +237,10 @@ Value MathFuncImp::call(ExecState *exec,
     break;
   case MathObjectImp::Round:
-    if (isNaN(arg)) {
-      result = arg;
-    }
-    else if (isInf(arg) || isInf(-arg)) {
-      result = arg;
-    }
-    else if (arg == -0.5 || IS_NEGATIVE_ZERO(arg)) {
-      result = -0.0;
-    }
-    else {
-      result = (double)(arg >= 0.0 ? int(arg + 0.5) : int(arg - 0.5));
-      if (result == 0.0 && arg < 0.0)
+    if (arg < 0 && arg >= -0.5)
         result = -0.0;
-    }
+    else if (IS_NEGATIVE_ZERO(arg))
+      result = arg;
+    else
+      result = ::floor(arg + 0.5);
     break;
   case MathObjectImp::Sin:




More information about the Khtml-devel mailing list