ReactOS 0.4.17-dev-357-ga8f14ff
number.c
Go to the documentation of this file.
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#ifdef __REACTOS__
20#include <wine/config.h>
21#include <wine/port.h>
22#endif
23
24#include <math.h>
25#include <locale.h>
26#include <assert.h>
27
28#include "jscript.h"
29
30#include "wine/debug.h"
31
33
34typedef struct {
36
37 double value;
39
40#define NUMBER_TOSTRING_BUF_SIZE 64
41#define NUMBER_DTOA_SIZE 18
42
44{
45 return CONTAINING_RECORD(jsdisp, NumberInstance, dispex);
46}
47
48static inline HRESULT numberval_this(jsval_t vthis, DOUBLE *ret)
49{
50 jsdisp_t *jsdisp;
51 if(is_number(vthis))
52 *ret = get_number(vthis);
53 else if(is_object_instance(vthis) && (jsdisp = to_jsdisp(get_object(vthis))) && is_class(jsdisp, JSCLASS_NUMBER))
54 *ret = number_from_jsdisp(jsdisp)->value;
55 else
57 return S_OK;
58}
59
60static inline void number_to_str(double d, WCHAR *buf, int size, int *dec_point)
61{
63 int i;
64
65 /* TODO: this function should print doubles with bigger precision */
67
68 if(d == 0)
69 *dec_point = 0;
70 else
71 *dec_point = floor(log10(d));
72 l = d*pow(10, size-*dec_point-1);
73
74 if(l%10 >= 5)
75 l = l/10+1;
76 else
77 l /= 10;
78
79 buf[size-1] = 0;
80 for(i=size-2; i>=0; i--) {
81 buf[i] = '0'+l%10;
82 l /= 10;
83 }
84
85 /* log10 was wrong by 1 or rounding changed number of digits */
86 if(l) {
87 (*dec_point)++;
88 memmove(buf+1, buf, size-2);
89 buf[0] = '0'+l;
90 }else if(buf[0]=='0' && buf[1]>='1' && buf[1]<='9') {
91 (*dec_point)--;
92 memmove(buf, buf+1, size-2);
93 buf[size-2] = '0';
94 }
95}
96
97static inline jsstr_t *number_to_fixed(double val, int prec)
98{
100 int dec_point, size, buf_size, buf_pos;
101 BOOL neg = FALSE;
102 jsstr_t *ret;
103 WCHAR *str;
104
105 TRACE("%lf %d\n", val, prec);
106
107 if(val < 0) {
108 neg = TRUE;
109 val = -val;
110 }
111
112 if(val >= 1)
113 buf_size = log10(val)+prec+2;
114 else
115 buf_size = prec ? prec+1 : 2;
116 if(buf_size > NUMBER_DTOA_SIZE)
117 buf_size = NUMBER_DTOA_SIZE;
118
119 number_to_str(val, buf, buf_size, &dec_point);
120 dec_point++;
121 size = 0;
122 if(neg)
123 size++;
124 if(dec_point > 0)
125 size += dec_point;
126 else
127 size++;
128 if(prec)
129 size += prec+1;
130
132 if(!ret)
133 return NULL;
134
135 size = buf_pos = 0;
136 if(neg)
137 str[size++] = '-';
138 if(dec_point > 0) {
139 for(;buf_pos<buf_size-1 && dec_point; dec_point--)
140 str[size++] = buf[buf_pos++];
141 }else {
142 str[size++] = '0';
143 }
144 for(; dec_point>0; dec_point--)
145 str[size++] = '0';
146 if(prec) {
147 str[size++] = '.';
148
149 for(; dec_point<0 && prec; dec_point++, prec--)
150 str[size++] = '0';
151 for(; buf_pos<buf_size-1 && prec; prec--)
152 str[size++] = buf[buf_pos++];
153 for(; prec; prec--) {
154 str[size++] = '0';
155 }
156 }
157 str[size++] = 0;
158 return ret;
159}
160
161static inline jsstr_t *number_to_exponential(double val, int prec)
162{
164 int dec_point, size, buf_size, exp_size = 1;
165 BOOL neg = FALSE;
166 jsstr_t *ret;
167 WCHAR *str;
168
169 if(val < 0) {
170 neg = TRUE;
171 val = -val;
172 }
173
174 buf_size = prec+2;
175 if(buf_size<2 || buf_size>NUMBER_DTOA_SIZE)
176 buf_size = NUMBER_DTOA_SIZE;
177 number_to_str(val, buf, buf_size, &dec_point);
178 buf_size--;
179 if(prec == -1)
180 for(; buf_size>1 && buf[buf_size-1]=='0'; buf_size--)
181 buf[buf_size-1] = 0;
182
183 size = 10;
184 while(dec_point>=size || dec_point<=-size) {
185 size *= 10;
186 exp_size++;
187 }
188
189 if(buf_size == 1)
190 size = buf_size+2+exp_size; /* 2 = strlen(e+) */
191 else if(prec == -1)
192 size = buf_size+3+exp_size; /* 3 = strlen(.e+) */
193 else
194 size = prec+4+exp_size; /* 4 = strlen(0.e+) */
195 if(neg)
196 size++;
197
199 if(!ret)
200 return NULL;
201
202 size = 0;
203 pbuf = buf;
204 if(neg)
205 str[size++] = '-';
206 str[size++] = *pbuf++;
207 if(buf_size != 1) {
208 str[size++] = '.';
209 while(*pbuf)
210 str[size++] = *pbuf++;
211 for(; prec>buf_size-1; prec--)
212 str[size++] = '0';
213 }
214 str[size++] = 'e';
215 if(dec_point >= 0) {
216 str[size++] = '+';
217 }else {
218 str[size++] = '-';
219 dec_point = -dec_point;
220 }
221 size += exp_size;
222 do {
223 str[--size] = '0'+dec_point%10;
224 dec_point /= 10;
225 }while(dec_point>0);
226 size += exp_size;
227 str[size] = 0;
228
229 return ret;
230}
231
232/* ECMA-262 3rd Edition 15.7.4.2 */
234 jsval_t *r)
235{
236 INT radix = 10;
237 DOUBLE val;
238 jsstr_t *str;
240
241 TRACE("\n");
242
243 hres = numberval_this(vthis, &val);
244 if(FAILED(hres))
245 return hres;
246
247 if(argc && (ctx->version < SCRIPTLANGUAGEVERSION_ES5 || !is_undefined(argv[0]))) {
248 hres = to_int32(ctx, argv[0], &radix);
249 if(FAILED(hres))
250 return hres;
251
252 if(radix < 2 || radix > 36)
253 return JS_E_INVALIDARG;
254 }
255
256 if(radix==10 || !isfinite(val)) {
258 if(FAILED(hres))
259 return hres;
260 }else {
261 INT idx = 0;
262 DOUBLE integ, frac, log_radix = 0;
264 BOOL exp = FALSE;
265
266 if(val<0) {
267 val = -val;
268 buf[idx++] = '-';
269 }
270
271 while(1) {
272 integ = floor(val);
273 frac = val-integ;
274
275 if(integ == 0)
276 buf[idx++] = '0';
277 while(integ>=1 && idx<NUMBER_TOSTRING_BUF_SIZE) {
278 buf[idx] = fmod(integ, radix);
279 if(buf[idx]<10) buf[idx] += '0';
280 else buf[idx] += 'a'-10;
281 integ /= radix;
282 idx++;
283 }
284
286 INT beg = buf[0]=='-'?1:0;
287 INT end = idx-1;
288 WCHAR wch;
289
290 while(end > beg) {
291 wch = buf[beg];
292 buf[beg++] = buf[end];
293 buf[end--] = wch;
294 }
295 }
296
297 if(idx != NUMBER_TOSTRING_BUF_SIZE) buf[idx++] = '.';
298
299 while(frac>0 && idx<NUMBER_TOSTRING_BUF_SIZE) {
300 frac *= radix;
301 buf[idx] = fmod(frac, radix);
302 frac -= buf[idx];
303 if(buf[idx]<10) buf[idx] += '0';
304 else buf[idx] += 'a'-10;
305 idx++;
306 }
307
309 exp = TRUE;
310 idx = (buf[0]=='-') ? 1 : 0;
311 log_radix = floor(log(val)/log(radix));
312 val *= pow(radix, -log_radix);
313 continue;
314 }
315
316 break;
317 }
318
319 while(buf[idx-1] == '0') idx--;
320 if(buf[idx-1] == '.') idx--;
321
322 if(exp) {
323 if(log_radix==0)
324 buf[idx] = 0;
325 else {
326 WCHAR ch;
327
328 if(log_radix<0) {
329 log_radix = -log_radix;
330 ch = '-';
331 }
332 else ch = '+';
333 swprintf(&buf[idx], ARRAY_SIZE(buf) - idx, L"(e%c%d)", ch, (int)log_radix);
334 }
335 }
336 else buf[idx] = '\0';
337
339 if(!str)
340 return E_OUTOFMEMORY;
341 }
342
343 if(r)
344 *r = jsval_string(str);
345 else
347 return S_OK;
348}
349
351{
352 WCHAR buf[316], decimal[8], thousands[8], *numstr;
353 NUMBERFMTW *format = NULL, format_buf;
354 LCID lcid = ctx->lcid;
355#ifndef __REACTOS__
357#endif
358 unsigned convlen;
359 jsstr_t *str;
360 int len;
361
362 /* FIXME: Localize this */
363 if(!isfinite(val))
364 return to_string(ctx, jsval_number(val), ret);
365
366 /* Native never uses an exponent, even if the number is very large, it will in fact
367 return all the digits (with thousands separators). jscript.dll uses two digits for
368 fraction even if they are zero (likely default numDigits) and always returns them,
369 while mshtml's jscript uses 3 digits and trims trailing zeros (on same locale).
370 This is even for very small numbers, such as 0.0000999, which will simply be 0. */
371#ifdef __REACTOS__ /* FIXME: Inspect */
372 len = swprintf(buf, ARRAY_SIZE(buf), L"%.3f", val);
373#else
374 if(!(locale = _create_locale(LC_ALL, "C")))
375 return E_OUTOFMEMORY;
376 len = _swprintf_l(buf, ARRAY_SIZE(buf), L"%.3f", locale, val);
378#endif
379
380 if(new_format) {
381 WCHAR grouping[10];
382
383 format = &format_buf;
384 format->NumDigits = 3;
385 while(buf[--len] == '0')
386 format->NumDigits--;
387
388 /* same logic as VarFormatNumber */
389 grouping[2] = '\0';
390 if(!GetLocaleInfoW(lcid, LOCALE_SGROUPING, grouping, ARRAY_SIZE(grouping)))
391 format->Grouping = 3;
392 else
393 format->Grouping = (grouping[2] == '2' ? 32 : grouping[0] - '0');
394
395 if(!GetLocaleInfoW(lcid, LOCALE_ILZERO | LOCALE_RETURN_NUMBER, (WCHAR*)&format->LeadingZero, 2))
396 format->LeadingZero = 0;
397 if(!GetLocaleInfoW(lcid, LOCALE_INEGNUMBER | LOCALE_RETURN_NUMBER, (WCHAR*)&format->NegativeOrder, 2))
398 format->NegativeOrder = 1;
399 format->lpDecimalSep = decimal;
400 if(!GetLocaleInfoW(lcid, LOCALE_SDECIMAL, decimal, ARRAY_SIZE(decimal)))
401 wcscpy(decimal, L".");
402 format->lpThousandSep = thousands;
403 if(!GetLocaleInfoW(lcid, LOCALE_STHOUSAND, thousands, ARRAY_SIZE(thousands)))
404 wcscpy(thousands, L",");
405 }
406
407 if(!(convlen = GetNumberFormatW(lcid, 0, buf, format, NULL, 0)) ||
408 !(str = jsstr_alloc_buf(convlen - 1, &numstr)))
409 return E_OUTOFMEMORY;
410
411 if(!GetNumberFormatW(lcid, 0, buf, format, numstr, convlen)) {
413 return E_OUTOFMEMORY;
414 }
415
416 *ret = str;
417 return S_OK;
418}
419
421 jsval_t *r)
422{
423 jsstr_t *str;
425 DOUBLE val;
426
427 TRACE("\n");
428
429 hres = numberval_this(vthis, &val);
430 if(FAILED(hres)) {
432 return throw_error(ctx, JS_E_WRONG_THIS, L"Number");
433 return hres;
434 }
435
436 if(r) {
438 if(FAILED(hres))
439 return hres;
440 *r = jsval_string(str);
441 }
442 return S_OK;
443}
444
446 jsval_t *r)
447{
448 DOUBLE val;
449 INT prec = 0;
450 jsstr_t *str;
452
453 TRACE("\n");
454
455 hres = numberval_this(vthis, &val);
456 if(FAILED(hres))
457 return hres;
458
459 if(argc) {
460 hres = to_int32(ctx, argv[0], &prec);
461 if(FAILED(hres))
462 return hres;
463
464 if(prec < 0 || prec > 20)
466 }
467
468 if(!isfinite(val)) {
470 if(FAILED(hres))
471 return hres;
472 }else {
473 str = number_to_fixed(val, prec);
474 if(!str)
475 return E_OUTOFMEMORY;
476 }
477
478 if(r)
479 *r = jsval_string(str);
480 else
482 return S_OK;
483}
484
486 jsval_t *r)
487{
488 DOUBLE val;
489 INT prec = 0;
490 jsstr_t *str;
492
493 TRACE("\n");
494
495 hres = numberval_this(vthis, &val);
496 if(FAILED(hres))
497 return hres;
498
499 if(argc) {
500 hres = to_int32(ctx, argv[0], &prec);
501 if(FAILED(hres))
502 return hres;
503
504 if(prec < 0 || prec > 20)
506 }
507
508 if(!isfinite(val)) {
510 if(FAILED(hres))
511 return hres;
512 }else {
513 if(!prec)
514 prec--;
516 if(!str)
517 return E_OUTOFMEMORY;
518 }
519
520 if(r)
521 *r = jsval_string(str);
522 else
524 return S_OK;
525}
526
528 jsval_t *r)
529{
530 INT prec = 0, size;
531 jsstr_t *str;
532 DOUBLE val;
534
535 hres = numberval_this(vthis, &val);
536 if(FAILED(hres))
537 return hres;
538
539 if(argc && (ctx->version < 2 || !is_undefined(argv[0]))) {
540 hres = to_int32(ctx, argv[0], &prec);
541 if(FAILED(hres))
542 return hres;
543
544 if(prec<1 || prec>21)
546 }
547
548 if(!isfinite(val) || !prec) {
550 if(FAILED(hres))
551 return hres;
552 }else {
553 if(val != 0)
554 size = floor(log10(val>0 ? val : -val)) + 1;
555 else
556 size = 1;
557
558 if(size > prec)
559 str = number_to_exponential(val, prec-1);
560 else
561 str = number_to_fixed(val, prec-size);
562 if(!str)
563 return E_OUTOFMEMORY;
564 }
565
566 if(r)
567 *r = jsval_string(str);
568 else
570 return S_OK;
571}
572
574 jsval_t *r)
575{
577 DOUBLE val;
578
579 TRACE("\n");
580
581 hres = numberval_this(vthis, &val);
582 if(FAILED(hres))
583 return hres;
584
585 if(r)
586 *r = jsval_number(val);
587 return S_OK;
588}
589
590static const builtin_prop_t Number_props[] = {
591 {L"toExponential", Number_toExponential, PROPF_METHOD|1},
592 {L"toFixed", Number_toFixed, PROPF_METHOD},
593 {L"toLocaleString", Number_toLocaleString, PROPF_METHOD},
594 {L"toPrecision", Number_toPrecision, PROPF_METHOD|1},
595 {L"toString", Number_toString, PROPF_METHOD|1},
596 {L"valueOf", Number_valueOf, PROPF_METHOD}
597};
598
601 .props_cnt = ARRAY_SIZE(Number_props),
602 .props = Number_props,
603};
604
607};
608
610 jsval_t *r)
611{
612 double n;
614
615 TRACE("\n");
616
617 switch(flags) {
618 case INVOKE_FUNC:
619 if(!argc) {
620 if(r)
621 *r = jsval_number(0);
622 return S_OK;
623 }
624
625 hres = to_number(ctx, argv[0], &n);
626 if(FAILED(hres))
627 return hres;
628
629 if(r)
630 *r = jsval_number(n);
631 break;
632
633 case DISPATCH_CONSTRUCT: {
634 jsdisp_t *obj;
635
636 if(argc) {
637 hres = to_number(ctx, argv[0], &n);
638 if(FAILED(hres))
639 return hres;
640 }else {
641 n = 0;
642 }
643
644 if(r) {
645 hres = create_number(ctx, n, &obj);
646 if(FAILED(hres))
647 return hres;
648 *r = jsval_obj(obj);
649 }
650 break;
651 }
652 default:
653 FIXME("unimplemented flags %x\n", flags);
654 return E_NOTIMPL;
655 }
656
657 return S_OK;
658}
659
661{
664
665 number = calloc(1, sizeof(NumberInstance));
666 if(!number)
667 return E_OUTOFMEMORY;
668
669 if(object_prototype)
670 hres = init_dispex(&number->dispex, ctx, &Number_info, object_prototype);
671 else
672 hres = init_dispex_from_constr(&number->dispex, ctx, &NumberInst_info, ctx->number_constr);
673 if(FAILED(hres)) {
674 free(number);
675 return hres;
676 }
677
678 *ret = number;
679 return S_OK;
680}
681
683{
686
687 hres = alloc_number(ctx, object_prototype, &number);
688 if(FAILED(hres))
689 return hres;
690
691 number->value = 0;
693 PROPF_CONSTR|1, &number->dispex, ret);
694
695 jsdisp_release(&number->dispex);
696 return hres;
697}
698
700{
703
705 if(FAILED(hres))
706 return hres;
707
708 number->value = value;
709
710 *ret = &number->dispex;
711 return S_OK;
712}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ARRAY_SIZE(A)
Definition: main.h:20
#define FIXME(fmt,...)
Definition: precomp.h:53
r l[0]
Definition: byte_order.h:168
Definition: _locale.h:75
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_NOTIMPL
Definition: ddrawi.h:99
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int idx
Definition: utils.c:41
#define frac(x)
Definition: texture.c:364
HRESULT throw_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
Definition: error.c:398
HRESULT create_builtin_constructor(script_ctx_t *ctx, builtin_invoke_t value_proc, const WCHAR *name, const builtin_info_t *builtin_info, DWORD flags, jsdisp_t *prototype, jsdisp_t **ret)
Definition: function.c:809
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1675
LCID lcid
Definition: locale.c:5660
MonoAssembly int argc
Definition: metahost.c:107
unsigned char ch[4][2]
Definition: console.c:118
#define assert(_expr)
Definition: assert.h:32
_ACRTIMP void __cdecl _free_locale(_locale_t)
Definition: locale.c:1183
_ACRTIMP _locale_t __cdecl _create_locale(int, const char *)
Definition: locale.c:1981
#define LC_ALL
Definition: locale.h:25
#define isfinite(x)
Definition: math.h:363
_ACRTIMP double __cdecl fmod(double, double)
_ACRTIMP double __cdecl floor(double)
Definition: floor.c:18
#define swprintf
Definition: precomp.h:40
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned int BOOL
Definition: ntddk_ex.h:94
double log10(double x)
Definition: freeldr.c:191
double pow(double x, double y)
Definition: freeldr.c:179
GLuint GLuint end
Definition: gl.h:1545
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble n
Definition: glext.h:7729
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLuint GLfloat * val
Definition: glext.h:7180
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static HRESULT to_string(VARIANT *src, BSTR *dst)
Definition: host.c:46
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
HRESULT init_dispex_from_constr(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *constr)
Definition: dispex.c:2512
ULONG jsdisp_release(jsdisp_t *obj)
Definition: dispex.c:1911
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype)
Definition: dispex.c:2454
jsdisp_t * to_jsdisp(IDispatch *disp)
Definition: dispex.c:2447
#define JS_E_PRECISION_OUT_OF_RANGE
Definition: jscript.h:570
#define SCRIPTLANGUAGEVERSION_ES5
Definition: jscript.h:53
#define JS_E_NUMBER_EXPECTED
Definition: jscript.h:554
HRESULT to_number(script_ctx_t *, jsval_t, double *)
Definition: jsutils.c:630
HRESULT to_int32(script_ctx_t *, jsval_t, INT *)
Definition: jsutils.c:735
@ JSCLASS_NUMBER
Definition: jscript.h:112
#define JS_E_WRONG_THIS
Definition: jscript.h:582
#define JS_E_INVALIDARG
Definition: jscript.h:527
#define JS_E_FRACTION_DIGITS_OUT_OF_RANGE
Definition: jscript.h:569
static BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
Definition: jscript.h:503
const unsigned int PROPF_METHOD
Definition: jsdisp.idl:33
const unsigned int PROPF_CONSTR
Definition: jsdisp.idl:34
jsstr_t * jsstr_alloc_buf(unsigned len, WCHAR **buf)
Definition: jsstr.c:69
static void jsstr_release(jsstr_t *str)
Definition: jsstr.h:107
static jsstr_t * jsstr_alloc(const WCHAR *str)
Definition: jsstr.h:100
static BOOL is_number(jsval_t v)
Definition: jsval.h:200
static jsval_t jsval_string(jsstr_t *str)
Definition: jsval.h:109
static jsval_t jsval_obj(jsdisp_t *obj)
Definition: jsval.h:125
static BOOL is_undefined(jsval_t v)
Definition: jsval.h:180
static double get_number(jsval_t v)
Definition: jsval.h:233
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:228
static BOOL is_object_instance(jsval_t v)
Definition: jsval.h:175
static jsval_t jsval_number(double n)
Definition: jsval.h:153
#define d
Definition: ke_i.h:81
INT WINAPI GetNumberFormatW(LCID lcid, DWORD dwFlags, LPCWSTR lpszValue, const NUMBERFMTW *lpFormat, LPWSTR lpNumberStr, int cchOut)
Definition: lcformat.c:1130
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static unsigned int number
Definition: dsound.c:1479
HRESULT hres
Definition: protocol.c:465
DWORD exp
Definition: msg.c:18625
#define argv
Definition: mplay32.c:18
static HRESULT Number_toString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:233
static HRESULT Number_toFixed(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:445
HRESULT localize_number(script_ctx_t *ctx, DOUBLE val, BOOL new_format, jsstr_t **ret)
Definition: number.c:350
static HRESULT Number_valueOf(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:573
HRESULT create_number_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
Definition: number.c:682
static const builtin_info_t NumberInst_info
Definition: number.c:605
static HRESULT numberval_this(jsval_t vthis, DOUBLE *ret)
Definition: number.c:48
static HRESULT Number_toExponential(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:485
static const builtin_info_t Number_info
Definition: number.c:599
static HRESULT NumberConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:609
HRESULT create_number(script_ctx_t *ctx, double value, jsdisp_t **ret)
Definition: number.c:699
static HRESULT alloc_number(script_ctx_t *ctx, jsdisp_t *object_prototype, NumberInstance **ret)
Definition: number.c:660
static NumberInstance * number_from_jsdisp(jsdisp_t *jsdisp)
Definition: number.c:43
#define NUMBER_DTOA_SIZE
Definition: number.c:41
static HRESULT Number_toLocaleString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:420
#define NUMBER_TOSTRING_BUF_SIZE
Definition: number.c:40
static jsstr_t * number_to_exponential(double val, int prec)
Definition: number.c:161
static HRESULT Number_toPrecision(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:527
static jsstr_t * number_to_fixed(double val, int prec)
Definition: number.c:97
static void number_to_str(double d, WCHAR *buf, int size, int *dec_point)
Definition: number.c:60
static const builtin_prop_t Number_props[]
Definition: number.c:590
short WCHAR
Definition: pedump.c:58
#define calloc
Definition: rosglue.h:14
const WCHAR * str
DWORD LCID
Definition: nls.h:13
wcscpy
#define log(outFile, fmt,...)
Definition: util.h:15
#define TRACE(s)
Definition: solgame.cpp:4
jsdisp_t dispex
Definition: number.c:35
double value
Definition: number.c:37
Definition: jsstr.h:36
Definition: jsval.h:54
jsclass_t class
Definition: jscript.h:183
Definition: format.c:58
Definition: pbuf.h:186
int32_t INT
Definition: typedefs.h:58
uint64_t ULONGLONG
Definition: typedefs.h:67
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
double DOUBLE
Definition: typedefs.h:70
Definition: pdh_main.c:96
#define LOCALE_SGROUPING
Definition: winnls.h:54
#define LOCALE_SDECIMAL
Definition: winnls.h:52
#define LOCALE_STHOUSAND
Definition: winnls.h:53
#define LOCALE_INEGNUMBER
Definition: winnls.h:57
#define LOCALE_ILZERO
Definition: winnls.h:56
size_t const unsigned const radix
Definition: xtoa.cpp:37