ReactOS 0.4.16-dev-334-g4d9f67c
number.c File Reference
#include <math.h>
#include <assert.h>
#include "jscript.h"
#include "wine/debug.h"
Include dependency graph for number.c:

Go to the source code of this file.

Classes

struct  NumberInstance
 

Macros

#define NUMBER_TOSTRING_BUF_SIZE   64
 
#define NUMBER_DTOA_SIZE   18
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (jscript)
 
static NumberInstancenumber_from_jsdisp (jsdisp_t *jsdisp)
 
static NumberInstancenumber_from_vdisp (vdisp_t *vdisp)
 
static NumberInstancenumber_this (vdisp_t *jsthis)
 
static void number_to_str (double d, WCHAR *buf, int size, int *dec_point)
 
static jsstr_tnumber_to_fixed (double val, int prec)
 
static jsstr_tnumber_to_exponential (double val, int prec)
 
static HRESULT Number_toString (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Number_toLocaleString (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Number_toFixed (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Number_toExponential (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Number_toPrecision (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Number_valueOf (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT Number_get_value (script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
 
static HRESULT NumberConstr_value (script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
 
static HRESULT alloc_number (script_ctx_t *ctx, jsdisp_t *object_prototype, NumberInstance **ret)
 
HRESULT create_number_constr (script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
 
HRESULT create_number (script_ctx_t *ctx, double value, jsdisp_t **ret)
 

Variables

static const WCHAR toStringW [] = {'t','o','S','t','r','i','n','g',0}
 
static const WCHAR toLocaleStringW [] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0}
 
static const WCHAR toFixedW [] = {'t','o','F','i','x','e','d',0}
 
static const WCHAR toExponentialW [] = {'t','o','E','x','p','o','n','e','n','t','i','a','l',0}
 
static const WCHAR toPrecisionW [] = {'t','o','P','r','e','c','i','s','i','o','n',0}
 
static const WCHAR valueOfW [] = {'v','a','l','u','e','O','f',0}
 
static const builtin_prop_t Number_props []
 
static const builtin_info_t Number_info
 
static const builtin_info_t NumberInst_info
 

Macro Definition Documentation

◆ NUMBER_DTOA_SIZE

#define NUMBER_DTOA_SIZE   18

Definition at line 42 of file number.c.

◆ NUMBER_TOSTRING_BUF_SIZE

#define NUMBER_TOSTRING_BUF_SIZE   64

Definition at line 41 of file number.c.

Function Documentation

◆ alloc_number()

static HRESULT alloc_number ( script_ctx_t ctx,
jsdisp_t object_prototype,
NumberInstance **  ret 
)
static

Definition at line 591 of file number.c.

592{
595
596 number = heap_alloc_zero(sizeof(NumberInstance));
597 if(!number)
598 return E_OUTOFMEMORY;
599
600 if(object_prototype)
601 hres = init_dispex(&number->dispex, ctx, &Number_info, object_prototype);
602 else
603 hres = init_dispex_from_constr(&number->dispex, ctx, &NumberInst_info, ctx->number_constr);
604 if(FAILED(hres)) {
606 return hres;
607 }
608
609 *ret = number;
610 return S_OK;
611}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#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:1030
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype)
Definition: dispex.c:919
static unsigned int number
Definition: dsound.c:1479
HRESULT hres
Definition: protocol.c:465
static const builtin_info_t NumberInst_info
Definition: number.c:533
static const builtin_info_t Number_info
Definition: number.c:524
int ret

Referenced by create_number(), and create_number_constr().

◆ create_number()

HRESULT create_number ( script_ctx_t ctx,
double  value,
jsdisp_t **  ret 
)

Definition at line 632 of file number.c.

633{
636
638 if(FAILED(hres))
639 return hres;
640
641 number->value = value;
642
643 *ret = &number->dispex;
644 return S_OK;
645}
#define NULL
Definition: types.h:112
static HRESULT alloc_number(script_ctx_t *ctx, jsdisp_t *object_prototype, NumberInstance **ret)
Definition: number.c:591
Definition: pdh_main.c:94

Referenced by NumberConstr_value(), and to_object().

◆ create_number_constr()

HRESULT create_number_constr ( script_ctx_t ctx,
jsdisp_t object_prototype,
jsdisp_t **  ret 
)

Definition at line 613 of file number.c.

614{
617
618 static const WCHAR NumberW[] = {'N','u','m','b','e','r',0};
619
620 hres = alloc_number(ctx, object_prototype, &number);
621 if(FAILED(hres))
622 return hres;
623
624 number->value = 0;
626 PROPF_CONSTR|1, &number->dispex, ret);
627
628 jsdisp_release(&number->dispex);
629 return hres;
630}
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:686
static const WCHAR NumberW[]
Definition: global.c:47
#define PROPF_CONSTR
Definition: jscript.h:98
static void jsdisp_release(jsdisp_t *jsdisp)
Definition: jscript.h:268
static HRESULT NumberConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:541
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by init_constructors().

◆ number_from_jsdisp()

static NumberInstance * number_from_jsdisp ( jsdisp_t jsdisp)
inlinestatic

Definition at line 44 of file number.c.

45{
46 return CONTAINING_RECORD(jsdisp, NumberInstance, dispex);
47}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by number_from_vdisp(), and Number_get_value().

◆ number_from_vdisp()

static NumberInstance * number_from_vdisp ( vdisp_t vdisp)
inlinestatic

Definition at line 49 of file number.c.

50{
51 return number_from_jsdisp(vdisp->u.jsdisp);
52}
static NumberInstance * number_from_jsdisp(jsdisp_t *jsdisp)
Definition: number.c:44
union vdisp_t::@442 u
jsdisp_t * jsdisp
Definition: jscript.h:144

Referenced by number_this().

◆ Number_get_value()

static HRESULT Number_get_value ( script_ctx_t ctx,
jsdisp_t jsthis,
jsval_t r 
)
static

Definition at line 505 of file number.c.

506{
508
509 TRACE("(%p)\n", number);
510
511 *r = jsval_number(number->value);
512 return S_OK;
513}
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
static jsval_t jsval_number(double n)
Definition: jsval.h:144
#define TRACE(s)
Definition: solgame.cpp:4

◆ number_this()

static NumberInstance * number_this ( vdisp_t jsthis)
inlinestatic

Definition at line 54 of file number.c.

55{
56 return is_vclass(jsthis, JSCLASS_NUMBER) ? number_from_vdisp(jsthis) : NULL;
57}
static BOOL is_vclass(vdisp_t *vdisp, jsclass_t class)
Definition: jscript.h:509
@ JSCLASS_NUMBER
Definition: jscript.h:129
static NumberInstance * number_from_vdisp(vdisp_t *vdisp)
Definition: number.c:49

Referenced by Number_toExponential(), Number_toFixed(), Number_toPrecision(), Number_toString(), and Number_valueOf().

◆ number_to_exponential()

static jsstr_t * number_to_exponential ( double  val,
int  prec 
)
inlinestatic

Definition at line 160 of file number.c.

161{
163 int dec_point, size, buf_size, exp_size = 1;
164 BOOL neg = FALSE;
165 jsstr_t *ret;
166 WCHAR *str;
167
168 if(val < 0) {
169 neg = TRUE;
170 val = -val;
171 }
172
173 buf_size = prec+2;
174 if(buf_size<2 || buf_size>NUMBER_DTOA_SIZE)
175 buf_size = NUMBER_DTOA_SIZE;
176 number_to_str(val, buf, buf_size, &dec_point);
177 buf_size--;
178 if(prec == -1)
179 for(; buf_size>1 && buf[buf_size-1]=='0'; buf_size--)
180 buf[buf_size-1] = 0;
181
182 size = 10;
183 while(dec_point>=size || dec_point<=-size) {
184 size *= 10;
185 exp_size++;
186 }
187
188 if(buf_size == 1)
189 size = buf_size+2+exp_size; /* 2 = strlen(e+) */
190 else if(prec == -1)
191 size = buf_size+3+exp_size; /* 3 = strlen(.e+) */
192 else
193 size = prec+4+exp_size; /* 4 = strlen(0.e+) */
194 if(neg)
195 size++;
196
198 if(!ret)
199 return NULL;
200
201 size = 0;
202 pbuf = buf;
203 if(neg)
204 str[size++] = '-';
205 str[size++] = *pbuf++;
206 if(buf_size != 1) {
207 str[size++] = '.';
208 while(*pbuf)
209 str[size++] = *pbuf++;
210 for(; prec>buf_size-1; prec--)
211 str[size++] = '0';
212 }
213 str[size++] = 'e';
214 if(dec_point >= 0) {
215 str[size++] = '+';
216 }else {
217 str[size++] = '-';
218 dec_point = -dec_point;
219 }
220 size += exp_size;
221 do {
222 str[--size] = '0'+dec_point%10;
223 dec_point /= 10;
224 }while(dec_point>0);
225 size += exp_size;
226 str[size] = 0;
227
228 return ret;
229}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint GLfloat * val
Definition: glext.h:7180
jsstr_t * jsstr_alloc_buf(unsigned len, WCHAR **buf)
Definition: jsstr.c:69
#define NUMBER_DTOA_SIZE
Definition: number.c:42
static void number_to_str(double d, WCHAR *buf, int size, int *dec_point)
Definition: number.c:59
const WCHAR * str
Definition: jsstr.h:39
Definition: pbuf.h:186

Referenced by Number_toExponential(), and Number_toPrecision().

◆ number_to_fixed()

static jsstr_t * number_to_fixed ( double  val,
int  prec 
)
inlinestatic

Definition at line 96 of file number.c.

97{
99 int dec_point, size, buf_size, buf_pos;
100 BOOL neg = FALSE;
101 jsstr_t *ret;
102 WCHAR *str;
103
104 TRACE("%lf %d\n", val, prec);
105
106 if(val < 0) {
107 neg = TRUE;
108 val = -val;
109 }
110
111 if(val >= 1)
112 buf_size = log10(val)+prec+2;
113 else
114 buf_size = prec ? prec+1 : 2;
115 if(buf_size > NUMBER_DTOA_SIZE)
116 buf_size = NUMBER_DTOA_SIZE;
117
118 number_to_str(val, buf, buf_size, &dec_point);
119 dec_point++;
120 size = 0;
121 if(neg)
122 size++;
123 if(dec_point > 0)
124 size += dec_point;
125 else
126 size++;
127 if(prec)
128 size += prec+1;
129
131 if(!ret)
132 return NULL;
133
134 size = buf_pos = 0;
135 if(neg)
136 str[size++] = '-';
137 if(dec_point > 0) {
138 for(;buf_pos<buf_size-1 && dec_point; dec_point--)
139 str[size++] = buf[buf_pos++];
140 }else {
141 str[size++] = '0';
142 }
143 for(; dec_point>0; dec_point--)
144 str[size++] = '0';
145 if(prec) {
146 str[size++] = '.';
147
148 for(; dec_point<0 && prec; dec_point++, prec--)
149 str[size++] = '0';
150 for(; buf_pos<buf_size-1 && prec; prec--)
151 str[size++] = buf[buf_pos++];
152 for(; prec; prec--) {
153 str[size++] = '0';
154 }
155 }
156 str[size++] = 0;
157 return ret;
158}
double log10(double x)
Definition: freeldr.c:122

Referenced by Number_toFixed(), and Number_toPrecision().

◆ number_to_str()

static void number_to_str ( double  d,
WCHAR buf,
int  size,
int dec_point 
)
inlinestatic

Definition at line 59 of file number.c.

60{
62 int i;
63
64 /* TODO: this function should print doubles with bigger precision */
66
67 if(d == 0)
68 *dec_point = 0;
69 else
70 *dec_point = floor(log10(d));
71 l = d*pow(10, size-*dec_point-1);
72
73 if(l%10 >= 5)
74 l = l/10+1;
75 else
76 l /= 10;
77
78 buf[size-1] = 0;
79 for(i=size-2; i>=0; i--) {
80 buf[i] = '0'+l%10;
81 l /= 10;
82 }
83
84 /* log10 was wrong by 1 or rounding changed number of digits */
85 if(l) {
86 (*dec_point)++;
87 memmove(buf+1, buf, size-2);
88 buf[0] = '0'+l;
89 }else if(buf[0]=='0' && buf[1]>='1' && buf[1]<='9') {
90 (*dec_point)--;
91 memmove(buf, buf+1, size-2);
92 buf[size-2] = '0';
93 }
94}
r l[0]
Definition: byte_order.h:168
#define assert(x)
Definition: debug.h:53
double pow(double x, double y)
Definition: freeldr.c:110
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
_Check_return_ _CRTIMP double __cdecl floor(_In_ double x)
#define d
Definition: ke_i.h:81
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
uint64_t ULONGLONG
Definition: typedefs.h:67

Referenced by number_to_exponential(), and number_to_fixed().

◆ Number_toExponential()

static HRESULT Number_toExponential ( script_ctx_t ctx,
vdisp_t jsthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 400 of file number.c.

402{
404 DOUBLE val;
405 INT prec = 0;
406 jsstr_t *str;
408
409 TRACE("\n");
410
411 if(!(number = number_this(jsthis)))
413
414 if(argc) {
415 hres = to_int32(ctx, argv[0], &prec);
416 if(FAILED(hres))
417 return hres;
418
419 if(prec<0 || prec>20)
421 }
422
423 val = number->value;
424 if(!is_finite(val)) {
426 if(FAILED(hres))
427 return hres;
428 }else {
429 if(!prec)
430 prec--;
432 if(!str)
433 return E_OUTOFMEMORY;
434 }
435
436 if(r)
437 *r = jsval_string(str);
438 else
440 return S_OK;
441}
static int argc
Definition: ServiceArgs.c:12
HRESULT throw_type_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
Definition: error.c:440
HRESULT throw_range_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
Definition: error.c:420
static HRESULT to_string(VARIANT *src, BSTR *dst)
Definition: host.c:47
HRESULT to_int32(script_ctx_t *, jsval_t, INT *) DECLSPEC_HIDDEN
Definition: jsutils.c:665
#define JS_E_NUMBER_EXPECTED
Definition: jscript.h:554
BOOL is_finite(double) DECLSPEC_HIDDEN
Definition: jsutils.c:58
#define JS_E_FRACTION_DIGITS_OUT_OF_RANGE
Definition: jscript.h:566
static void jsstr_release(jsstr_t *str)
Definition: jsstr.h:110
static jsval_t jsval_string(jsstr_t *str)
Definition: jsval.h:109
#define argv
Definition: mplay32.c:18
static NumberInstance * number_this(vdisp_t *jsthis)
Definition: number.c:54
static jsstr_t * number_to_exponential(double val, int prec)
Definition: number.c:160
int32_t INT
Definition: typedefs.h:58
double DOUBLE
Definition: typedefs.h:70

◆ Number_toFixed()

static HRESULT Number_toFixed ( script_ctx_t ctx,
vdisp_t jsthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 359 of file number.c.

361{
363 DOUBLE val;
364 INT prec = 0;
365 jsstr_t *str;
367
368 TRACE("\n");
369
370 if(!(number = number_this(jsthis)))
372
373 if(argc) {
374 hres = to_int32(ctx, argv[0], &prec);
375 if(FAILED(hres))
376 return hres;
377
378 if(prec<0 || prec>20)
380 }
381
382 val = number->value;
383 if(!is_finite(val)) {
385 if(FAILED(hres))
386 return hres;
387 }else {
388 str = number_to_fixed(val, prec);
389 if(!str)
390 return E_OUTOFMEMORY;
391 }
392
393 if(r)
394 *r = jsval_string(str);
395 else
397 return S_OK;
398}
static jsstr_t * number_to_fixed(double val, int prec)
Definition: number.c:96

◆ Number_toLocaleString()

static HRESULT Number_toLocaleString ( script_ctx_t ctx,
vdisp_t jsthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 352 of file number.c.

354{
355 FIXME("\n");
356 return E_NOTIMPL;
357}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ Number_toPrecision()

static HRESULT Number_toPrecision ( script_ctx_t ctx,
vdisp_t jsthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 443 of file number.c.

445{
447 INT prec = 0, size;
448 jsstr_t *str;
449 DOUBLE val;
451
452 if(!(number = number_this(jsthis)))
454
455 if(argc) {
456 hres = to_int32(ctx, argv[0], &prec);
457 if(FAILED(hres))
458 return hres;
459
460 if(prec<1 || prec>21)
462 }
463
464 val = number->value;
465 if(!is_finite(val) || !prec) {
467 if(FAILED(hres))
468 return hres;
469 }else {
470 if(val != 0)
471 size = floor(log10(val>0 ? val : -val)) + 1;
472 else
473 size = 1;
474
475 if(size > prec)
476 str = number_to_exponential(val, prec-1);
477 else
478 str = number_to_fixed(val, prec-size);
479 if(!str)
480 return E_OUTOFMEMORY;
481 }
482
483 if(r)
484 *r = jsval_string(str);
485 else
487 return S_OK;
488}
#define JS_E_PRECISION_OUT_OF_RANGE
Definition: jscript.h:567

◆ Number_toString()

static HRESULT Number_toString ( script_ctx_t ctx,
vdisp_t jsthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 232 of file number.c.

234{
236 INT radix = 10;
237 DOUBLE val;
238 jsstr_t *str;
240
241 TRACE("\n");
242
243 if(!(number = number_this(jsthis)))
245
246 if(argc) {
247 hres = to_int32(ctx, argv[0], &radix);
248 if(FAILED(hres))
249 return hres;
250
251 if(radix<2 || radix>36)
253 }
254
255 val = number->value;
256
257 if(radix==10 || !is_finite(val)) {
259 if(FAILED(hres))
260 return hres;
261 }else {
262 INT idx = 0;
263 DOUBLE integ, frac, log_radix = 0;
265 BOOL exp = FALSE;
266
267 if(val<0) {
268 val = -val;
269 buf[idx++] = '-';
270 }
271
272 while(1) {
273 integ = floor(val);
274 frac = val-integ;
275
276 if(integ == 0)
277 buf[idx++] = '0';
278 while(integ>=1 && idx<NUMBER_TOSTRING_BUF_SIZE) {
279 buf[idx] = fmod(integ, radix);
280 if(buf[idx]<10) buf[idx] += '0';
281 else buf[idx] += 'a'-10;
282 integ /= radix;
283 idx++;
284 }
285
287 INT beg = buf[0]=='-'?1:0;
288 INT end = idx-1;
289 WCHAR wch;
290
291 while(end > beg) {
292 wch = buf[beg];
293 buf[beg++] = buf[end];
294 buf[end--] = wch;
295 }
296 }
297
298 if(idx != NUMBER_TOSTRING_BUF_SIZE) buf[idx++] = '.';
299
300 while(frac>0 && idx<NUMBER_TOSTRING_BUF_SIZE) {
301 frac *= radix;
302 buf[idx] = fmod(frac, radix);
303 frac -= buf[idx];
304 if(buf[idx]<10) buf[idx] += '0';
305 else buf[idx] += 'a'-10;
306 idx++;
307 }
308
310 exp = TRUE;
311 idx = (buf[0]=='-') ? 1 : 0;
312 log_radix = floor(log(val)/log(radix));
313 val *= pow(radix, -log_radix);
314 continue;
315 }
316
317 break;
318 }
319
320 while(buf[idx-1] == '0') idx--;
321 if(buf[idx-1] == '.') idx--;
322
323 if(exp) {
324 if(log_radix==0)
325 buf[idx] = 0;
326 else {
327 static const WCHAR formatW[] = {'(','e','%','c','%','d',')',0};
328 WCHAR ch;
329
330 if(log_radix<0) {
331 log_radix = -log_radix;
332 ch = '-';
333 }
334 else ch = '+';
335 swprintf(&buf[idx], formatW, ch, (int)log_radix);
336 }
337 }
338 else buf[idx] = '\0';
339
341 if(!str)
342 return E_OUTOFMEMORY;
343 }
344
345 if(r)
346 *r = jsval_string(str);
347 else
349 return S_OK;
350}
unsigned int idx
Definition: utils.c:41
#define frac(x)
Definition: texture.c:364
#define swprintf
Definition: precomp.h:40
GLuint GLuint end
Definition: gl.h:1545
_Check_return_ double __cdecl fmod(_In_ double x, _In_ double y)
#define JS_E_INVALIDARG
Definition: jscript.h:529
static jsstr_t * jsstr_alloc(const WCHAR *str)
Definition: jsstr.h:103
DWORD exp
Definition: msg.c:16058
#define NUMBER_TOSTRING_BUF_SIZE
Definition: number.c:41
#define log(outFile, fmt,...)
Definition: util.h:15

◆ Number_valueOf()

static HRESULT Number_valueOf ( script_ctx_t ctx,
vdisp_t jsthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 490 of file number.c.

492{
494
495 TRACE("\n");
496
497 if(!(number = number_this(jsthis)))
499
500 if(r)
501 *r = jsval_number(number->value);
502 return S_OK;
503}

◆ NumberConstr_value()

static HRESULT NumberConstr_value ( script_ctx_t ctx,
vdisp_t jsthis,
WORD  flags,
unsigned  argc,
jsval_t argv,
jsval_t r 
)
static

Definition at line 541 of file number.c.

543{
544 double n;
546
547 TRACE("\n");
548
549 switch(flags) {
550 case INVOKE_FUNC:
551 if(!argc) {
552 if(r)
553 *r = jsval_number(0);
554 return S_OK;
555 }
556
557 hres = to_number(ctx, argv[0], &n);
558 if(FAILED(hres))
559 return hres;
560
561 if(r)
562 *r = jsval_number(n);
563 break;
564
565 case DISPATCH_CONSTRUCT: {
566 jsdisp_t *obj;
567
568 if(argc) {
569 hres = to_number(ctx, argv[0], &n);
570 if(FAILED(hres))
571 return hres;
572 }else {
573 n = 0;
574 }
575
576 hres = create_number(ctx, n, &obj);
577 if(FAILED(hres))
578 return hres;
579
580 *r = jsval_obj(obj);
581 break;
582 }
583 default:
584 FIXME("unimplemented flags %x\n", flags);
585 return E_NOTIMPL;
586 }
587
588 return S_OK;
589}
GLdouble n
Definition: glext.h:7729
GLbitfield flags
Definition: glext.h:7161
HRESULT to_number(script_ctx_t *, jsval_t, double *) DECLSPEC_HIDDEN
Definition: jsutils.c:609
static jsval_t jsval_obj(jsdisp_t *obj)
Definition: jsval.h:125
HRESULT create_number(script_ctx_t *ctx, double value, jsdisp_t **ret)
Definition: number.c:632

Referenced by create_number_constr().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( jscript  )

Variable Documentation

◆ Number_info

const builtin_info_t Number_info
static
Initial value:
= {
}
#define ARRAY_SIZE(A)
Definition: main.h:20
static HRESULT Number_get_value(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: number.c:505
static const builtin_prop_t Number_props[]
Definition: number.c:515

Definition at line 524 of file number.c.

Referenced by alloc_number().

◆ Number_props

const builtin_prop_t Number_props[]
static
Initial value:
= {
}
#define PROPF_METHOD
Definition: jscript.h:97
static const WCHAR toPrecisionW[]
Definition: number.c:38
static HRESULT Number_toExponential(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:400
static HRESULT Number_toFixed(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:359
static const WCHAR valueOfW[]
Definition: number.c:39
static HRESULT Number_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:490
static HRESULT Number_toPrecision(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:443
static HRESULT Number_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:232
static const WCHAR toLocaleStringW[]
Definition: number.c:35
static HRESULT Number_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: number.c:352
static const WCHAR toStringW[]
Definition: number.c:34
static const WCHAR toFixedW[]
Definition: number.c:36
static const WCHAR toExponentialW[]
Definition: number.c:37

Definition at line 515 of file number.c.

◆ NumberInst_info

const builtin_info_t NumberInst_info
static
Initial value:

Definition at line 533 of file number.c.

Referenced by alloc_number().

◆ toExponentialW

const WCHAR toExponentialW[] = {'t','o','E','x','p','o','n','e','n','t','i','a','l',0}
static

Definition at line 37 of file number.c.

◆ toFixedW

const WCHAR toFixedW[] = {'t','o','F','i','x','e','d',0}
static

Definition at line 36 of file number.c.

◆ toLocaleStringW

const WCHAR toLocaleStringW[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0}
static

Definition at line 35 of file number.c.

◆ toPrecisionW

const WCHAR toPrecisionW[] = {'t','o','P','r','e','c','i','s','i','o','n',0}
static

Definition at line 38 of file number.c.

◆ toStringW

const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0}
static

Definition at line 34 of file number.c.

◆ valueOfW

const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0}
static

Definition at line 39 of file number.c.