Module: wine Branch: master Commit: c4fe1b2efdb10c04a2a0fa984b42d7aa3e979880 URL: http://source.winehq.org/git/wine.git/?a=commit;h=c4fe1b2efdb10c04a2a0fa984b...
Author: Jacek Caban jacek@codeweavers.com Date: Sun Sep 21 15:46:22 2008 +0200
jscript: Added Math.pow implementation.
---
dlls/jscript/math.c | 24 ++++++++++++++++++++++-- dlls/jscript/tests/api.js | 9 +++++++++ 2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/dlls/jscript/math.c b/dlls/jscript/math.c index dc6f365..8803f7c 100644 --- a/dlls/jscript/math.c +++ b/dlls/jscript/math.c @@ -272,11 +272,31 @@ static HRESULT Math_min(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *d return S_OK; }
+/* ECMA-262 3rd Edition 15.8.2.13 */ static HRESULT Math_pow(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) { - FIXME("\n"); - return E_NOTIMPL; + VARIANT x, y; + HRESULT hres; + + TRACE("\n"); + + if(arg_cnt(dp) < 2) { + FIXME("unimplemented arg_cnt %d\n", arg_cnt(dp)); + return E_NOTIMPL; + } + + hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &x); + if(FAILED(hres)) + return hres; + + hres = to_number(dispex->ctx, get_arg(dp, 1), ei, &y); + if(FAILED(hres)) + return hres; + + if(retv) + num_set_val(retv, pow(num_val(&x), num_val(&y))); + return S_OK; }
static HRESULT Math_random(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index 85bca45..7796623 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -291,4 +291,13 @@ ok(tmp === 1, "Math.abs(true) = " + tmp); tmp = Math.abs(-3, 2); ok(tmp === 3, "Math.abs(-3, 2) = " + tmp);
+tmp = Math.pow(2, 2); +ok(tmp === 4, "Math.pow(2, 2) = " + tmp); + +tmp = Math.pow(4, 0.5); +ok(tmp === 2, "Math.pow(2, 2) = " + tmp); + +tmp = Math.pow(2, 2, 3); +ok(tmp === 4, "Math.pow(2, 2, 3) = " + tmp); + reportSuccess();