jscript: Added to_string(VT_I4) implementation.
[wine] / dlls / jscript / math.c
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "jscript.h"
20
21 #include "wine/debug.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
24
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};
51
52 static HRESULT Math_E(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
53         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
54 {
55     FIXME("\n");
56     return E_NOTIMPL;
57 }
58
59 static HRESULT Math_LOG2E(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
60         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
61 {
62     FIXME("\n");
63     return E_NOTIMPL;
64 }
65
66 static HRESULT Math_LOG10E(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
67         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
68 {
69     FIXME("\n");
70     return E_NOTIMPL;
71 }
72
73 static HRESULT Math_LN2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
74         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
75 {
76     FIXME("\n");
77     return E_NOTIMPL;
78 }
79
80 static HRESULT Math_LN10(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
81         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
82 {
83     FIXME("\n");
84     return E_NOTIMPL;
85 }
86
87 static HRESULT Math_PI(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
88         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
89 {
90     FIXME("\n");
91     return E_NOTIMPL;
92 }
93
94 static HRESULT Math_SQRT2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
95         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
96 {
97     FIXME("\n");
98     return E_NOTIMPL;
99 }
100
101 static HRESULT Math_SQRT1_2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
102         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
103 {
104     FIXME("\n");
105     return E_NOTIMPL;
106 }
107
108 static HRESULT Math_abs(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
109         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
110 {
111     FIXME("\n");
112     return E_NOTIMPL;
113 }
114
115 static HRESULT Math_acos(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
116         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
117 {
118     FIXME("\n");
119     return E_NOTIMPL;
120 }
121
122 static HRESULT Math_asin(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
123         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
124 {
125     FIXME("\n");
126     return E_NOTIMPL;
127 }
128
129 static HRESULT Math_atan(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
130         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
131 {
132     FIXME("\n");
133     return E_NOTIMPL;
134 }
135
136 static HRESULT Math_atan2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
137         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
138 {
139     FIXME("\n");
140     return E_NOTIMPL;
141 }
142
143 static HRESULT Math_ceil(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
144         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
145 {
146     FIXME("\n");
147     return E_NOTIMPL;
148 }
149
150 static HRESULT Math_cos(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
151         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
152 {
153     FIXME("\n");
154     return E_NOTIMPL;
155 }
156
157 static HRESULT Math_exp(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
158         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
159 {
160     FIXME("\n");
161     return E_NOTIMPL;
162 }
163
164 static HRESULT Math_floor(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
165         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
166 {
167     FIXME("\n");
168     return E_NOTIMPL;
169 }
170
171 static HRESULT Math_log(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
172         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
173 {
174     FIXME("\n");
175     return E_NOTIMPL;
176 }
177
178 static HRESULT Math_max(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
179         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
180 {
181     FIXME("\n");
182     return E_NOTIMPL;
183 }
184
185 static HRESULT Math_min(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
186         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
187 {
188     FIXME("\n");
189     return E_NOTIMPL;
190 }
191
192 static HRESULT Math_pow(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
193         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
194 {
195     FIXME("\n");
196     return E_NOTIMPL;
197 }
198
199 static HRESULT Math_random(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
200         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
201 {
202     FIXME("\n");
203     return E_NOTIMPL;
204 }
205
206 static HRESULT Math_round(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
207         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
208 {
209     FIXME("\n");
210     return E_NOTIMPL;
211 }
212
213 static HRESULT Math_sin(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
214         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
215 {
216     FIXME("\n");
217     return E_NOTIMPL;
218 }
219
220 static HRESULT Math_sqrt(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
221         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
222 {
223     FIXME("\n");
224     return E_NOTIMPL;
225 }
226
227 static HRESULT Math_tan(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
228         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
229 {
230     FIXME("\n");
231     return E_NOTIMPL;
232 }
233
234 static const builtin_prop_t Math_props[] = {
235     {EW,        Math_E,        0},
236     {LOG2EW,    Math_LOG2E,    0},
237     {LOG10EW,   Math_LOG10E,   0},
238     {LN2W,      Math_LN2,      0},
239     {LN10W,     Math_LN10,     0},
240     {PIW,       Math_PI,       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}
261 };
262
263 static const builtin_info_t Math_info = {
264     JSCLASS_MATH,
265     {NULL, NULL, 0},
266     sizeof(Math_props)/sizeof(*Math_props),
267     Math_props,
268     NULL,
269     NULL
270 };
271
272 HRESULT create_math(script_ctx_t *ctx, DispatchEx **ret)
273 {
274     return create_dispex(ctx, &Math_info, NULL, ret);
275 }