Lines Matching full:x
18 #define DUK__DIGITCHAR(x) duk_lc_digits[(x)] argument
68 * x <- y * z --> duk__bi_mul(x, y, z);
77 #define DUK__BI_PRINT(name,x) duk__bi_print((name),(x)) argument
79 #define DUK__BI_PRINT(name,x) argument
89 DUK_LOCAL void duk__bi_print(const char *name, duk__bigint *x) { in duk__bi_print() argument
96 p += DUK_SPRINTF(p, "%p n=%ld", (void *) x, (long) x->n); in duk__bi_print()
97 if (x->n == 0) { in duk__bi_print()
100 for (i = x->n - 1; i >= 0; i--) { in duk__bi_print()
101 p += DUK_SPRINTF(p, " %08lx", (unsigned long) x->v[i]); in duk__bi_print()
109 DUK_LOCAL duk_small_int_t duk__bi_is_valid(duk__bigint *x) { in duk__bi_is_valid() argument
111 ( ((x->n >= 0) && (x->n <= DUK__BI_MAX_PARTS)) /* is valid size */ && in duk__bi_is_valid()
112 ((x->n == 0) || (x->v[x->n - 1] != 0)) /* is normalized */ ); in duk__bi_is_valid()
116 DUK_LOCAL void duk__bi_normalize(duk__bigint *x) { in duk__bi_normalize() argument
119 for (i = x->n - 1; i >= 0; i--) { in duk__bi_normalize()
120 if (x->v[i] != 0) { in duk__bi_normalize()
125 /* Note: if 'x' is zero, x->n becomes 0 here */ in duk__bi_normalize()
126 x->n = i + 1; in duk__bi_normalize()
127 DUK_ASSERT(duk__bi_is_valid(x)); in duk__bi_normalize()
130 /* x <- y */
131 DUK_LOCAL void duk__bi_copy(duk__bigint *x, duk__bigint *y) { in duk__bi_copy() argument
135 x->n = n; in duk__bi_copy()
139 DUK_MEMCPY((void *) x->v, (const void *) y->v, (size_t) (sizeof(duk_uint32_t) * n)); in duk__bi_copy()
142 DUK_LOCAL void duk__bi_set_small(duk__bigint *x, duk_uint32_t v) { in duk__bi_set_small() argument
144 x->n = 0; in duk__bi_set_small()
146 x->n = 1; in duk__bi_set_small()
147 x->v[0] = v; in duk__bi_set_small()
149 DUK_ASSERT(duk__bi_is_valid(x)); in duk__bi_set_small()
152 /* Return value: <0 <=> x < y
153 * 0 <=> x == y
154 * >0 <=> x > y
156 DUK_LOCAL int duk__bi_compare(duk__bigint *x, duk__bigint *y) { in duk__bi_compare() argument
160 DUK_ASSERT(duk__bi_is_valid(x)); in duk__bi_compare()
163 nx = x->n; in duk__bi_compare()
172 tx = x->v[i]; in duk__bi_compare()
192 /* x <- y + z */
194 DUK_LOCAL void duk__bi_add(duk__bigint *x, duk__bigint *y, duk__bigint *z) { in duk__bi_add() argument
215 x->v[i] = (duk_uint32_t) (tmp & 0xffffffffUL); in duk__bi_add()
220 x->v[i++] = (duk_uint32_t) tmp; in duk__bi_add()
222 x->n = i; in duk__bi_add()
223 DUK_ASSERT(x->n <= DUK__BI_MAX_PARTS); in duk__bi_add()
226 DUK_ASSERT(duk__bi_is_valid(x)); in duk__bi_add()
229 DUK_LOCAL void duk__bi_add(duk__bigint *x, duk__bigint *y, duk__bigint *z) { in duk__bi_add() argument
266 x->v[i] = tmp2; in duk__bi_add()
271 x->v[i++] = carry; in duk__bi_add()
273 x->n = i; in duk__bi_add()
274 DUK_ASSERT(x->n <= DUK__BI_MAX_PARTS); in duk__bi_add()
277 DUK_ASSERT(duk__bi_is_valid(x)); in duk__bi_add()
281 /* x <- y + z */
282 DUK_LOCAL void duk__bi_add_small(duk__bigint *x, duk__bigint *y, duk_uint32_t z) { in duk__bi_add_small() argument
289 duk__bi_add(x, y, &tmp); in duk__bi_add_small()
291 DUK_ASSERT(duk__bi_is_valid(x)); in duk__bi_add_small()
295 /* x <- x + y, use t as temp */
296 DUK_LOCAL void duk__bi_add_copy(duk__bigint *x, duk__bigint *y, duk__bigint *t) {
297 duk__bi_add(t, x, y);
298 duk__bi_copy(x, t);
302 /* x <- y - z, require x >= y => z >= 0, i.e. y >= z */
304 DUK_LOCAL void duk__bi_sub(duk__bigint *x, duk__bigint *y, duk__bigint *z) { in duk__bi_sub() argument
324 x->v[i] = (duk_uint32_t) (tmp & 0xffffffffUL); in duk__bi_sub()
329 x->n = i; in duk__bi_sub()
330 duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ in duk__bi_sub()
331 DUK_ASSERT(duk__bi_is_valid(x)); in duk__bi_sub()
334 DUK_LOCAL void duk__bi_sub(duk__bigint *x, duk__bigint *y, duk__bigint *z) { in duk__bi_sub() argument
366 x->v[i] = tmp2; in duk__bi_sub()
370 x->n = i; in duk__bi_sub()
371 duk__bi_normalize(x); /* need to normalize, may even cancel to 0 */ in duk__bi_sub()
372 DUK_ASSERT(duk__bi_is_valid(x)); in duk__bi_sub()
377 /* x <- y - z */
378 DUK_LOCAL void duk__bi_sub_small(duk__bigint *x, duk__bigint *y, duk_uint32_t z) {
385 duk__bi_sub(x, y, &tmp);
387 DUK_ASSERT(duk__bi_is_valid(x));
391 /* x <- x - y, use t as temp */
392 DUK_LOCAL void duk__bi_sub_copy(duk__bigint *x, duk__bigint *y, duk__bigint *t) { in duk__bi_sub_copy() argument
393 duk__bi_sub(t, x, y); in duk__bi_sub_copy()
394 duk__bi_copy(x, t); in duk__bi_sub_copy()
397 /* x <- y * z */
398 DUK_LOCAL void duk__bi_mul(duk__bigint *x, duk__bigint *y, duk__bigint *z) { in duk__bi_mul() argument
411 x->n = 0; in duk__bi_mul()
415 DUK_MEMZERO((void *) x->v, (size_t) (sizeof(duk_uint32_t) * nx)); in duk__bi_mul()
416 x->n = nx; in duk__bi_mul()
423 tmp += (duk_uint64_t) y->v[i] * (duk_uint64_t) z->v[j] + x->v[i+j]; in duk__bi_mul()
424 x->v[i+j] = (duk_uint32_t) (tmp & 0xffffffffUL); in duk__bi_mul()
430 DUK_ASSERT(x->v[i+j] == 0U); in duk__bi_mul()
431 x->v[i+j] = (duk_uint32_t) tmp; in duk__bi_mul()
456 e = x->v[i+j]; in duk__bi_mul()
492 (unsigned long) x->v[i+j], (unsigned long) r, in duk__bi_mul()
495 x->v[i+j] = s; in duk__bi_mul()
501 DUK_ASSERT(x->v[i+j] == 0U); in duk__bi_mul()
502 x->v[i+j] = (duk_uint32_t) f; in duk__bi_mul()
507 duk__bi_normalize(x); in duk__bi_mul()
508 DUK_ASSERT(duk__bi_is_valid(x)); in duk__bi_mul()
511 /* x <- y * z */
512 DUK_LOCAL void duk__bi_mul_small(duk__bigint *x, duk__bigint *y, duk_uint32_t z) { in duk__bi_mul_small() argument
519 duk__bi_mul(x, y, &tmp); in duk__bi_mul_small()
521 DUK_ASSERT(duk__bi_is_valid(x)); in duk__bi_mul_small()
524 /* x <- x * y, use t as temp */
525 DUK_LOCAL void duk__bi_mul_copy(duk__bigint *x, duk__bigint *y, duk__bigint *t) { in duk__bi_mul_copy() argument
526 duk__bi_mul(t, x, y); in duk__bi_mul_copy()
527 duk__bi_copy(x, t); in duk__bi_mul_copy()
530 /* x <- x * y, use t as temp */
531 DUK_LOCAL void duk__bi_mul_small_copy(duk__bigint *x, duk_uint32_t y, duk__bigint *t) { in duk__bi_mul_small_copy() argument
532 duk__bi_mul_small(t, x, y); in duk__bi_mul_small_copy()
533 duk__bi_copy(x, t); in duk__bi_mul_small_copy()
536 DUK_LOCAL int duk__bi_is_even(duk__bigint *x) { in duk__bi_is_even() argument
537 DUK_ASSERT(duk__bi_is_valid(x)); in duk__bi_is_even()
538 return (x->n == 0) || ((x->v[0] & 0x01) == 0); in duk__bi_is_even()
541 DUK_LOCAL int duk__bi_is_zero(duk__bigint *x) { in duk__bi_is_zero() argument
542 DUK_ASSERT(duk__bi_is_valid(x)); in duk__bi_is_zero()
543 return (x->n == 0); /* this is the case for normalized numbers */ in duk__bi_is_zero()
552 DUK_LOCAL duk_small_int_t duk__bi_is_2to52(duk__bigint *x) { in duk__bi_is_2to52() argument
553 DUK_ASSERT(duk__bi_is_valid(x)); in duk__bi_is_2to52()
555 (x->n == 2) && (x->v[0] == 0U) && (x->v[1] == (1U << (52-32))); in duk__bi_is_2to52()
558 /* x <- (1<<y) */
559 DUK_LOCAL void duk__bi_twoexp(duk__bigint *x, duk_small_int_t y) { in duk__bi_twoexp() argument
565 DUK_MEMZERO((void *) x->v, sizeof(duk_uint32_t) * n); in duk__bi_twoexp()
566 x->n = n; in duk__bi_twoexp()
567 x->v[n - 1] = (((duk_uint32_t) 1) << r); in duk__bi_twoexp()
570 /* x <- b^y; use t1 and t2 as temps */
571 DUK_LOCAL void duk__bi_exp_small(duk__bigint *x, duk_small_int_t b, duk_small_int_t y, duk__bigint … in duk__bi_exp_small() argument
574 DUK_ASSERT(x != t1 && x != t2 && t1 != t2); /* distinct bignums, easy mistake to make */ in duk__bi_exp_small()
579 duk__bi_twoexp(x, y); in duk__bi_exp_small()
587 duk__bi_set_small(x, 1); in duk__bi_exp_small()
595 duk__bi_mul_copy(x, t1, t2); in duk__bi_exp_small()
604 DUK__BI_PRINT("exp_small result", x); in duk__bi_exp_small()
667 #define DUK__DRAGON4_OUTPUT_PREINC(nc_ctx,preinc_idx,x) do { \ argument
670 ((nc_ctx)->digits[(preinc_idx) - 1]) = (duk_uint8_t) (x); \
673 DUK_LOCAL duk_size_t duk__dragon4_format_uint32(duk_uint8_t *buf, duk_uint32_t x, duk_small_int_t r… in duk__dragon4_format_uint32() argument
688 t = x / radix; in duk__dragon4_format_uint32()
689 dig = x - t * radix; in duk__dragon4_format_uint32()
690 x = t; in duk__dragon4_format_uint32()
695 if (x == 0) { in duk__dragon4_format_uint32()
1254 (k - digits >= 1)) || /* (e.g. k=3, digits=2 -> "12X") */ in duk__dragon4_convert_and_push()
1347 DUK_LOCAL void duk__dragon4_double_to_ctx(duk__numconv_stringify_ctx *nc_ctx, duk_double_t x) { in duk__dragon4_double_to_ctx() argument
1366 DUK_DBLUNION_SET_DOUBLE(&u, x); in duk__dragon4_double_to_ctx()
1392 DUK_LOCAL void duk__dragon4_ctx_to_double(duk__numconv_stringify_ctx *nc_ctx, duk_double_t *x) { in duk__dragon4_ctx_to_double() argument
1427 * 1 x x x x ... x x x x|y ==> x x x x ... x x x x in duk__dragon4_ctx_to_double()
1434 * 1 x x x x ... x x|x x y ==> 0 0 ... 1 x x ... x x in duk__dragon4_ctx_to_double()
1531 *x = DUK_DBLUNION_GET_DOUBLE(&u); in duk__dragon4_ctx_to_double()
1542 duk_double_t x; in duk_numconv_stringify() local
1549 x = (duk_double_t) duk_require_number(ctx, -1); in duk_numconv_stringify()
1556 c = (duk_small_int_t) DUK_FPCLASSIFY(x); in duk_numconv_stringify()
1557 if (DUK_SIGNBIT((double) x)) { in duk_numconv_stringify()
1558 x = -x; in duk_numconv_stringify()
1565 DUK_ASSERT(c == DUK_FP_NAN || DUK_SIGNBIT((double) x) == 0); in duk_numconv_stringify()
1597 uval = (unsigned int) x; in duk_numconv_stringify()
1598 if (((double) uval) == x && /* integer number in range */ in duk_numconv_stringify()
1676 duk__dragon4_double_to_ctx(nc_ctx, x); /* -> sets 'f' and 'e' */ in duk_numconv_stringify()
1782 DUK_DDD(DUK_DDDPRINT("parse number: %!T, radix=%ld, flags=0x%08lx", in duk_numconv_parse()
1801 * Automatic hex number detection (leading '0x' or '0X') and octal in duk_numconv_parse()
1860 if (allow_auto_hex_int && (ch == (duk_small_int_t) 'x' || ch == (duk_small_int_t) 'X')) { in duk_numconv_parse()
1861 …DUK_DDD(DUK_DDDPRINT("detected 0x/0X hex prefix, changing radix and preventing fractions and expon… in duk_numconv_parse()
1863 allow_empty = 0; /* interpret e.g. '0x' and '0xg' as a NaN (= parse error) */ in duk_numconv_parse()