2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/debug.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
25 static const WCHAR EW[] = {'E',0};
26 static const WCHAR LOG2EW[] = {'L','O','G','2','E',0};
27 static const WCHAR LOG10EW[] = {'L','O','G','1','0',0};
28 static const WCHAR LN2W[] = {'L','N','2',0};
29 static const WCHAR LN10W[] = {'L','N','1','0',0};
30 static const WCHAR PIW[] = {'P','I',0};
31 static const WCHAR SQRT2W[] = {'S','Q','R','T','2',0};
32 static const WCHAR SQRT1_2W[] = {'S','Q','R','T','1','_','2',0};
33 static const WCHAR absW[] = {'a','b','s',0};
34 static const WCHAR acosW[] = {'a','c','o','s',0};
35 static const WCHAR asinW[] = {'a','s','i','n',0};
36 static const WCHAR atanW[] = {'a','t','a','n',0};
37 static const WCHAR atan2W[] = {'a','t','a','n','2',0};
38 static const WCHAR ceilW[] = {'c','e','i','l',0};
39 static const WCHAR cosW[] = {'c','o','s',0};
40 static const WCHAR expW[] = {'e','x','p',0};
41 static const WCHAR floorW[] = {'f','l','o','o','r',0};
42 static const WCHAR logW[] = {'l','o','g',0};
43 static const WCHAR maxW[] = {'m','a','x',0};
44 static const WCHAR minW[] = {'m','i','n',0};
45 static const WCHAR powW[] = {'p','o','w',0};
46 static const WCHAR randomW[] = {'r','a','n','d','o','m',0};
47 static const WCHAR roundW[] = {'r','o','u','n','d',0};
48 static const WCHAR sinW[] = {'s','i','n',0};
49 static const WCHAR sqrtW[] = {'s','q','r','t',0};
50 static const WCHAR tanW[] = {'t','a','n',0};
52 static HRESULT Math_E(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
53 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
59 static HRESULT Math_LOG2E(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
60 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
66 static HRESULT Math_LOG10E(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
67 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
73 static HRESULT Math_LN2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
74 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
80 static HRESULT Math_LN10(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
81 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
87 static HRESULT Math_PI(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
88 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
94 static HRESULT Math_SQRT2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
95 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
101 static HRESULT Math_SQRT1_2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
102 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
108 static HRESULT Math_abs(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
109 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
115 static HRESULT Math_acos(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
116 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
122 static HRESULT Math_asin(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
123 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
129 static HRESULT Math_atan(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
130 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
136 static HRESULT Math_atan2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
137 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
143 static HRESULT Math_ceil(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
144 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
150 static HRESULT Math_cos(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
151 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
157 static HRESULT Math_exp(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
158 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
164 static HRESULT Math_floor(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
165 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
171 static HRESULT Math_log(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
172 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
178 static HRESULT Math_max(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
179 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
185 static HRESULT Math_min(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
186 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
192 static HRESULT Math_pow(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
193 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
199 static HRESULT Math_random(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
200 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
206 static HRESULT Math_round(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
207 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
213 static HRESULT Math_sin(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
214 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
220 static HRESULT Math_sqrt(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
221 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
227 static HRESULT Math_tan(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
228 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
234 static const builtin_prop_t Math_props[] = {
236 {LOG2EW, Math_LOG2E, 0},
237 {LOG10EW, Math_LOG10E, 0},
239 {LN10W, Math_LN10, 0},
241 {SQRT1_2W, Math_SQRT1_2, 0},
242 {SQRT2W, Math_SQRT2, 0},
243 {absW, Math_abs, PROPF_METHOD},
244 {acosW, Math_acos, PROPF_METHOD},
245 {asinW, Math_asin, PROPF_METHOD},
246 {atanW, Math_atan, PROPF_METHOD},
247 {atan2W, Math_atan2, PROPF_METHOD},
248 {ceilW, Math_ceil, PROPF_METHOD},
249 {cosW, Math_cos, PROPF_METHOD},
250 {expW, Math_exp, PROPF_METHOD},
251 {floorW, Math_floor, PROPF_METHOD},
252 {logW, Math_log, PROPF_METHOD},
253 {maxW, Math_max, PROPF_METHOD},
254 {minW, Math_min, PROPF_METHOD},
255 {powW, Math_pow, PROPF_METHOD},
256 {randomW, Math_random, PROPF_METHOD},
257 {roundW, Math_round, PROPF_METHOD},
258 {sinW, Math_sin, PROPF_METHOD},
259 {sqrtW, Math_sqrt, PROPF_METHOD},
260 {tanW, Math_tan, PROPF_METHOD}
263 static const builtin_info_t Math_info = {
266 sizeof(Math_props)/sizeof(*Math_props),
272 HRESULT create_math(script_ctx_t *ctx, DispatchEx **ret)
274 return create_dispex(ctx, &Math_info, NULL, ret);