diff --git a/dlls/jscript/math.c b/dlls/jscript/math.c index 9804c36603b..2928a97c56b 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 a5d9286a886..54fc2a15823 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;