32 #if defined __MINGW32__
33 #define USHORT _USHORT
36 #define BDIGITS(x) (RBIGNUM_DIGITS(x))
37 #define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT)
38 #define BIGRAD ((BDIGIT_DBL)1 << BITSPERDIG)
39 #define BIGRAD_HALF ((BDIGIT)(BIGRAD >> 1))
40 #define DIGSPERLONG (SIZEOF_LONG/SIZEOF_BDIGITS)
42 # define DIGSPERLL (SIZEOF_LONG_LONG/SIZEOF_BDIGITS)
44 #define BIGUP(x) ((BDIGIT_DBL)(x) << BITSPERDIG)
45 #define BIGDN(x) RSHIFT((x),BITSPERDIG)
46 #define BIGLO(x) ((BDIGIT)((x) & (BIGRAD-1)))
47 #define BDIGMAX ((BDIGIT)-1)
49 #define BIGZEROP(x) (RBIGNUM_LEN(x) == 0 || \
50 (BDIGITS(x)[0] == 0 && \
51 (RBIGNUM_LEN(x) == 1 || bigzero_p(x))))
53 #define BIGNUM_DEBUG 0
55 #define ON_DEBUG(x) do { x; } while (0)
105 if (l < 0)
return -1;
118 #define RBIGNUM_SET_LEN(b,l) \
119 ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
120 (void)(RBASIC(b)->flags = \
121 (RBASIC(b)->flags & ~RBIGNUM_EMBED_LEN_MASK) | \
122 ((l) << RBIGNUM_EMBED_LEN_SHIFT)) : \
123 (void)(RBIGNUM(b)->as.heap.len = (l)))
134 RBIGNUM(big)->as.heap.digits = ds;
135 RBASIC(big)->flags &= ~RBIGNUM_EMBED_FLAG;
140 ds =
RBIGNUM(big)->as.heap.digits;
183 #define bignew(len,sign) bignew_1(rb_cBignum,(len),(sign))
188 return bignew(len, sign != 0);
210 while (i--) ds[
i] = ~ds[
i];
214 ds[i++] =
BIGLO(num);
236 if (len == 0)
return x;
237 while (--len && !ds[len]);
250 if (len == 0)
return INT2FIX(0);
253 #if 2*SIZEOF_BDIGITS > SIZEOF_LONG
298 digits[i++] =
BIGLO(num);
303 while (--i && !digits[i]) ;
316 u = 1 + (
VALUE)(-(n + 1));
343 #if SIZEOF_LONG % SIZEOF_BDIGITS != 0
344 # error unexpected SIZEOF_LONG : SIZEOF_BDIGITS ratio
377 buf[0] = (
unsigned long)tmp;
378 tmp = tmp < 0 ? ~0L : 0;
379 for (i = 1; i < num_longs; i++)
380 buf[i] = (
unsigned long)
tmp;
387 for (i = 0; i < num_longs && ds < dend; i++) {
389 for (j = 0; j <
DIGSPERLONG && ds < dend; j++, ds++) {
390 l |= ((
unsigned long)*ds << (j *
BITSPERDIG));
394 for (; i < num_longs; i++)
397 for (i = 0; i < num_longs; i++) {
400 for (i = 0; i < num_longs; i++) {
413 while (2 <= num_longs) {
414 if (buf[num_longs-1] == 0 && (
long)buf[num_longs-2] >= 0)
416 else if (buf[num_longs-1] == ~0UL && (
long)buf[num_longs-2] < 0)
423 else if (num_longs == 1)
432 for (i = 0; i < num_longs; i++) {
433 unsigned long d = buf[
i];
434 #if SIZEOF_LONG == SIZEOF_BDIGITS
444 if ((
long)buf[num_longs-1] < 0) {
454 #if SIZEOF_LONG_LONG == QUAD_SIZE && SIZEOF_BDIGITS*2 == SIZEOF_LONG_LONG
480 memcpy(buf, (
char*)&q, SIZEOF_LONG_LONG);
486 unsigned LONG_LONG
q;
492 memcpy(&q, buf, SIZEOF_LONG_LONG);
495 if ((LONG_LONG)q < 0) {
505 big =
bignew(DIGSPERLL, 1);
507 while (i < DIGSPERLL) {
508 digits[i++] =
BIGLO(q);
513 while (i-- && !digits[i]) ;
528 for (i = 0; i <
len; i++)
530 for (i = 0; i <
len; i++) {
558 #define BNEG(b) (RSHIFT(((BDIGIT*)(b))[QUAD_SIZE/SIZEOF_BDIGITS-1],BITSPERDIG-1) != 0)
566 if (sign &&
BNEG(buf)) {
583 char sign = 1, nondigit = 0;
592 #define ISDIGIT(c) ('0' <= (c) && (c) <= '9')
593 #define conv_digit(c) \
594 (!ISASCII(c) ? -1 : \
595 ISDIGIT(c) ? ((c) - '0') : \
596 ISLOWER(c) ? ((c) - 'a' + 10) : \
597 ISUPPER(c) ? ((c) - 'A' + 10) : \
601 if (badcheck)
goto bad;
609 else if (str[0] ==
'-') {
613 if (str[0] ==
'+' || str[0] ==
'-') {
614 if (badcheck)
goto bad;
636 else if (base < -1) {
646 if (str[0] ==
'0' && (str[1] ==
'b'||str[1] ==
'B')) {
654 if (str[0] ==
'0' && (str[1] ==
'o'||str[1] ==
'O')) {
657 case 4:
case 5:
case 6:
case 7:
661 if (str[0] ==
'0' && (str[1] ==
'd'||str[1] ==
'D')) {
664 case 9:
case 11:
case 12:
case 13:
case 14:
case 15:
669 if (str[0] ==
'0' && (str[1] ==
'x'||str[1] ==
'X')) {
674 if (base < 2 || 36 < base) {
687 while ((c = *++str) ==
'0' || c ==
'_') {
698 if (c < 0 || c >= base) {
699 if (badcheck)
goto bad;
702 len *=
strlen(str)*
sizeof(char);
704 if ((
size_t)len <= (
sizeof(long)*
CHAR_BIT)) {
707 if (str < end && *end ==
'_')
goto bigparse;
709 if (end == str)
goto bad;
710 while (*end &&
ISSPACE(*end)) end++;
729 if (badcheck && *str ==
'_')
goto bad;
733 for (i=len;i--;) zds[i]=0;
734 while ((c = *str++) != 0) {
737 if (badcheck)
goto bad;
746 if (c >= base)
break;
753 zds[i++] =
BIGLO(num);
765 if (s+1 < str && str[-1] ==
'_')
goto bad;
766 while (*str &&
ISSPACE(*str)) str++;
811 rb_ull2big(
unsigned LONG_LONG
n)
818 big =
bignew(DIGSPERLL, 1);
820 while (i < DIGSPERLL) {
821 digits[i++] =
BIGLO(num);
826 while (i-- && !digits[i]) ;
832 rb_ll2big(LONG_LONG n)
849 rb_ull2inum(
unsigned LONG_LONG n)
852 return rb_ull2big(n);
856 rb_ll2inum(LONG_LONG n)
881 #define POW2_P(x) (((x)&((x)-1))==0)
887 # define MASK_55 0x5555555555555555UL
888 # define MASK_33 0x3333333333333333UL
889 # define MASK_0f 0x0f0f0f0f0f0f0f0fUL
891 # define MASK_55 0x55555555UL
892 # define MASK_33 0x33333333UL
893 # define MASK_0f 0x0f0f0f0fUL
903 return (
int)(x & 0x7f);
909 static inline unsigned long
934 return (
int)
ones(x) - 1;
943 #define LOG2_KARATSUBA_DIGITS 7
944 #define KARATSUBA_DIGITS (1L<<LOG2_KARATSUBA_DIGITS)
945 #define MAX_BIG2STR_TABLE_ENTRIES 64
953 for (i = 0; i < 35; ++
i) {
955 big2str_power_cache[
i][j] =
Qnil;
963 if (
NIL_P(big2str_power_cache[base - 2][i])) {
964 big2str_power_cache[base - 2][
i] =
969 return big2str_power_cache[base - 2][
i];
980 rb_bug(
"n1 > KARATSUBA_DIGITS");
983 if (m1) *m1 = 1 <<
m;
1013 static const double log_2[] = {
1014 1.0, 1.58496250072116, 2.0,
1015 2.32192809488736, 2.58496250072116, 2.8073549220576,
1016 3.0, 3.16992500144231, 3.32192809488736,
1017 3.4594316186373, 3.58496250072116, 3.70043971814109,
1018 3.8073549220576, 3.90689059560852, 4.0,
1019 4.08746284125034, 4.16992500144231, 4.24792751344359,
1020 4.32192809488736, 4.39231742277876, 4.4594316186373,
1021 4.52356195605701, 4.58496250072116, 4.64385618977472,
1022 4.70043971814109, 4.75488750216347, 4.8073549220576,
1023 4.85798099512757, 4.90689059560852, 4.95419631038688,
1024 5.0, 5.04439411935845, 5.08746284125034,
1025 5.12928301694497, 5.16992500144231
1029 if (base < 2 || 36 < base)
1030 rb_bug(
"invalid radix %d", base);
1033 bits = (SIZEOF_LONG*
CHAR_BIT - 1)/2 + 1;
1046 return (
long)ceil(((
double)bits)/log_2[base - 2]);
1055 while (i && j > 0) {
1060 num =
BIGUP(num) + ds[k];
1061 ds[k] = (
BDIGIT)(num / hbase);
1064 if (trim && ds[i-1] == 0) i--;
1067 ptr[--j] = ruby_digitmap[num % base];
1070 if (trim && i == 0 && num == 0)
break;
1074 while (j < len && ptr[j] ==
'0') j++;
1075 MEMMOVE(ptr, ptr + j,
char, len - j);
1083 long n1,
long len,
long hbase,
int trim)
1103 len - m1, hbase, trim);
1106 m1, hbase, !lh && trim);
1117 long n1, n2,
len, hbase;
1127 if (base < 2 || 36 < base)
1137 #if SIZEOF_BDIGITS > 2
1144 len = off +
big2str_orig(xx, base, ptr + off, n2, hbase, trim);
1183 if (argc == 0) base = 10;
1235 if (num == 1+(
unsigned long)(-(
LONG_MIN+1)))
1255 if (num == 1+(
unsigned long)(-(
LONG_MIN+1)))
1263 static unsigned LONG_LONG
1284 unsigned LONG_LONG num = big2ull(x,
"unsigned long long");
1290 if (num <= LLONG_MAX)
1291 return -(LONG_LONG)num;
1292 if (num == 1+(
unsigned LONG_LONG)(-(LLONG_MIN+1)))
1302 unsigned LONG_LONG num = big2ull(x,
"long long");
1305 if (LLONG_MAX < num)
1310 if (num <= LLONG_MAX)
1311 return -(LONG_LONG)num;
1312 if (num == 1+(
unsigned LONG_LONG)(-(LLONG_MIN+1)))
1327 double u = (d < 0)?-d:d;
1364 y = x >> 64;
if (y) {n -= 64; x = y;}
1367 y = x >> 32;
if (y) {n -= 32; x = y;}
1370 y = x >> 16;
if (y) {n -= 16; x = y;}
1372 y = x >> 8;
if (y) {n -= 8; x = y;}
1373 y = x >> 4;
if (y) {n -= 4; x = y;}
1374 y = x >> 2;
if (y) {n -= 2; x = y;}
1375 y = x >> 1;
if (y) {
return n - 2;}
1400 if (bits && (dl & (1UL << (bits %=
BITSPERDIG)))) {
1401 int carry = dl & ~(~(
BDIGIT)0 << bits);
1404 if ((carry = ds[i]) != 0)
break;
1408 dl &= (
BDIGIT)~0 << bits;
1468 if (yd > 0.0)
return INT2FIX(-1);
1473 #if SIZEOF_LONG * CHAR_BIT < DBL_MANT_DIG
1501 if (yf == 0.0 || rel !=
INT2FIX(0))
1520 #if SIZEOF_LONG * CHAR_BIT < DBL_MANT_DIG
1583 while (xlen-- && (xds[xlen]==yds[xlen]));
1584 if (-1 == xlen)
return INT2FIX(0);
1585 return (xds[xlen] > yds[xlen]) ?
1801 for (i = 0, num = 0; i < yn; i++) {
1806 while (num && i < xn) {
1808 zds[i++] =
BIGLO(num);
1830 z = x; x = y; y = z;
1837 if (xds[i] > yds[i]) {
1840 if (xds[i] < yds[i]) {
1841 z = x; x = y; y = z;
1873 #if SIZEOF_BDIGITS == SIZEOF_LONG
1875 if (xn == 1 && num < 0) {
1881 zds[0] =
BIGLO(num);
1886 for (i=0; i<(
int)(
sizeof(y)/
sizeof(
BDIGIT)); i++) {
1893 while (num && i < xn) {
1895 zds[i++] =
BIGLO(num);
1930 #if SIZEOF_BDIGITS == SIZEOF_LONG
1932 zds[0] =
BIGLO(num);
1937 for (i=0; i<(
int)(
sizeof(y)/
sizeof(
BDIGIT)); i++) {
1944 while (num && i < xn) {
1946 zds[i++] =
BIGLO(num);
1949 if (num) zds[i++] = (
BDIGIT)num;
1950 else while (i < xn) {
1970 tds = xds; xds = yds; yds = tds;
1971 i = xn; xn = yn; yn =
i;
1977 zds[i++] =
BIGLO(num);
1980 while (num && i < yn) {
1982 zds[i++] =
BIGLO(num);
1989 if (num) zds[i++] = (
BDIGIT)num;
2004 if (sign)
return bigsub(y, x);
2102 while (--i && !xds[i]);
2135 while (j--) zds[j] = 0;
2136 for (i = 0; i < xl; i++) {
2139 if (dd == 0)
continue;
2141 for (j = 0; j < yl; j++) {
2143 n = zds[i + j] + ee;
2144 if (ee) zds[i + j] =
BIGLO(n);
2162 long i, xn, yn,
r,
n;
2163 BDIGIT *yds, *zds, *t1ds;
2167 assert(2 * xn <= yn || 3 * xn <= 2*(yn+2));
2176 for (i = 0; i < xn + yn; i++) zds[i] = 0;
2180 r = xn > yn ? yn : xn;
2211 while (--hn && !vds[hn + ln]);
2217 while (--ln && !vds[ln]);
2230 long i,
n, xn, yn, t1n, t2n;
2231 VALUE xh, xl, yh, yl, z,
t1, t2, t3;
2266 for (i = 2 * n + t1n; i < xn + yn; i++) zds[i] = 0;
2275 for (i = t2n; i < 2 *
n; i++) zds[i] = 0;
2282 for (i = 0; i < 2 *
n; i++) zds[i] = 0;
2287 t3 = xl; xl = xh; xh = t3;
2297 t3 = yl; yl = yh; yh = t3;
2327 int const s3 = BITSPERDIG-s2;
2339 *zds-- = num | xds[--xn]>>s3;
2344 for (i = s1; i > 0; --
i)
2353 int s3 = BITSPERDIG - s2;
2366 xds[i++] = (
BDIGIT)(*zds<<s3) | num;
2369 while (i < xn - s1 - 1);
2377 VALUE v0, v12, v1, v2;
2395 VALUE x0, x1, x2, y0, y1, y2;
2396 VALUE u0, u1, u2, u3, u4, v1, v2, v3;
2397 VALUE z0, z1, z2, z3, z4, z,
t;
2407 y0 = x0; y1 = x1; y2 = x2;
2464 v1 = u1; v2 = u2; v3 = u3;
2502 v1 = v2 = v3 =
Qnil;
2569 for (i = 2 * len + 1; i--; ) zds[i] = 0;
2570 for (i = 0; i <
len; i++) {
2577 for (j = i + 1; j <
len; j++) {
2580 zds[i + j] =
BIGLO(c);
2582 if (
BIGDN(v)) c += w;
2589 if (c) zds[i + len + 1] += (
BDIGIT)c;
2594 #define KARATSUBA_MUL_DIGITS 70
2595 #define TOOM3_MUL_DIGITS 150
2623 t = x; x = y; y =
t;
2624 tn = xn; xn = yn; yn = tn;
2647 else if (3*xn <= 2*(yn + 2))
2706 i = bds->
nyzero; num = 0; t2 = 0;
2710 ee = num -
BIGLO(t2);
2716 num +=
zds[j - ny +
i] - t2;
2718 i = 0; num = 0; q--;
2729 }
while (--j >= ny);
2754 if (nx <
ny || (nx ==
ny && xds[nx - 1] < yds[
ny - 1])) {
2756 if (modp) *modp = x;
2774 if (divp) *divp = z;
2780 if (nx==
ny) zds[nx+1] = 0;
2781 while (!yds[
ny-1])
ny--;
2796 tds[j++] =
BIGLO(t2);
2805 zds[j++] =
BIGLO(t2);
2813 while (j--) zds[
j] = xds[
j];
2821 bds.
j = nx==
ny?nx+1:
nx;
2823 if (nx > 10000 ||
ny > 10000) {
2840 j = (nx==
ny ? nx+2 : nx+1) -
ny;
2841 for (i = 0;i <
j;i++) zds[i] = zds[i+
ny];
2848 while (
ny > 1 && !zds[
ny-1]) --
ny;
2852 t2 = (t2 | zds[
i]) >> dd;
2858 if (!zds[
ny-1])
ny--;
2873 if (modp) *modp =
bigadd(mod, y, 1);
3035 BDIGIT bits = (~0 << nb);
3067 #define DBL_BIGDIG ((DBL_MANT_DIG + BITSPERDIG) / BITSPERDIG)
3099 #if SIZEOF_LONG > SIZEOF_INT
3103 if (l < INT_MIN)
return DBL2NUM(0.0);
3189 rb_warn(
"in a**b, b may be too big");
3203 const long BIGLEN_LIMIT =
BITSPERDIG*1024*1024;
3205 if ((xbits > BIGLEN_LIMIT) || (xbits * yy > BIGLEN_LIMIT)) {
3206 rb_warn(
"in a**b, b may be too big");
3210 for (mask =
FIXNUM_MAX + 1; mask; mask >>= 1) {
3236 if (y == 0)
return INT2FIX(0);
3240 #if SIZEOF_BDIGITS == SIZEOF_LONG
3250 #if SIZEOF_BDIGITS == SIZEOF_LONG
3252 zds[0] = xds[0] & y;
3257 for (i=0; i<(
int)(
sizeof(y)/
sizeof(
BDIGIT)); i++) {
3264 zds[
i] = sign?0:xds[
i];
3281 volatile VALUE x, y, z;
3321 for (i=0; i<l1; i++) {
3322 zds[
i] = ds1[
i] & ds2[
i];
3325 zds[
i] = sign?0:ds2[
i];
3346 #if SIZEOF_BDIGITS == SIZEOF_LONG
3348 zds[0] = xds[0] | y;
3353 for (i=0; i<(
int)(
sizeof(y)/
sizeof(
BDIGIT)); i++) {
3377 volatile VALUE x, y, z;
3417 for (i=0; i<l1; i++) {
3418 zds[
i] = ds1[
i] | ds2[
i];
3436 sign = (y >= 0) ? 1 : 0;
3442 #if SIZEOF_BDIGITS == SIZEOF_LONG
3444 zds[0] = xds[0] ^ y;
3449 for (i=0; i<(
int)(
sizeof(y)/
sizeof(
BDIGIT)); i++) {
3456 zds[
i] = sign?xds[
i]:~xds[
i];
3472 volatile VALUE x, y;
3515 for (i=0; i<l1; i++) {
3516 zds[
i] = ds1[
i] ^ ds2[
i];
3519 zds[
i] = sign?ds2[
i]:~ds2[
i];
3587 for (i=0; i<s1; i++) {
3591 for (i=0; i<
len; i++) {
3593 *zds++ =
BIGLO(num);
3649 volatile VALUE save_x;
3674 num = (num | xds[
i]) >> s2;
3676 num =
BIGUP(xds[i]);
3734 while (num += ~xds[i], ++i <= s1) {
#define RB_TYPE_P(obj, type)
VALUE rb_big_modulo(VALUE x, VALUE y)
static VALUE bigdivrem(VALUE, VALUE, volatile VALUE *, volatile VALUE *)
int rb_bigzero_p(VALUE x)
static VALUE bignorm(VALUE x)
#define RBIGNUM_EMBED_LEN_MAX
VALUE rb_big_clone(VALUE x)
#define RBIGNUM_POSITIVE_P(b)
static VALUE bigtrunc(VALUE x)
void rb_bug(const char *fmt,...)
VALUE rb_uint2big(VALUE n)
static VALUE rb_big_even_p(VALUE num)
static VALUE big_shift(VALUE x, long n)
size_t strlen(const char *)
static void big_split(VALUE v, long n, volatile VALUE *ph, volatile VALUE *pl)
static VALUE big2str_power_cache[35][MAX_BIG2STR_TABLE_ENTRIES]
const char * rb_obj_classname(VALUE)
#define MAX_BIG2STR_TABLE_ENTRIES
static VALUE check_shiftdown(VALUE y, VALUE x)
VALUE rb_big_xor(VALUE xx, VALUE yy)
VALUE rb_big2ulong(VALUE x)
static void rb_big_realloc(VALUE big, long len)
static VALUE rb_big_size(VALUE big)
static void * bigdivrem1(void *ptr)
VALUE rb_num_coerce_relop(VALUE, VALUE, ID)
static VALUE bigmul1_single(VALUE x, VALUE y)
static VALUE bigsqr_fast(VALUE x)
#define rb_usascii_str_new2
void rb_big_pack(VALUE val, unsigned long *buf, long num_longs)
static void rb_big_stop(void *ptr)
static VALUE dbl2big(double d)
const char ruby_digitmap[]
static VALUE big_lt(VALUE x, VALUE y)
VALUE rb_big_eql(VALUE x, VALUE y)
VALUE rb_big_plus(VALUE x, VALUE y)
#define BDIGIT_DBL_SIGNED
#define RBIGNUM_SET_LEN(b, l)
static VALUE rb_big_abs(VALUE x)
static unsigned long next_pow2(register unsigned long x)
#define bignew(len, sign)
static int bdigbitsize(BDIGIT x)
VALUE rb_big_and(VALUE xx, VALUE yy)
static long big_real_len(VALUE x)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
#define MEMMOVE(p1, p2, type, n)
static VALUE bigfixize(VALUE x)
VALUE rb_big_fdiv(VALUE x, VALUE y)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_quad_unpack(const char *buf, int sign)
#define MEMCMP(p1, p2, type, n)
static int ceil_log2(register unsigned long x)
VALUE rb_integer_float_cmp(VALUE x, VALUE y)
static VALUE rb_big_neg(VALUE x)
static VALUE bigadd_int(VALUE x, long y)
double rb_big2dbl(VALUE x)
static void power_cache_init(void)
void rb_must_asciicompat(VALUE)
static long big2str_orig(VALUE x, int base, char *ptr, long len, long hbase, int trim)
void rb_big_resize(VALUE big, long len)
static VALUE big_le(VALUE x, VALUE y)
VALUE rb_big_unpack(unsigned long *buf, long num_longs)
VALUE rb_big_new(long len, int sign)
#define STRTOUL(str, endptr, base)
RUBY_EXTERN double round(double)
#define LOG2_KARATSUBA_DIGITS
int rb_cmpint(VALUE val, VALUE a, VALUE b)
VALUE rb_equal(VALUE, VALUE)
static VALUE bigmul1_toom3(VALUE x, VALUE y)
static VALUE rb_big_aref(VALUE x, VALUE y)
#define rb_complex_raw1(x)
static int floor_log2(register unsigned long x)
#define MEMZERO(p, type, n)
VALUE rb_usascii_str_new(const char *, long)
static VALUE rb_big_divide(VALUE x, VALUE y, ID op)
unsigned long rb_genrand_ulong_limited(unsigned long i)
VALUE rb_big2ulong_pack(VALUE x)
VALUE rb_big_divmod(VALUE x, VALUE y)
memset(y->frac+ix+1, 0,(y->Prec-(ix+1))*sizeof(BDIGIT))
VALUE rb_dbl2big(double d)
VALUE rb_big_eq(VALUE x, VALUE y)
static void bigsub_core(BDIGIT *xds, long xn, BDIGIT *yds, long yn, BDIGIT *zds, long zn)
VALUE rb_str_to_inum(VALUE str, int base, int badcheck)
static void biglsh_bang(BDIGIT *xds, long xn, unsigned long shift)
static VALUE big_op(VALUE x, VALUE y, enum big_op_t op)
static VALUE bigxor_int(VALUE x, long y)
#define StringValueCStr(v)
VALUE rb_big_cmp(VALUE x, VALUE y)
static VALUE bigor_int(VALUE x, long y)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
static VALUE bigmul0(VALUE x, VALUE y)
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_num_coerce_cmp(VALUE, VALUE, ID)
#define RBIGNUM_NEGATIVE_P(b)
void rb_thread_check_ints(void)
SIGNED_VALUE rb_big2long(VALUE x)
static VALUE power_cache_get_power(int base, long n1, long *m1)
void rb_num_zerodiv(void)
VALUE rb_big2str(VALUE x, int base)
void * rb_thread_call_without_gvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
#define RBIGNUM_DIGITS(b)
static VALUE bigand_int(VALUE x, long y)
static VALUE bigsub_int(VALUE x, long y0)
RUBY_EXTERN VALUE rb_cInteger
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
VALUE rb_big_minus(VALUE x, VALUE y)
VALUE rb_str_resize(VALUE, long)
#define RBIGNUM_SET_SIGN(b, sign)
static VALUE rb_big_to_s(int argc, VALUE *argv, VALUE x)
#define rb_rational_raw1(x)
VALUE rb_big_div(VALUE x, VALUE y)
VALUE rb_big_idiv(VALUE x, VALUE y)
void rb_gc_register_mark_object(VALUE)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static VALUE bigmul1_balance(VALUE x, VALUE y)
VALUE rb_assoc_new(VALUE car, VALUE cdr)
static void bigadd_core(BDIGIT *xds, long xn, BDIGIT *yds, long yn, BDIGIT *zds, long zn)
VALUE rb_big_mul(VALUE x, VALUE y)
static VALUE rb_big_remainder(VALUE x, VALUE y)
static VALUE big_rshift(VALUE, unsigned long)
static VALUE big_sparse_p(VALUE x)
static VALUE bigmul1_karatsuba(VALUE x, VALUE y)
static VALUE power_cache_get_power0(int base, int i)
static VALUE rb_big_coerce(VALUE x, VALUE y)
static void bigrsh_bang(BDIGIT *xds, long xn, unsigned long shift)
RUBY_EXTERN int isinf(double)
static VALUE big_lshift(VALUE, unsigned long)
static VALUE bigsqr(VALUE x)
static VALUE rb_big_odd_p(VALUE num)
#define MEMCPY(p1, p2, type, n)
static VALUE bignew_1(VALUE klass, long len, int sign)
static VALUE rb_big_to_f(VALUE x)
#define NEWOBJ_OF(obj, type, klass, flags)
VALUE rb_big_uminus(VALUE x)
VALUE rb_str2inum(VALUE str, int base)
VALUE rb_num_coerce_bit(VALUE, VALUE, ID)
st_index_t rb_memhash(const void *ptr, long len)
static void get2comp(VALUE x)
VALUE rb_big_norm(VALUE x)
VALUE rb_big_lshift(VALUE x, VALUE y)
VALUE rb_big_or(VALUE xx, VALUE yy)
VALUE rb_big2str0(VALUE x, int base, int trim)
VALUE rb_uint2inum(VALUE n)
static VALUE rb_big_hash(VALUE x)
static VALUE bigadd(VALUE x, VALUE y, int sign)
static VALUE big_fdiv(VALUE x, VALUE y)
static long big2str_find_n1(VALUE x, int base)
VALUE rb_big_pow(VALUE x, VALUE y)
VALUE rb_int2big(SIGNED_VALUE n)
VALUE rb_integer_float_eq(VALUE x, VALUE y)
static VALUE big2ulong(VALUE x, const char *type, int check)
static VALUE bigmul1_normal(VALUE x, VALUE y)
#define assert(condition)
static int quad_buf_complement(char *buf, size_t len)
static double big2dbl(VALUE x)
VALUE rb_int2inum(SIGNED_VALUE n)
VALUE rb_fix2str(VALUE, int)
void rb_warning(const char *fmt,...)
static long big2str_karatsuba(VALUE x, int base, char *ptr, long n1, long len, long hbase, int trim)
void rb_big_2comp(VALUE x)
VALUE rb_big_rshift(VALUE x, VALUE y)
VALUE rb_cstr_to_inum(const char *str, int base, int badcheck)
static int bigzero_p(VALUE x)
VALUE rb_num_coerce_bin(VALUE, VALUE, ID)
RUBY_EXTERN VALUE rb_eFloatDomainError
static VALUE bigsub(VALUE x, VALUE y)
#define REALLOC_N(var, type, n)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
void rb_quad_pack(char *buf, VALUE val)
void rb_warn(const char *fmt,...)
#define RBIGNUM_EMBED_FLAG
void rb_invalid_str(const char *str, const char *type)
static void big_split3(VALUE v, long n, volatile VALUE *p0, volatile VALUE *p1, volatile VALUE *p2)
static VALUE big_ge(VALUE x, VALUE y)
VALUE rb_cstr2inum(const char *str, int base)
void rb_cmperr(VALUE x, VALUE y)
static void bigdivmod(VALUE x, VALUE y, volatile VALUE *divp, volatile VALUE *modp)
static int ones(register unsigned long x)
#define KARATSUBA_MUL_DIGITS
static VALUE big_gt(VALUE x, VALUE y)