Jacek Caban : jscript: Added NaN handling to Math.min and Math.max.

Alexandre Julliard julliard at winehq.org
Fri Oct 17 07:25:50 CDT 2008


Module: wine
Branch: master
Commit: 2e075e9862e55c7937477d7cdfd2810e5ea415ca
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=2e075e9862e55c7937477d7cdfd2810e5ea415ca

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Oct 16 14:31:52 2008 -0500

jscript: Added NaN handling to Math.min and Math.max.

---

 dlls/jscript/math.c       |   21 +++++++++++----------
 dlls/jscript/tests/api.js |   12 ++++++++++++
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/dlls/jscript/math.c b/dlls/jscript/math.c
index e0e88e4..b55ed52 100644
--- a/dlls/jscript/math.c
+++ b/dlls/jscript/math.c
@@ -16,6 +16,9 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <math.h>
 
 #include "jscript.h"
@@ -222,11 +225,10 @@ static HRESULT Math_max(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *d
 
     TRACE("\n");
 
-    /* FIXME: Handle NaN */
-
     if(!arg_cnt(dp)) {
-        FIXME("arg_cnt = 0\n");
-        return E_NOTIMPL;
+        if(retv)
+            num_set_inf(retv, FALSE);
+        return S_OK;
     }
 
     hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &v);
@@ -240,7 +242,7 @@ static HRESULT Math_max(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *d
             return hres;
 
         d = num_val(&v);
-        if(d > max)
+        if(d > max || isnan(d))
             max = d;
     }
 
@@ -260,11 +262,10 @@ static HRESULT Math_min(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *d
 
     TRACE("\n");
 
-    /* FIXME: Handle NaN */
-
     if(!arg_cnt(dp)) {
-        FIXME("arg_cnt = 0\n");
-        return E_NOTIMPL;
+        if(retv)
+            num_set_inf(retv, TRUE);
+        return S_OK;
     }
 
     hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &v);
@@ -278,7 +279,7 @@ static HRESULT Math_min(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *d
             return hres;
 
         d = num_val(&v);
-        if(d < min)
+        if(d < min || isnan(d))
             min = d;
     }
 
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 42dc080..c0e63ef 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -368,6 +368,12 @@ ok(tmp === 1, "Math.min(1) = " + tmp);
 tmp = Math.min(1, false);
 ok(tmp === 0, "Math.min(1, false) = " + tmp);
 
+tmp = Math.min();
+ok(tmp === Infinity, "Math.min() = " + tmp);
+
+tmp = Math.min(1, NaN, -Infinity, false);
+ok(isNaN(tmp), "Math.min(1, NaN, -Infinity, false) is not NaN");
+
 tmp = Math.min(1, false, true, null, -3);
 ok(tmp === -3, "Math.min(1, false, true, null, -3) = " + tmp);
 
@@ -380,6 +386,12 @@ ok(tmp === 1, "Math.max(true, 0) = " + tmp);
 tmp = Math.max(-2, false, true, null, 1);
 ok(tmp === 1, "Math.max(-2, false, true, null, 1) = " + tmp);
 
+tmp = Math.max();
+ok(tmp === -Infinity, "Math.max() = " + tmp);
+
+tmp = Math.max(true, NaN, 0);
+ok(isNaN(tmp), "Math.max(true, NaN, 0) is not NaN");
+
 tmp = Math.round(0.5);
 ok(tmp === 1, "Math.round(0.5) = " + tmp);
 




More information about the wine-cvs mailing list