Piotr Caban : jscript: Added implementation of Math_sqrt.

Alexandre Julliard julliard at winehq.org
Wed May 27 09:26:52 CDT 2009


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

Author: Piotr Caban <piotr.caban at gmail.com>
Date:   Wed May 27 01:10:25 2009 +0200

jscript: Added implementation of Math_sqrt.

---

 dlls/jscript/math.c       |   18 ++++++++++++++++--
 dlls/jscript/tests/api.js |   30 ++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/dlls/jscript/math.c b/dlls/jscript/math.c
index 9804c36..2928a97 100644
--- a/dlls/jscript/math.c
+++ b/dlls/jscript/math.c
@@ -522,8 +522,22 @@ static HRESULT Math_sin(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *d
 static HRESULT Math_sqrt(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    VARIANT v;
+    HRESULT hres;
+
+    TRACE("\n");
+
+    if(!arg_cnt(dp)) {
+        if(retv) num_set_nan(retv);
+        return S_OK;
+    }
+
+    hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &v);
+    if(FAILED(hres))
+        return hres;
+
+    if(retv) num_set_val(retv, sqrt(num_val(&v)));
+    return S_OK;
 }
 
 static HRESULT Math_tan(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index a5d9286..54fc2a1 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -848,6 +848,36 @@ ok(isNaN(tmp), "Math.sin(Infinity) is not NaN");
 tmp = Math.sin(-Infinity);
 ok(isNaN(tmp), "Math.sin(-Infinity) is not NaN");
 
+tmp = Math.sqrt(0);
+ok(tmp === 0, "Math.sqrt(0) = " + tmp);
+
+tmp = Math.sqrt(4);
+ok(tmp === 2, "Math.sqrt(4) = " + tmp);
+
+tmp = Math.sqrt(-1);
+ok(isNaN(tmp), "Math.sqrt(-1) is not NaN");
+
+tmp = Math.sqrt(2, 2);
+ok(Math.floor(tmp*100) === 141, "Math.sqrt(2, 2) = " + tmp);
+
+tmp = Math.sqrt(true);
+ok(tmp === 1, "Math.sqrt(true) = " + tmp);
+
+tmp = Math.sqrt(false);
+ok(tmp === 0, "Math.sqrt(false) = " + tmp);
+
+tmp = Math.sqrt();
+ok(isNaN(tmp), "Math.sqrt() is not NaN");
+
+tmp = Math.sqrt(NaN);
+ok(isNaN(tmp), "Math.sqrt(NaN) is not NaN");
+
+tmp = Math.sqrt(Infinity);
+ok(tmp === Infinity, "Math.sqrt(Infinity) = " + tmp);
+
+tmp = Math.sqrt(-Infinity);
+ok(isNaN(tmp), "Math.sqrt(-Infinity) is not NaN");
+
 var func = function  (a) {
         var a = 1;
         if(a) return;




More information about the wine-cvs mailing list