Piotr Caban : jscript: Added Math_sin implementation.

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


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

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

jscript: Added Math_sin implementation.

---

 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 9b41385..9804c36 100644
--- a/dlls/jscript/math.c
+++ b/dlls/jscript/math.c
@@ -501,8 +501,22 @@ static HRESULT Math_round(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS
 static HRESULT Math_sin(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, sin(num_val(&v)));
+    return S_OK;
 }
 
 static HRESULT Math_sqrt(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index d810ff0..a5d9286 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -818,6 +818,36 @@ ok(tmp === Infinity, "Math.log(Infinity) = " + tmp);
 tmp = Math.log(-Infinity);
 ok(isNaN(tmp), "Math.log(-Infinity) is not NaN");
 
+tmp = Math.sin(0);
+ok(tmp === 0, "Math.sin(0) = " + tmp);
+
+tmp = Math.sin(Math.PI/2);
+ok(tmp === 1, "Math.sin(Math.PI/2) = " + tmp);
+
+tmp = Math.sin(-Math.PI/2);
+ok(tmp === -1, "Math.sin(-Math.PI/2) = " + tmp);
+
+tmp = Math.sin(Math.PI/3, 2);
+ok(Math.floor(tmp*100) === 86, "Math.sin(Math.PI/3, 2) = " + tmp);
+
+tmp = Math.sin(true);
+ok(Math.floor(tmp*100) === 84, "Math.sin(true) = " + tmp);
+
+tmp = Math.sin(false);
+ok(tmp === 0, "Math.sin(false) = " + tmp);
+
+tmp = Math.sin();
+ok(isNaN(tmp), "Math.sin() is not NaN");
+
+tmp = Math.sin(NaN);
+ok(isNaN(tmp), "Math.sin(NaN) is not NaN");
+
+tmp = Math.sin(Infinity);
+ok(isNaN(tmp), "Math.sin(Infinity) is not NaN");
+
+tmp = Math.sin(-Infinity);
+ok(isNaN(tmp), "Math.sin(-Infinity) is not NaN");
+
 var func = function  (a) {
         var a = 1;
         if(a) return;




More information about the wine-cvs mailing list