jscript: Added implementation of Math_sqrt.

This commit is contained in:
Piotr Caban 2009-05-27 01:10:25 +02:00 committed by Alexandre Julliard
parent a67672f9ee
commit 8c609c9f50
2 changed files with 46 additions and 2 deletions

View file

@ -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,

View file

@ -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;