15#define DUK__IEEE_DOUBLE_EXP_BIAS 1023
16#define DUK__IEEE_DOUBLE_EXP_MIN (-1022)
18#define DUK__DIGITCHAR(x) duk_lc_digits[(x)]
36 69, 44, 35, 30, 27, 25, 23, 22, 20, 20,
37 20, 19, 19, 18, 18, 17, 17, 17, 16, 16,
38 16, 16, 16, 15, 15, 15, 15, 15, 15, 14,
48 { 957, -1147 }, { 605, -725 }, { 479, -575 }, { 414, -496 },
49 { 372, -446 }, { 342, -411 }, { 321, -384 }, { 304, -364 },
50 { 291, -346 }, { 279, -334 }, { 268, -323 }, { 260, -312 },
51 { 252, -304 }, { 247, -296 }, { 240, -289 }, { 236, -283 },
52 { 231, -278 }, { 227, -273 }, { 223, -267 }, { 220, -263 },
53 { 216, -260 }, { 213, -256 }, { 210, -253 }, { 208, -249 },
54 { 205, -246 }, { 203, -244 }, { 201, -241 }, { 198, -239 },
55 { 196, -237 }, { 195, -234 }, { 193, -232 }, { 191, -230 },
56 { 190, -228 }, { 188, -226 }, { 187, -225 },
74#define DUK__BI_MAX_PARTS 37
76#ifdef DUK_USE_DDDPRINT
77#define DUK__BI_PRINT(name,x) duk__bi_print((name),(x))
79#define DUK__BI_PRINT(name,x)
88#ifdef DUK_USE_DDDPRINT
96 p +=
DUK_SPRINTF(p,
"%p n=%ld", (
void *) x, (
long) x->n);
100 for (i = x->n - 1; i >= 0; i--) {
101 p +=
DUK_SPRINTF(p,
" %08lx", (
unsigned long) x->v[i]);
108#ifdef DUK_USE_ASSERTIONS
112 ((x->
n == 0) || (x->
v[x->
n - 1] != 0)) );
119 for (i = x->
n - 1; i >= 0; i--) {
139 DUK_MEMCPY((
void *) x->
v, (
const void *) y->
v, (
size_t) (
sizeof(duk_uint32_t) * n));
171 for (i = nx - 1; i >= 0; i--) {
193#ifdef DUK_USE_64BIT_OPS
207 ny = y->
n; nz = z->
n;
209 for (i = 0; i < ny; i++) {
215 x->
v[i] = (duk_uint32_t) (tmp & 0xffffffffUL);
220 x->
v[i++] = (duk_uint32_t) tmp;
230 duk_uint32_t carry, tmp1, tmp2;
242 ny = y->
n; nz = z->
n;
244 for (i = 0; i < ny; i++) {
261 carry = (tmp2 <= tmp1 ? 1U : 0U);
263 carry = (tmp2 < tmp1 ? 1U : 0U);
303#ifdef DUK_USE_64BIT_OPS
314 ny = y->
n; nz = z->
n;
316 for (i = 0; i < ny; i++) {
323 tmp = (duk_int64_t) ty - (duk_int64_t) tz + tmp;
324 x->
v[i] = (duk_uint32_t) (tmp & 0xffffffffUL);
336 duk_uint32_t tmp1, tmp2, borrow;
343 ny = y->
n; nz = z->
n;
345 for (i = 0; i < ny; i++) {
361 borrow = (tmp2 >= tmp1 ? 1U : 0U);
363 borrow = (tmp2 > tmp1 ? 1U : 0U);
415 DUK_MEMZERO((
void *) x->
v, (
size_t) (
sizeof(duk_uint32_t) * nx));
419 for (i = 0; i < y->
n; i++) {
420#ifdef DUK_USE_64BIT_OPS
421 duk_uint64_t tmp = 0U;
422 for (j = 0; j < nz; j++) {
423 tmp += (duk_uint64_t) y->
v[i] * (duk_uint64_t) z->
v[j] + x->
v[i+j];
424 x->
v[i+j] = (duk_uint32_t) (tmp & 0xffffffffUL);
431 x->
v[i+j] = (duk_uint32_t) tmp;
448 duk_uint32_t
a, b, c, d, e, f;
449 duk_uint32_t r,
s, t;
451 a = y->
v[i]; b =
a & 0xffffUL;
a =
a >> 16;
454 for (j = 0; j < nz; j++) {
455 c = z->
v[j]; d = c & 0xffffUL; c = c >> 16;
475 t =
s + ((t & 0xffffUL) << 16);
482 t =
s + ((t & 0xffffUL) << 16);
491 (
unsigned long) y->
v[i], (
unsigned long) z->
v[j],
492 (
unsigned long) x->
v[i+j], (
unsigned long) r,
502 x->
v[i+j] = (duk_uint32_t) f;
538 return (x->
n == 0) || ((x->
v[0] & 0x01) == 0);
555 (x->
n == 2) && (x->
v[0] == 0U) && (x->
v[1] == (1U << (52-32)));
567 x->
v[n - 1] = (((duk_uint32_t) 1) << r);
629#define DUK__MAX_OUTPUT_DIGITS 1040
632#define DUK__MAX_FORMATTED_LENGTH 1040
635#define DUK__NUMCONV_CTX_NUM_BIGINTS 7
636#define DUK__NUMCONV_CTX_BIGINTS_SIZE (sizeof(duk__bigint) * DUK__NUMCONV_CTX_NUM_BIGINTS)
667#define DUK__DRAGON4_OUTPUT_PREINC(nc_ctx,preinc_idx,x) do { \
668 DUK_ASSERT((preinc_idx) - 1 >= 0); \
669 DUK_ASSERT((preinc_idx) - 1 < DUK__MAX_OUTPUT_DIGITS); \
670 ((nc_ctx)->digits[(preinc_idx) - 1]) = (duk_uint8_t) (x); \
701 DUK_MEMMOVE((
void *) buf, (
const void *) p, (
size_t) len);
746 if (nc_ctx->
e >= 0) {
749 if (lowest_mantissa) {
765 "lowest mantissa value for this exponent -> "
789 "not lowest mantissa for this exponent -> "
815 "lowest mantissa for this exponent -> "
836 "lowest mantissa for this exponent -> "
874 (
long) nc_ctx->
B, (
long) nc_ctx->
low_ok, (
long) nc_ctx->
high_ok));
978 (
long) count, (
long) nc_ctx->
k, (
long) nc_ctx->
B,
1036 (
long) d, (
long) nc_ctx->
k));
1040 (
long) (d + 1), (
long) nc_ctx->
k));
1047 (
long) d, (
long) nc_ctx->
k));
1055 (
long) (d + 1), (
long) nc_ctx->
k));
1061 (
long) d, (
long) nc_ctx->
k));
1078 int pos = nc_ctx->
k - count + 1;
1080 (
long) pos, (
long) nc_ctx->
k, (
long) count, (
long) nc_ctx->
req_digits));
1081 if (pos <= nc_ctx->req_digits) {
1087 (
long) nc_ctx->
k, (
long) count, (
long) nc_ctx->
req_digits));
1096 nc_ctx->
count = count;
1100#ifdef DUK_USE_DDDPRINT
1102 duk_uint8_t buf[2048];
1105 for (i = 0; i < nc_ctx->
count; i++) {
1107 if (t < 0 || t > 36) {
1108 buf[i] = (duk_uint8_t)
'?';
1114 (
long) nc_ctx->
k, (
const char *) buf));
1131 duk_uint8_t roundup_limit;
1141 if (round_idx >= nc_ctx->
count) {
1143 (
long) round_idx, (
long) nc_ctx->
count));
1145 }
else if (round_idx < 0) {
1159 roundup_limit = (duk_uint8_t) ((nc_ctx->
B + 1) / 2);
1161 p = &nc_ctx->
digits[round_idx];
1162 if (*p >= roundup_limit) {
1167 if (p == &nc_ctx->
digits[0]) {
1170 (
const void *) (&nc_ctx->
digits[0]),
1171 (
size_t) (
sizeof(
char) * nc_ctx->
count));
1179 DUK_DDD(
DUK_DDDPRINT(
"fixed-format rounding carry: B=%ld, roundup_limit=%ld, p=%p, digits=%p",
1180 (
long) nc_ctx->
B, (
long) roundup_limit, (
void *) p, (
void *) nc_ctx->
digits));
1184 if (++t < nc_ctx->B) {
1186 *p = (duk_uint8_t) t;
1197#define DUK__NO_EXP (65536)
1240 buf = (duk_uint8_t *) &nc_ctx->
f;
1254 (k - digits >= 1)) ||
1255 ((k > 21 || k <= -6) && (radix == 10))) {
1257 (
long) k, (
long) (k - 1)));
1268 pos = (k >= 1 ? k : 1);
1274 pos_end = k - digits;
1277 pos_end = k - nc_ctx->
count;
1284 "digits=%ld, abs_pos=%ld",
1285 (
long) expt, (
long) k, (
long) nc_ctx->
count, (
long) pos, (
long) pos_end,
1289 while (pos > pos_end) {
1291 (
long) pos, (
long) pos_end));
1293 *q++ = (duk_uint8_t)
'.';
1296 *q++ = (duk_uint8_t)
'0';
1297 }
else if (pos <= k - nc_ctx->count) {
1298 *q++ = (duk_uint8_t)
'0';
1300 dig = nc_ctx->
digits[k - pos];
1335 *q++ = (duk_uint8_t) expt_sign;
1371 nc_ctx->
f.
v[0] = tmp;
1373 nc_ctx->
f.
v[1] = tmp & 0x000fffffUL;
1382 nc_ctx->
f.
v[1] |= 0x00100000UL;
1454 expt = nc_ctx->
k - 1;
1461 }
else if (expt >= -1022) {
1468 bitstart = 1023 + expt;
1473 bitround = bitstart + 52;
1476 (
long) expt, (
long) bitstart, (
long) bitround));
1495 for (i = 0; i < 52; i++) {
1496 bitidx = bitstart + 52 - 1 - i;
1497 if (bitidx >= nc_ctx->
count) {
1499 }
else if (bitidx < 0) {
1502 v = nc_ctx->
digits[bitidx];
1597 uval = (
unsigned int) x;
1598 if (((
double) uval) == x &&
1601 duk_uint8_t *buf = (duk_uint8_t *) (&nc_ctx->
f);
1602 duk_uint8_t *p = buf;
1605 if (neg && uval != 0) {
1607 *p++ = (duk_uint8_t)
'-';
1670 nc_ctx->
count = count;
1716 roundpos = nc_ctx->
k - roundpos;
1721 (
long) nc_ctx->
k, (
long) nc_ctx->
count, (
long) digits, (
long) roundpos));
1761 const duk_uint8_t *p;
1784 (
long) radix, (
unsigned long) flags));
1843 const duk_uint8_t *q;
1847 if (
DUK_STRNCMP((
const char *) p, (
const char *) q, 8) == 0) {
1848 if (!allow_garbage && (p[8] != (duk_uint8_t) 0)) {
1849 DUK_DDD(
DUK_DDDPRINT(
"parse failed: trailing garbage after matching 'Infinity' not allowed"));
1853 goto negcheck_and_ret;
1861 DUK_DDD(
DUK_DDDPRINT(
"detected 0x/0X hex prefix, changing radix and preventing fractions and exponent"));
1866 DUK_DDD(
DUK_DDDPRINT(
"detected 0n oct prefix, changing radix and preventing fractions and exponent"));
1871 if (detect_radix > 0) {
1872 radix = detect_radix;
1875 allow_naked_frac = 0;
1876 allow_empty_frac = 0;
1877 allow_leading_zero = 1;
1940 "dig_whole=%ld, dig_frac=%ld, dig_expt=%ld, dig_lzero=%ld, dig_prec=%ld",
1941 (
const void *) p, (
int) ((ch >= 0x20 && ch <= 0x7e) ? ch :
'?'), (
long) ch,
1942 (long) expt, (
long) expt_adj, (long) dig_whole, (
long) dig_frac,
1943 (long) dig_expt, (
long) dig_lzero, (long) dig_prec));
1948 dig = (int) ch -
'0' + 0;
1954 if (dig_frac >= 0 || dig_expt >= 0) {
1955 if (allow_garbage) {
1968 if (allow_garbage) {
2014 DUK_ASSERT((dig >= 0 && dig <= 35) || dig == 255);
2017 if (allow_garbage) {
2033 if (f_zero && dig == 0) {
2055 if (dig_frac >= 0) {
2064 expt = expt * radix + dig;
2070 goto parse_explimit_error;
2078 if (dig_lzero > 0 && dig_whole > 1) {
2079 if (!allow_leading_zero) {
2087 if (dig_whole == 0) {
2088 if (dig_frac == 0) {
2092 }
else if (dig_frac > 0) {
2094 if (!allow_naked_frac) {
2096 "leading integer digit(s)"));
2107 if (dig_frac == 0) {
2109 if (!allow_empty_frac) {
2113 }
else if (dig_frac > 0) {
2126 if (dig_expt == 0) {
2127 if (!allow_garbage) {
2138 (
long) expt, (
long) expt_adj, (
long) (expt + expt_adj)));
2143 if (nc_ctx->
f.
n <= 1 &&
2152 if (nc_ctx->
f.
n == 1) {
2153 res = (double) nc_ctx->
f.
v[0];
2157 goto negcheck_and_ret;
2177 if (nc_ctx->
f.
n == 0) {
2183 goto negcheck_and_ret;
2193 if (expt > explim->
upper) {
2196 goto negcheck_and_ret;
2197 }
else if (expt < explim->lower) {
2200 goto negcheck_and_ret;
2245 goto negcheck_and_ret;
2262 parse_explimit_error:
unsigned int duk_small_uint_t
#define DUK_MEMZERO(p, n)
#define DUK_DOUBLE_INFINITY
#define DUK_ERROR_RANGE(thr, msg)
#define DUK_HSTRING_GET_DATA(x)
#define DUK_S2N_FLAG_ALLOW_FRAC
DUK_EXTERNAL duk_double_t duk_require_number(duk_context *ctx, duk_idx_t index)
#define DUK_N2S_FLAG_FIXED_FORMAT
#define DUK_STRIDX_MINUS_INFINITY
#define DUK_S2N_FLAG_ALLOW_MINUS
#define DUK_S2N_FLAG_ALLOW_EMPTY_FRAC
DUK_INTERNAL_DECL void duk_push_hstring_stridx(duk_context *ctx, duk_small_int_t stridx)
DUK_EXTERNAL const char * duk_push_lstring(duk_context *ctx, const char *str, duk_size_t len)
#define DUK_ASSERT_DISABLE(x)
#define DUK_S2N_FLAG_ALLOW_NAKED_FRAC
#define DUK_N2S_FLAG_FORCE_EXP
#define DUK_S2N_FLAG_ALLOW_AUTO_OCT_INT
#define DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT
DUK_EXTERNAL void duk_trim(duk_context *ctx, duk_idx_t index)
#define DUK_N2S_FLAG_FRACTION_DIGITS
#define DUK_S2N_FLAG_ALLOW_EMPTY_AS_ZERO
#define DUK_S2N_MAX_EXPONENT
#define DUK_S2N_FLAG_ALLOW_PLUS
DUK_EXTERNAL void duk_push_number(duk_context *ctx, duk_double_t val)
#define DUK_STRIDX_INFINITY
#define DUK_N2S_FLAG_NO_ZERO_PAD
#define DUK_S2N_FLAG_ALLOW_INF
DUK_EXTERNAL void duk_pop(duk_context *ctx)
DUK_EXTERNAL void duk_push_nan(duk_context *ctx)
#define DUK_S2N_FLAG_TRIM_WHITE
DUK_INTERNAL_DECL duk_hstring * duk_require_hstring(duk_context *ctx, duk_idx_t index)
#define DUK_S2N_FLAG_ALLOW_LEADING_ZERO
#define DUK_HTHREAD_STRING_INFINITY(thr)
#define DUK_S2N_FLAG_ALLOW_EXP
#define DUK_S2N_FLAG_ALLOW_GARBAGE
DUK_INTERNAL_DECL duk_tval * duk_get_tval(duk_context *ctx, duk_idx_t index)
#define DUK_DBLUNION_GET_LOW32(u)
#define DUK_DBLUNION_SET_DOUBLE(u, v)
#define DUK_DBLUNION_GET_DOUBLE(u)
#define DUK_DBLUNION_SET_HIGH32(u, v)
#define DUK_DBLUNION_GET_HIGH32(u)
#define DUK_DBLUNION_SET_LOW32(u, v)
#define DUK__BI_MAX_PARTS
DUK_LOCAL void duk__bi_sub_copy(duk__bigint *x, duk__bigint *y, duk__bigint *t)
DUK_LOCAL void duk__bi_mul_small(duk__bigint *x, duk__bigint *y, duk_uint32_t z)
#define DUK__IEEE_DOUBLE_EXP_BIAS
#define DUK__MAX_OUTPUT_DIGITS
DUK_LOCAL void duk__bi_add_small(duk__bigint *x, duk__bigint *y, duk_uint32_t z)
DUK_LOCAL int duk__bi_is_even(duk__bigint *x)
DUK_INTERNAL void duk_numconv_stringify(duk_context *ctx, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags)
#define DUK__MAX_FORMATTED_LENGTH
DUK_LOCAL void duk__bi_mul(duk__bigint *x, duk__bigint *y, duk__bigint *z)
DUK_LOCAL void duk__bi_normalize(duk__bigint *x)
#define DUK__NUMCONV_CTX_BIGINTS_SIZE
DUK_LOCAL void duk__bi_add(duk__bigint *x, duk__bigint *y, duk__bigint *z)
DUK_LOCAL void duk__dragon4_double_to_ctx(duk__numconv_stringify_ctx *nc_ctx, duk_double_t x)
DUK_LOCAL void duk__bi_set_small(duk__bigint *x, duk_uint32_t v)
DUK_LOCAL duk_small_int_t duk__bi_is_2to52(duk__bigint *x)
DUK_LOCAL int duk__bi_is_zero(duk__bigint *x)
DUK_LOCAL const duk__exp_limits duk__str2num_exp_limits[]
#define DUK__DIGITCHAR(x)
DUK_LOCAL void duk__bi_copy(duk__bigint *x, duk__bigint *y)
DUK_LOCAL void duk__bi_mul_copy(duk__bigint *x, duk__bigint *y, duk__bigint *t)
DUK_LOCAL void duk__bi_mul_small_copy(duk__bigint *x, duk_uint32_t y, duk__bigint *t)
DUK_LOCAL void duk__dragon4_ctx_to_double(duk__numconv_stringify_ctx *nc_ctx, duk_double_t *x)
DUK_LOCAL duk_small_int_t duk__dragon4_fixed_format_round(duk__numconv_stringify_ctx *nc_ctx, duk_small_int_t round_idx)
DUK_LOCAL void duk__dragon4_generate(duk__numconv_stringify_ctx *nc_ctx)
DUK_LOCAL const duk_uint8_t duk__str2num_digits_for_radix[]
#define DUK__IEEE_DOUBLE_EXP_MIN
#define DUK__BI_PRINT(name, x)
DUK_LOCAL void duk__bi_exp_small(duk__bigint *x, duk_small_int_t b, duk_small_int_t y, duk__bigint *t1, duk__bigint *t2)
DUK_LOCAL void duk__bi_sub(duk__bigint *x, duk__bigint *y, duk__bigint *z)
DUK_INTERNAL void duk_numconv_parse(duk_context *ctx, duk_small_int_t radix, duk_small_uint_t flags)
DUK_LOCAL void duk__bi_twoexp(duk__bigint *x, duk_small_int_t y)
DUK_LOCAL void duk__dragon4_scale(duk__numconv_stringify_ctx *nc_ctx)
DUK_LOCAL void duk__dragon4_prepare(duk__numconv_stringify_ctx *nc_ctx)
DUK_LOCAL int duk__bi_compare(duk__bigint *x, duk__bigint *y)
DUK_LOCAL duk_size_t duk__dragon4_format_uint32(duk_uint8_t *buf, duk_uint32_t x, duk_small_int_t radix)
DUK_LOCAL void duk__dragon4_convert_and_push(duk__numconv_stringify_ctx *nc_ctx, duk_context *ctx, duk_small_int_t radix, duk_small_int_t digits, duk_small_uint_t flags, duk_small_int_t neg)
#define DUK__DRAGON4_OUTPUT_PREINC(nc_ctx, preinc_idx, x)
CURL_EXTERN CURLMcode curl_socket_t s
duk_uint32_t v[DUK__BI_MAX_PARTS]
duk_small_int_t req_digits
duk_uint8_t digits[DUK__MAX_OUTPUT_DIGITS]
duk_small_int_t unequal_gaps