summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-15 21:17:34 (GMT)
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-15 21:17:34 (GMT)
commit3c99764bcdd181cbac849f82e512f4b64bdf27c1 (patch)
tree6947c6d745b014a192c645a2652a84c46718d421
parent7f27543b3b1dfbd864c7e4edd22f739078fd2908 (diff)
* internal.h: Rename macro names: RBIGNUM_FOO to BIGNUM_FOO.
(BIGNUM_EMBED_LEN_NUMBITS): Renamed from RBIGNUM_EMBED_LEN_NUMBITS. (BIGNUM_EMBED_LEN_MAX): Renamed from RBIGNUM_EMBED_LEN_MAX. (BIGNUM_SIGN_BIT): Renamed from RBIGNUM_SIGN_BIT. (BIGNUM_SIGN): Renamed from RBIGNUM_SIGN. (BIGNUM_SET_SIGN): Renamed from RBIGNUM_SET_SIGN. (BIGNUM_POSITIVE_P): Renamed from RBIGNUM_POSITIVE_P. (BIGNUM_NEGATIVE_P): Renamed from RBIGNUM_NEGATIVE_P. (BIGNUM_EMBED_FLAG): Renamed from RBIGNUM_EMBED_FLAG. (BIGNUM_EMBED_LEN_MASK): Renamed from RBIGNUM_EMBED_LEN_MASK. (BIGNUM_EMBED_LEN_SHIFT): Renamed from RBIGNUM_EMBED_LEN_SHIFT. (BIGNUM_LEN): Renamed from RBIGNUM_LEN. (RBIGNUM_DIGITS): Renamed from RBIGNUM_DIGITS. (BIGNUM_LENINT): Renamed from RBIGNUM_LENINT. * bignum.c: Follow the above change. * gc.c: Ditto. * marshal.c: Ditto. * math.c: Ditto. * numeric.c: Ditto. * random.c: Ditto. * rational.c: Ditto. * sprintf.c: Ditto. * ext/-test-/bignum/bigzero.c: Ditto. * ext/-test-/bignum/intpack.c: Ditto. * ext/bigdecimal/bigdecimal.c: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog39
-rw-r--r--bignum.c328
-rw-r--r--ext/-test-/bignum/bigzero.c4
-rw-r--r--ext/-test-/bignum/intpack.c4
-rw-r--r--ext/bigdecimal/bigdecimal.c4
-rw-r--r--gc.c8
-rw-r--r--internal.h50
-rw-r--r--marshal.c6
-rw-r--r--math.c6
-rw-r--r--numeric.c10
-rw-r--r--random.c4
-rw-r--r--rational.c10
-rw-r--r--sprintf.c2
13 files changed, 257 insertions, 218 deletions
diff --git a/ChangeLog b/ChangeLog
index 885a412..ced3513 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,42 @@
+Sun Feb 16 06:12:23 2014 Tanaka Akira <akr@fsij.org>
+
+ * internal.h: Rename macro names: RBIGNUM_FOO to BIGNUM_FOO.
+ (BIGNUM_EMBED_LEN_NUMBITS): Renamed from RBIGNUM_EMBED_LEN_NUMBITS.
+ (BIGNUM_EMBED_LEN_MAX): Renamed from RBIGNUM_EMBED_LEN_MAX.
+ (BIGNUM_SIGN_BIT): Renamed from RBIGNUM_SIGN_BIT.
+ (BIGNUM_SIGN): Renamed from RBIGNUM_SIGN.
+ (BIGNUM_SET_SIGN): Renamed from RBIGNUM_SET_SIGN.
+ (BIGNUM_POSITIVE_P): Renamed from RBIGNUM_POSITIVE_P.
+ (BIGNUM_NEGATIVE_P): Renamed from RBIGNUM_NEGATIVE_P.
+ (BIGNUM_EMBED_FLAG): Renamed from RBIGNUM_EMBED_FLAG.
+ (BIGNUM_EMBED_LEN_MASK): Renamed from RBIGNUM_EMBED_LEN_MASK.
+ (BIGNUM_EMBED_LEN_SHIFT): Renamed from RBIGNUM_EMBED_LEN_SHIFT.
+ (BIGNUM_LEN): Renamed from RBIGNUM_LEN.
+ (RBIGNUM_DIGITS): Renamed from RBIGNUM_DIGITS.
+ (BIGNUM_LENINT): Renamed from RBIGNUM_LENINT.
+
+ * bignum.c: Follow the above change.
+
+ * gc.c: Ditto.
+
+ * marshal.c: Ditto.
+
+ * math.c: Ditto.
+
+ * numeric.c: Ditto.
+
+ * random.c: Ditto.
+
+ * rational.c: Ditto.
+
+ * sprintf.c: Ditto.
+
+ * ext/-test-/bignum/bigzero.c: Ditto.
+
+ * ext/-test-/bignum/intpack.c: Ditto.
+
+ * ext/bigdecimal/bigdecimal.c: Ditto.
+
Sat Feb 15 20:48:49 2014 Tanaka Akira <akr@fsij.org>
* configure.in (FILE_READEND): Don't detect it because it is not used.
diff --git a/bignum.c b/bignum.c
index eb04e43..564bfe3 100644
--- a/bignum.c
+++ b/bignum.c
@@ -50,7 +50,7 @@ STATIC_ASSERT(sizeof_bdigit_and_dbl, SIZEOF_BDIGITS*2 <= SIZEOF_BDIGIT_DBL);
STATIC_ASSERT(bdigit_signedness, 0 < (BDIGIT)-1);
STATIC_ASSERT(bdigit_dbl_signedness, 0 < (BDIGIT_DBL)-1);
STATIC_ASSERT(bdigit_dbl_signed_signedness, 0 > (BDIGIT_DBL_SIGNED)-1);
-STATIC_ASSERT(rbignum_embed_len_max, RBIGNUM_EMBED_LEN_MAX <= (RBIGNUM_EMBED_LEN_MASK >> RBIGNUM_EMBED_LEN_SHIFT));
+STATIC_ASSERT(rbignum_embed_len_max, BIGNUM_EMBED_LEN_MAX <= (BIGNUM_EMBED_LEN_MASK >> BIGNUM_EMBED_LEN_SHIFT));
#if SIZEOF_BDIGITS < SIZEOF_LONG
STATIC_ASSERT(sizeof_long_and_sizeof_bdigit, SIZEOF_LONG % SIZEOF_BDIGITS == 0);
@@ -71,7 +71,7 @@ STATIC_ASSERT(sizeof_long_and_sizeof_bdigit, SIZEOF_BDIGITS % SIZEOF_LONG == 0);
#define FILL_LOWBITS(d, numbits) ((d) | (LSHIFTX(((d)*0+1), (numbits))-1))
#define POW2_P(x) (((x)&((x)-1))==0)
-#define BDIGITS(x) (RBIGNUM_DIGITS(x))
+#define BDIGITS(x) (BIGNUM_DIGITS(x))
#define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT)
#define BIGRAD ((BDIGIT_DBL)1 << BITSPERDIG)
#define BIGRAD_HALF ((BDIGIT)(BIGRAD >> 1))
@@ -90,12 +90,12 @@ STATIC_ASSERT(sizeof_long_and_sizeof_bdigit, SIZEOF_BDIGITS % SIZEOF_LONG == 0);
# define swap_bdigit(x) swap64(x)
#endif
-#define BIGZEROP(x) (RBIGNUM_LEN(x) == 0 || \
+#define BIGZEROP(x) (BIGNUM_LEN(x) == 0 || \
(BDIGITS(x)[0] == 0 && \
- (RBIGNUM_LEN(x) == 1 || bigzero_p(x))))
-#define BIGSIZE(x) (RBIGNUM_LEN(x) == 0 ? (size_t)0 : \
- BDIGITS(x)[RBIGNUM_LEN(x)-1] ? \
- (size_t)(RBIGNUM_LEN(x)*SIZEOF_BDIGITS - nlz(BDIGITS(x)[RBIGNUM_LEN(x)-1])/CHAR_BIT) : \
+ (BIGNUM_LEN(x) == 1 || bigzero_p(x))))
+#define BIGSIZE(x) (BIGNUM_LEN(x) == 0 ? (size_t)0 : \
+ BDIGITS(x)[BIGNUM_LEN(x)-1] ? \
+ (size_t)(BIGNUM_LEN(x)*SIZEOF_BDIGITS - nlz(BDIGITS(x)[BIGNUM_LEN(x)-1])/CHAR_BIT) : \
rb_absint_size(x, NULL))
#define BIGDIVREM_EXTRA_WORDS 1
@@ -109,8 +109,8 @@ STATIC_ASSERT(sizeof_long_and_sizeof_bdigit, SIZEOF_BDIGITS % SIZEOF_LONG == 0);
#define BARY_DIVMOD(q, r, x, y) bary_divmod(BARY_ARGS(q), BARY_ARGS(r), BARY_ARGS(x), BARY_ARGS(y))
#define BARY_ZERO_P(x) bary_zero_p(BARY_ARGS(x))
-#define RBIGNUM_SET_NEGATIVE_SIGN(b) RBIGNUM_SET_SIGN(b, 0)
-#define RBIGNUM_SET_POSITIVE_SIGN(b) RBIGNUM_SET_SIGN(b, 1)
+#define BIGNUM_SET_NEGATIVE_SIGN(b) BIGNUM_SET_SIGN(b, 0)
+#define BIGNUM_SET_POSITIVE_SIGN(b) BIGNUM_SET_SIGN(b, 1)
#define bignew(len,sign) bignew_1(rb_cBignum,(len),(sign))
@@ -1542,8 +1542,8 @@ bary_mul_normal(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIG
VALUE
rb_big_mul_normal(VALUE x, VALUE y)
{
- size_t xn = RBIGNUM_LEN(x), yn = RBIGNUM_LEN(y), zn = xn + yn;
- VALUE z = bignew(zn, RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
+ size_t xn = BIGNUM_LEN(x), yn = BIGNUM_LEN(y), zn = xn + yn;
+ VALUE z = bignew(zn, BIGNUM_SIGN(x)==BIGNUM_SIGN(y));
bary_mul_normal(BDIGITS(z), zn, BDIGITS(x), xn, BDIGITS(y), yn);
RB_GC_GUARD(x);
RB_GC_GUARD(y);
@@ -1611,7 +1611,7 @@ bary_sq_fast(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn)
VALUE
rb_big_sq_fast(VALUE x)
{
- size_t xn = RBIGNUM_LEN(x), zn = 2 * xn;
+ size_t xn = BIGNUM_LEN(x), zn = 2 * xn;
VALUE z = bignew(zn, 1);
bary_sq_fast(BDIGITS(z), zn, BDIGITS(x), xn);
RB_GC_GUARD(x);
@@ -1670,8 +1670,8 @@ bary_mul_balance_with_mulfunc(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t
VALUE
rb_big_mul_balance(VALUE x, VALUE y)
{
- size_t xn = RBIGNUM_LEN(x), yn = RBIGNUM_LEN(y), zn = xn + yn;
- VALUE z = bignew(zn, RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
+ size_t xn = BIGNUM_LEN(x), yn = BIGNUM_LEN(y), zn = xn + yn;
+ VALUE z = bignew(zn, BIGNUM_SIGN(x)==BIGNUM_SIGN(y));
bary_mul_balance_with_mulfunc(BDIGITS(z), zn, BDIGITS(x), xn, BDIGITS(y), yn, NULL, 0, bary_mul_toom3_start);
RB_GC_GUARD(x);
RB_GC_GUARD(y);
@@ -1851,8 +1851,8 @@ bary_mul_karatsuba(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const B
VALUE
rb_big_mul_karatsuba(VALUE x, VALUE y)
{
- size_t xn = RBIGNUM_LEN(x), yn = RBIGNUM_LEN(y), zn = xn + yn;
- VALUE z = bignew(zn, RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
+ size_t xn = BIGNUM_LEN(x), yn = BIGNUM_LEN(y), zn = xn + yn;
+ VALUE z = bignew(zn, BIGNUM_SIGN(x)==BIGNUM_SIGN(y));
if (!((xn <= yn && yn < 2) || KARATSUBA_BALANCED(xn, yn)))
rb_raise(rb_eArgError, "unexpected bignum length for karatsuba");
bary_mul_karatsuba(BDIGITS(z), zn, BDIGITS(x), xn, BDIGITS(y), yn, NULL, 0);
@@ -2248,8 +2248,8 @@ bary_mul_toom3(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGI
VALUE
rb_big_mul_toom3(VALUE x, VALUE y)
{
- size_t xn = RBIGNUM_LEN(x), yn = RBIGNUM_LEN(y), zn = xn + yn;
- VALUE z = bignew(zn, RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
+ size_t xn = BIGNUM_LEN(x), yn = BIGNUM_LEN(y), zn = xn + yn;
+ VALUE z = bignew(zn, BIGNUM_SIGN(x)==BIGNUM_SIGN(y));
if (xn > yn || yn < 3 || !TOOM3_BALANCED(xn,yn))
rb_raise(rb_eArgError, "unexpected bignum length for toom3");
bary_mul_toom3(BDIGITS(z), zn, BDIGITS(x), xn, BDIGITS(y), yn, NULL, 0);
@@ -2289,8 +2289,8 @@ bary_mul_gmp(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT
VALUE
rb_big_mul_gmp(VALUE x, VALUE y)
{
- size_t xn = RBIGNUM_LEN(x), yn = RBIGNUM_LEN(y), zn = xn + yn;
- VALUE z = bignew(zn, RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
+ size_t xn = BIGNUM_LEN(x), yn = BIGNUM_LEN(y), zn = xn + yn;
+ VALUE z = bignew(zn, BIGNUM_SIGN(x)==BIGNUM_SIGN(y));
bary_mul_gmp(BDIGITS(z), zn, BDIGITS(x), xn, BDIGITS(y), yn);
RB_GC_GUARD(x);
RB_GC_GUARD(y);
@@ -2700,7 +2700,7 @@ bary_divmod_normal(BDIGIT *qds, size_t qn, BDIGIT *rds, size_t rn, const BDIGIT
VALUE
rb_big_divrem_normal(VALUE x, VALUE y)
{
- size_t xn = RBIGNUM_LEN(x), yn = RBIGNUM_LEN(y), qn, rn;
+ size_t xn = BIGNUM_LEN(x), yn = BIGNUM_LEN(y), qn, rn;
BDIGIT *xds = BDIGITS(x), *yds = BDIGITS(y), *qds, *rds;
VALUE q, r;
@@ -2713,11 +2713,11 @@ rb_big_divrem_normal(VALUE x, VALUE y)
return rb_assoc_new(LONG2FIX(0), x);
qn = xn + BIGDIVREM_EXTRA_WORDS;
- q = bignew(qn, RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
+ q = bignew(qn, BIGNUM_SIGN(x)==BIGNUM_SIGN(y));
qds = BDIGITS(q);
rn = yn;
- r = bignew(rn, RBIGNUM_SIGN(x));
+ r = bignew(rn, BIGNUM_SIGN(x));
rds = BDIGITS(r);
bary_divmod_normal(qds, qn, rds, rn, xds, xn, yds, yn);
@@ -2781,7 +2781,7 @@ bary_divmod_gmp(BDIGIT *qds, size_t qn, BDIGIT *rds, size_t rn, const BDIGIT *xd
VALUE
rb_big_divrem_gmp(VALUE x, VALUE y)
{
- size_t xn = RBIGNUM_LEN(x), yn = RBIGNUM_LEN(y), qn, rn;
+ size_t xn = BIGNUM_LEN(x), yn = BIGNUM_LEN(y), qn, rn;
BDIGIT *xds = BDIGITS(x), *yds = BDIGITS(y), *qds, *rds;
VALUE q, r;
@@ -2794,11 +2794,11 @@ rb_big_divrem_gmp(VALUE x, VALUE y)
return rb_assoc_new(LONG2FIX(0), x);
qn = xn - yn + 1;
- q = bignew(qn, RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
+ q = bignew(qn, BIGNUM_SIGN(x)==BIGNUM_SIGN(y));
qds = BDIGITS(q);
rn = yn;
- r = bignew(rn, RBIGNUM_SIGN(x));
+ r = bignew(rn, BIGNUM_SIGN(x));
rds = BDIGITS(r);
bary_divmod_gmp(qds, qn, rds, rn, xds, xn, yds, yn);
@@ -2878,11 +2878,11 @@ static void
dump_bignum(VALUE x)
{
long i;
- printf("%c0x0", RBIGNUM_SIGN(x) ? '+' : '-');
- for (i = RBIGNUM_LEN(x); i--; ) {
+ printf("%c0x0", BIGNUM_SIGN(x) ? '+' : '-');
+ for (i = BIGNUM_LEN(x); i--; ) {
printf("_%0*"PRIxBDIGIT, SIZEOF_BDIGITS*2, BDIGITS(x)[i]);
}
- printf(", len=%lu", RBIGNUM_LEN(x));
+ printf(", len=%lu", BIGNUM_LEN(x));
puts("");
}
@@ -2899,7 +2899,7 @@ rb_big_dump(VALUE x)
static int
bigzero_p(VALUE x)
{
- return bary_zero_p(BDIGITS(x), RBIGNUM_LEN(x));
+ return bary_zero_p(BDIGITS(x), BIGNUM_LEN(x));
}
int
@@ -2922,7 +2922,7 @@ rb_cmpint(VALUE val, VALUE a, VALUE b)
}
if (RB_BIGNUM_TYPE_P(val)) {
if (BIGZEROP(val)) return 0;
- if (RBIGNUM_SIGN(val)) return 1;
+ if (BIGNUM_SIGN(val)) return 1;
return -1;
}
if (RTEST(rb_funcall(val, '>', 1, INT2FIX(0)))) return 1;
@@ -2930,31 +2930,31 @@ rb_cmpint(VALUE val, VALUE a, VALUE b)
return 0;
}
-#define RBIGNUM_SET_LEN(b,l) \
- ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
+#define BIGNUM_SET_LEN(b,l) \
+ ((RBASIC(b)->flags & BIGNUM_EMBED_FLAG) ? \
(void)(RBASIC(b)->flags = \
- (RBASIC(b)->flags & ~RBIGNUM_EMBED_LEN_MASK) | \
- ((l) << RBIGNUM_EMBED_LEN_SHIFT)) : \
+ (RBASIC(b)->flags & ~BIGNUM_EMBED_LEN_MASK) | \
+ ((l) << BIGNUM_EMBED_LEN_SHIFT)) : \
(void)(RBIGNUM(b)->as.heap.len = (l)))
static void
rb_big_realloc(VALUE big, long len)
{
BDIGIT *ds;
- if (RBASIC(big)->flags & RBIGNUM_EMBED_FLAG) {
- if (RBIGNUM_EMBED_LEN_MAX < len) {
+ if (RBASIC(big)->flags & BIGNUM_EMBED_FLAG) {
+ if (BIGNUM_EMBED_LEN_MAX < len) {
ds = ALLOC_N(BDIGIT, len);
- MEMCPY(ds, RBIGNUM(big)->as.ary, BDIGIT, RBIGNUM_EMBED_LEN_MAX);
- RBIGNUM(big)->as.heap.len = RBIGNUM_LEN(big);
+ MEMCPY(ds, RBIGNUM(big)->as.ary, BDIGIT, BIGNUM_EMBED_LEN_MAX);
+ RBIGNUM(big)->as.heap.len = BIGNUM_LEN(big);
RBIGNUM(big)->as.heap.digits = ds;
- RBASIC(big)->flags &= ~RBIGNUM_EMBED_FLAG;
+ RBASIC(big)->flags &= ~BIGNUM_EMBED_FLAG;
}
}
else {
- if (len <= RBIGNUM_EMBED_LEN_MAX) {
+ if (len <= BIGNUM_EMBED_LEN_MAX) {
ds = RBIGNUM(big)->as.heap.digits;
- RBASIC(big)->flags |= RBIGNUM_EMBED_FLAG;
- RBIGNUM_SET_LEN(big, len);
+ RBASIC(big)->flags |= BIGNUM_EMBED_FLAG;
+ BIGNUM_SET_LEN(big, len);
(void)VALGRIND_MAKE_MEM_UNDEFINED((void*)RBIGNUM(big)->as.ary, sizeof(RBIGNUM(big)->as.ary));
if (ds) {
MEMCPY(RBIGNUM(big)->as.ary, ds, BDIGIT, len);
@@ -2962,7 +2962,7 @@ rb_big_realloc(VALUE big, long len)
}
}
else {
- if (RBIGNUM_LEN(big) == 0) {
+ if (BIGNUM_LEN(big) == 0) {
RBIGNUM(big)->as.heap.digits = ALLOC_N(BDIGIT, len);
}
else {
@@ -2976,17 +2976,17 @@ void
rb_big_resize(VALUE big, long len)
{
rb_big_realloc(big, len);
- RBIGNUM_SET_LEN(big, len);
+ BIGNUM_SET_LEN(big, len);
}
static VALUE
bignew_1(VALUE klass, long len, int sign)
{
NEWOBJ_OF(big, struct RBignum, klass, T_BIGNUM | (RGENGC_WB_PROTECTED_BIGNUM ? FL_WB_PROTECTED : 0));
- RBIGNUM_SET_SIGN(big, sign?1:0);
- if (len <= RBIGNUM_EMBED_LEN_MAX) {
- RBASIC(big)->flags |= RBIGNUM_EMBED_FLAG;
- RBIGNUM_SET_LEN(big, len);
+ BIGNUM_SET_SIGN(big, sign?1:0);
+ if (len <= BIGNUM_EMBED_LEN_MAX) {
+ RBASIC(big)->flags |= BIGNUM_EMBED_FLAG;
+ BIGNUM_SET_LEN(big, len);
(void)VALGRIND_MAKE_MEM_UNDEFINED((void*)RBIGNUM(big)->as.ary, sizeof(RBIGNUM(big)->as.ary));
}
else {
@@ -3006,8 +3006,8 @@ rb_big_new(long len, int sign)
VALUE
rb_big_clone(VALUE x)
{
- long len = RBIGNUM_LEN(x);
- VALUE z = bignew_1(CLASS_OF(x), len, RBIGNUM_SIGN(x));
+ long len = BIGNUM_LEN(x);
+ VALUE z = bignew_1(CLASS_OF(x), len, BIGNUM_SIGN(x));
MEMCPY(BDIGITS(z), BDIGITS(x), BDIGIT, len);
return z;
@@ -3016,15 +3016,15 @@ rb_big_clone(VALUE x)
static void
big_extend_carry(VALUE x)
{
- rb_big_resize(x, RBIGNUM_LEN(x)+1);
- BDIGITS(x)[RBIGNUM_LEN(x)-1] = 1;
+ rb_big_resize(x, BIGNUM_LEN(x)+1);
+ BDIGITS(x)[BIGNUM_LEN(x)-1] = 1;
}
/* modify a bignum by 2's complement */
static void
get2comp(VALUE x)
{
- long i = RBIGNUM_LEN(x);
+ long i = BIGNUM_LEN(x);
BDIGIT *ds = BDIGITS(x);
if (bary_2comp(ds, i)) {
@@ -3042,13 +3042,13 @@ static BDIGIT
abs2twocomp(VALUE *xp, long *n_ret)
{
VALUE x = *xp;
- long n = RBIGNUM_LEN(x);
+ long n = BIGNUM_LEN(x);
BDIGIT *ds = BDIGITS(x);
BDIGIT hibits = 0;
BARY_TRUNC(ds, n);
- if (n != 0 && RBIGNUM_NEGATIVE_P(x)) {
+ if (n != 0 && BIGNUM_NEGATIVE_P(x)) {
VALUE z = bignew_1(CLASS_OF(x), n, 0);
MEMCPY(BDIGITS(z), ds, BDIGIT, n);
bary_2comp(BDIGITS(z), n);
@@ -3062,7 +3062,7 @@ abs2twocomp(VALUE *xp, long *n_ret)
static void
twocomp2abs_bang(VALUE x, int hibits)
{
- RBIGNUM_SET_SIGN(x, !hibits);
+ BIGNUM_SET_SIGN(x, !hibits);
if (hibits) {
get2comp(x);
}
@@ -3071,12 +3071,12 @@ twocomp2abs_bang(VALUE x, int hibits)
static inline VALUE
bigtrunc(VALUE x)
{
- long len = RBIGNUM_LEN(x);
+ long len = BIGNUM_LEN(x);
BDIGIT *ds = BDIGITS(x);
if (len == 0) return x;
while (--len && !ds[len]);
- if (RBIGNUM_LEN(x) > len+1) {
+ if (BIGNUM_LEN(x) > len+1) {
rb_big_resize(x, len+1);
}
return x;
@@ -3085,7 +3085,7 @@ bigtrunc(VALUE x)
static inline VALUE
bigfixize(VALUE x)
{
- size_t n = RBIGNUM_LEN(x);
+ size_t n = BIGNUM_LEN(x);
BDIGIT *ds = BDIGITS(x);
#if SIZEOF_BDIGITS < SIZEOF_LONG
unsigned long u;
@@ -3114,7 +3114,7 @@ bigfixize(VALUE x)
u = ds[0];
#endif
- if (RBIGNUM_POSITIVE_P(x)) {
+ if (BIGNUM_POSITIVE_P(x)) {
if (POSFIXABLE(u)) return LONG2FIX((long)u);
}
else {
@@ -3159,7 +3159,7 @@ rb_uint2big(VALUE n)
i = bdigit_roomof(SIZEOF_VALUE);
while (--i && !digits[i]) ;
- RBIGNUM_SET_LEN(big, i+1);
+ BIGNUM_SET_LEN(big, i+1);
return big;
}
@@ -3179,7 +3179,7 @@ rb_int2big(SIGNED_VALUE n)
}
big = rb_uint2big(u);
if (neg) {
- RBIGNUM_SET_SIGN(big, 0);
+ BIGNUM_SET_SIGN(big, 0);
}
return big;
}
@@ -3262,7 +3262,7 @@ rb_absint_size(VALUE val, int *nlz_bits_ret)
}
else {
dp = BDIGITS(val);
- de = dp + RBIGNUM_LEN(val);
+ de = dp + BIGNUM_LEN(val);
}
while (dp < de && de[-1] == 0)
de--;
@@ -3411,7 +3411,7 @@ rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret)
* represent val in two's complement number, without sign bit.
*
* size_t size;
- * int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : RBIGNUM_NEGATIVE_P(val);
+ * int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : BIGNUM_NEGATIVE_P(val);
* size = rb_absint_numwords(val, 1, NULL)
* if (size == (size_t)-1) ...overflow...
* if (neg && rb_absint_singlebit_p(val))
@@ -3421,7 +3421,7 @@ rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret)
* represent val in two's complement number, with sign bit.
*
* size_t size;
- * int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : RBIGNUM_NEGATIVE_P(val);
+ * int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : BIGNUM_NEGATIVE_P(val);
* int nlz_bits;
* size = rb_absint_size(val, &nlz_bits);
* if (nlz_bits == 0 && !(neg && rb_absint_singlebit_p(val)))
@@ -3458,7 +3458,7 @@ rb_absint_singlebit_p(VALUE val)
}
else {
dp = BDIGITS(val);
- de = dp + RBIGNUM_LEN(val);
+ de = dp + BIGNUM_LEN(val);
}
while (dp < de && de[-1] == 0)
de--;
@@ -3562,9 +3562,9 @@ rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t
num_bdigits = numberof(fixbuf);
}
else {
- sign = RBIGNUM_POSITIVE_P(val) ? 1 : -1;
+ sign = BIGNUM_POSITIVE_P(val) ? 1 : -1;
ds = BDIGITS(val);
- num_bdigits = RBIGNUM_LEN(val);
+ num_bdigits = BIGNUM_LEN(val);
}
return bary_pack(sign, ds, num_bdigits, words, numwords, wordsize, nails, flags);
@@ -3677,9 +3677,9 @@ rb_integer_unpack(const void *words, size_t numwords, size_t wordsize, size_t na
}
if ((flags & INTEGER_PACK_FORCE_BIGNUM) && sign != 0 &&
- bary_zero_p(BDIGITS(val), RBIGNUM_LEN(val)))
+ bary_zero_p(BDIGITS(val), BIGNUM_LEN(val)))
sign = 0;
- RBIGNUM_SET_SIGN(val, 0 <= sign);
+ BIGNUM_SET_SIGN(val, 0 <= sign);
if (flags & INTEGER_PACK_FORCE_BIGNUM)
return bigtrunc(val);
@@ -3871,11 +3871,11 @@ str2big_karatsuba(
for (unit = 2; unit < num_bdigits; unit *= 2) {
for (i = 0; i < num_bdigits; i += unit*2) {
if (2*unit <= num_bdigits - i) {
- bary_mul(vds+i, unit*2, BDIGITS(powerv), RBIGNUM_LEN(powerv), uds+i+unit, unit);
+ bary_mul(vds+i, unit*2, BDIGITS(powerv), BIGNUM_LEN(powerv), uds+i+unit, unit);
bary_add(vds+i, unit*2, vds+i, unit*2, uds+i, unit);
}
else if (unit <= num_bdigits - i) {
- bary_mul(vds+i, num_bdigits-i, BDIGITS(powerv), RBIGNUM_LEN(powerv), uds+i+unit, num_bdigits-(i+unit));
+ bary_mul(vds+i, num_bdigits-i, BDIGITS(powerv), BIGNUM_LEN(powerv), uds+i+unit, num_bdigits-(i+unit));
bary_add(vds+i, num_bdigits-i, vds+i, num_bdigits-i, uds+i, unit);
}
else {
@@ -4069,7 +4069,7 @@ rb_cstr_to_inum(const char *str, int base, int badcheck)
}
else {
VALUE big = rb_uint2big(val);
- RBIGNUM_SET_SIGN(big, sign);
+ BIGNUM_SET_SIGN(big, sign);
return bignorm(big);
}
}
@@ -4311,7 +4311,7 @@ rb_ull2big(unsigned LONG_LONG n)
i = bdigit_roomof(SIZEOF_LONG_LONG);
while (i-- && !digits[i]) ;
- RBIGNUM_SET_LEN(big, i+1);
+ BIGNUM_SET_LEN(big, i+1);
return big;
}
@@ -4331,7 +4331,7 @@ rb_ll2big(LONG_LONG n)
}
big = rb_ull2big(u);
if (neg) {
- RBIGNUM_SET_SIGN(big, 0);
+ BIGNUM_SET_SIGN(big, 0);
}
return big;
}
@@ -4379,8 +4379,8 @@ big_shift3(VALUE x, int lshift_p, size_t shift_numdigits, int shift_numbits)
}
s1 = shift_numdigits;
s2 = shift_numbits;
- xn = RBIGNUM_LEN(x);
- z = bignew(xn+s1+1, RBIGNUM_SIGN(x));
+ xn = BIGNUM_LEN(x);
+ z = bignew(xn+s1+1, BIGNUM_SIGN(x));
zds = BDIGITS(z);
BDIGITS_ZERO(zds, s1);
xds = BDIGITS(x);
@@ -4389,9 +4389,9 @@ big_shift3(VALUE x, int lshift_p, size_t shift_numdigits, int shift_numbits)
else {
long zn;
BDIGIT hibitsx;
- if (LONG_MAX < shift_numdigits || (size_t)RBIGNUM_LEN(x) <= shift_numdigits) {
- if (RBIGNUM_POSITIVE_P(x) ||
- bary_zero_p(BDIGITS(x), RBIGNUM_LEN(x)))
+ if (LONG_MAX < shift_numdigits || (size_t)BIGNUM_LEN(x) <= shift_numdigits) {
+ if (BIGNUM_POSITIVE_P(x) ||
+ bary_zero_p(BDIGITS(x), BIGNUM_LEN(x)))
return INT2FIX(0);
else
return INT2FIX(-1);
@@ -4438,7 +4438,7 @@ big_shift2(VALUE x, int lshift_p, VALUE y)
}
else {
if (1 < sign || CHAR_BIT <= lens[1])
- return RBIGNUM_POSITIVE_P(x) ? INT2FIX(0) : INT2FIX(-1);
+ return BIGNUM_POSITIVE_P(x) ? INT2FIX(0) : INT2FIX(-1);
}
shift_numbits = (int)(lens[0] & (BITSPERDIG-1));
shift_numdigits = (lens[0] >> bit_length(BITSPERDIG-1)) |
@@ -4627,7 +4627,7 @@ big2str_karatsuba(struct big2str_struct *b2s, BDIGIT *xds, size_t xn, size_t wn,
lower_power_level = power_level-1;
b = power_cache_get_power(b2s->base, lower_power_level, &lower_numdigits);
- bn = RBIGNUM_LEN(b);
+ bn = BIGNUM_LEN(b);
bds = BDIGITS(b);
half_numdigits = lower_numdigits;
@@ -4637,7 +4637,7 @@ big2str_karatsuba(struct big2str_struct *b2s, BDIGIT *xds, size_t xn, size_t wn,
(xn == bn && bary_cmp(xds, xn, bds, bn) < 0))) {
lower_power_level--;
b = power_cache_get_power(b2s->base, lower_power_level, &lower_numdigits);
- bn = RBIGNUM_LEN(b);
+ bn = BIGNUM_LEN(b);
bds = BDIGITS(b);
}
@@ -4710,12 +4710,12 @@ big2str_base_poweroftwo(VALUE x, int base)
VALUE result;
char *ptr;
numwords = rb_absint_numwords(x, word_numbits, NULL);
- if (RBIGNUM_NEGATIVE_P(x)) {
+ if (BIGNUM_NEGATIVE_P(x)) {
if (LONG_MAX-1 < numwords)
rb_raise(rb_eArgError, "too big number");
result = rb_usascii_str_new(0, 1+numwords);
ptr = RSTRING_PTR(result);
- *ptr++ = RBIGNUM_POSITIVE_P(x) ? '+' : '-';
+ *ptr++ = BIGNUM_POSITIVE_P(x) ? '+' : '-';
}
else {
if (LONG_MAX < numwords)
@@ -4749,7 +4749,7 @@ big2str_generic(VALUE x, int base)
VALUE power;
xds = BDIGITS(x);
- xn = RBIGNUM_LEN(x);
+ xn = BIGNUM_LEN(x);
BARY_TRUNC(xds, xn);
if (xn == 0) {
@@ -4766,13 +4766,13 @@ big2str_generic(VALUE x, int base)
power_level = 0;
power = power_cache_get_power(base, power_level, NULL);
while (power_level < MAX_BASE36_POWER_TABLE_ENTRIES &&
- (size_t)RBIGNUM_LEN(power) <= (xn+1)/2) {
+ (size_t)BIGNUM_LEN(power) <= (xn+1)/2) {
power_level++;
power = power_cache_get_power(base, power_level, NULL);
}
assert(power_level != MAX_BASE36_POWER_TABLE_ENTRIES);
- if ((size_t)RBIGNUM_LEN(power) <= xn) {
+ if ((size_t)BIGNUM_LEN(power) <= xn) {
/*
* This increment guarantees x < power_cache_get_power(base, power_level)
* without invoking it actually.
@@ -4786,7 +4786,7 @@ big2str_generic(VALUE x, int base)
power_level++;
}
- b2s_data.negative = RBIGNUM_NEGATIVE_P(x);
+ b2s_data.negative = BIGNUM_NEGATIVE_P(x);
b2s_data.base = base;
b2s_data.hbase2 = maxpow_in_bdigit_dbl(base, &b2s_data.hbase2_numdigits);
@@ -4800,7 +4800,7 @@ big2str_generic(VALUE x, int base)
VALUE tmpw = 0;
BDIGIT *wds;
size_t wn;
- wn = power_level * BIGDIVREM_EXTRA_WORDS + RBIGNUM_LEN(power);
+ wn = power_level * BIGDIVREM_EXTRA_WORDS + BIGNUM_LEN(power);
wds = ALLOCV_N(BDIGIT, tmpw, xn + wn);
MEMCPY(wds, xds, BDIGIT, xn);
big2str_karatsuba(&b2s_data, wds, xn, wn, power_level, 0);
@@ -4831,14 +4831,14 @@ big2str_gmp(VALUE x, int base)
size_t size;
VALUE str;
BDIGIT *xds = BDIGITS(x);
- size_t xn = RBIGNUM_LEN(x);
+ size_t xn = BIGNUM_LEN(x);
mpz_init(mx);
mpz_import(mx, xn, -1, sizeof(BDIGIT), 0, nails, xds);
size = mpz_sizeinbase(mx, base);
- if (RBIGNUM_NEGATIVE_P(x)) {
+ if (BIGNUM_NEGATIVE_P(x)) {
mpz_neg(mx, mx);
str = rb_usascii_str_new(0, size+1);
}
@@ -4875,7 +4875,7 @@ rb_big2str1(VALUE x, int base)
bigtrunc(x);
xds = BDIGITS(x);
- xn = RBIGNUM_LEN(x);
+ xn = BIGNUM_LEN(x);
BARY_TRUNC(xds, xn);
if (xn == 0) {
@@ -4941,7 +4941,7 @@ rb_big_to_s(int argc, VALUE *argv, VALUE x)
static unsigned long
big2ulong(VALUE x, const char *type)
{
- long len = RBIGNUM_LEN(x);
+ long len = BIGNUM_LEN(x);
unsigned long num;
BDIGIT *ds;
@@ -4968,7 +4968,7 @@ rb_big2ulong(VALUE x)
{
unsigned long num = big2ulong(x, "unsigned long");
- if (RBIGNUM_POSITIVE_P(x)) {
+ if (BIGNUM_POSITIVE_P(x)) {
return num;
}
else {
@@ -4985,7 +4985,7 @@ rb_big2long(VALUE x)
{
unsigned long num = big2ulong(x, "long");
- if (RBIGNUM_POSITIVE_P(x)) {
+ if (BIGNUM_POSITIVE_P(x)) {
if (num <= LONG_MAX)
return num;
}
@@ -5003,7 +5003,7 @@ rb_big2long(VALUE x)
static unsigned LONG_LONG
big2ull(VALUE x, const char *type)
{
- long len = RBIGNUM_LEN(x);
+ long len = BIGNUM_LEN(x);
unsigned LONG_LONG num;
BDIGIT *ds = BDIGITS(x);
@@ -5028,7 +5028,7 @@ rb_big2ull(VALUE x)
{
unsigned LONG_LONG num = big2ull(x, "unsigned long long");
- if (RBIGNUM_POSITIVE_P(x)) {
+ if (BIGNUM_POSITIVE_P(x)) {
return num;
}
else {
@@ -5045,7 +5045,7 @@ rb_big2ll(VALUE x)
{
unsigned LONG_LONG num = big2ull(x, "long long");
- if (RBIGNUM_POSITIVE_P(x)) {
+ if (BIGNUM_POSITIVE_P(x)) {
if (num <= LLONG_MAX)
return num;
}
@@ -5102,7 +5102,7 @@ static double
big2dbl(VALUE x)
{
double d = 0.0;
- long i = (bigtrunc(x), RBIGNUM_LEN(x)), lo = 0, bits;
+ long i = (bigtrunc(x), BIGNUM_LEN(x)), lo = 0, bits;
BDIGIT *ds = BDIGITS(x), dl;
if (i) {
@@ -5144,7 +5144,7 @@ big2dbl(VALUE x)
}
}
}
- if (!RBIGNUM_SIGN(x)) d = -d;
+ if (!BIGNUM_SIGN(x)) d = -d;
return d;
}
@@ -5285,7 +5285,7 @@ rb_big_cmp(VALUE x, VALUE y)
return INT2FIX(0);
}
else {
- if (RBIGNUM_NEGATIVE_P(x)) return INT2FIX(-1);
+ if (BIGNUM_NEGATIVE_P(x)) return INT2FIX(-1);
return INT2FIX(1);
}
}
@@ -5298,11 +5298,11 @@ rb_big_cmp(VALUE x, VALUE y)
return rb_num_coerce_cmp(x, y, rb_intern("<=>"));
}
- if (RBIGNUM_SIGN(x) > RBIGNUM_SIGN(y)) return INT2FIX(1);
- if (RBIGNUM_SIGN(x) < RBIGNUM_SIGN(y)) return INT2FIX(-1);
+ if (BIGNUM_SIGN(x) > BIGNUM_SIGN(y)) return INT2FIX(1);
+ if (BIGNUM_SIGN(x) < BIGNUM_SIGN(y)) return INT2FIX(-1);
- cmp = bary_cmp(BDIGITS(x), RBIGNUM_LEN(x), BDIGITS(y), RBIGNUM_LEN(y));
- if (RBIGNUM_SIGN(x))
+ cmp = bary_cmp(BDIGITS(x), BIGNUM_LEN(x), BDIGITS(y), BIGNUM_LEN(y));
+ if (BIGNUM_SIGN(x))
return INT2FIX(cmp);
else
return INT2FIX(-cmp);
@@ -5432,9 +5432,9 @@ rb_big_eq(VALUE x, VALUE y)
else {
return rb_equal(y, x);
}
- if (RBIGNUM_SIGN(x) != RBIGNUM_SIGN(y)) return Qfalse;
- if (RBIGNUM_LEN(x) != RBIGNUM_LEN(y)) return Qfalse;
- if (MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,RBIGNUM_LEN(y)) != 0) return Qfalse;
+ if (BIGNUM_SIGN(x) != BIGNUM_SIGN(y)) return Qfalse;
+ if (BIGNUM_LEN(x) != BIGNUM_LEN(y)) return Qfalse;
+ if (MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,BIGNUM_LEN(y)) != 0) return Qfalse;
return Qtrue;
}
@@ -5453,9 +5453,9 @@ VALUE
rb_big_eql(VALUE x, VALUE y)
{
if (!RB_BIGNUM_TYPE_P(y)) return Qfalse;
- if (RBIGNUM_SIGN(x) != RBIGNUM_SIGN(y)) return Qfalse;
- if (RBIGNUM_LEN(x) != RBIGNUM_LEN(y)) return Qfalse;
- if (MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,RBIGNUM_LEN(y)) != 0) return Qfalse;
+ if (BIGNUM_SIGN(x) != BIGNUM_SIGN(y)) return Qfalse;
+ if (BIGNUM_LEN(x) != BIGNUM_LEN(y)) return Qfalse;
+ if (MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,BIGNUM_LEN(y)) != 0) return Qfalse;
return Qtrue;
}
@@ -5471,7 +5471,7 @@ rb_big_uminus(VALUE x)
{
VALUE z = rb_big_clone(x);
- RBIGNUM_SET_SIGN(z, !RBIGNUM_SIGN(x));
+ BIGNUM_SET_SIGN(z, !BIGNUM_SIGN(x));
return bignorm(z);
}
@@ -5493,22 +5493,22 @@ rb_big_neg(VALUE x)
{
VALUE z = rb_big_clone(x);
BDIGIT *ds = BDIGITS(z);
- long n = RBIGNUM_LEN(z);
+ long n = BIGNUM_LEN(z);
if (!n) return INT2FIX(-1);
- if (RBIGNUM_POSITIVE_P(z)) {
+ if (BIGNUM_POSITIVE_P(z)) {
if (bary_add_one(ds, n)) {
big_extend_carry(z);
}
- RBIGNUM_SET_NEGATIVE_SIGN(z);
+ BIGNUM_SET_NEGATIVE_SIGN(z);
}
else {
bary_neg(ds, n);
if (bary_add_one(ds, n))
return INT2FIX(-1);
bary_neg(ds, n);
- RBIGNUM_SET_POSITIVE_SIGN(z);
+ BIGNUM_SET_POSITIVE_SIGN(z);
}
return bignorm(z);
@@ -5521,8 +5521,8 @@ bigsub(VALUE x, VALUE y)
BDIGIT *xds, *yds, *zds;
long xn, yn, zn;
- xn = RBIGNUM_LEN(x);
- yn = RBIGNUM_LEN(y);
+ xn = BIGNUM_LEN(x);
+ yn = BIGNUM_LEN(y);
zn = xn < yn ? yn : xn;
z = bignew(zn, 1);
@@ -5533,7 +5533,7 @@ bigsub(VALUE x, VALUE y)
if (bary_sub(zds, zn, xds, xn, yds, yn)) {
bary_2comp(zds, zn);
- RBIGNUM_SET_NEGATIVE_SIGN(z);
+ BIGNUM_SET_NEGATIVE_SIGN(z);
}
return z;
@@ -5552,7 +5552,7 @@ bigsub_int(VALUE x, long y0)
y = y0;
xds = BDIGITS(x);
- xn = RBIGNUM_LEN(x);
+ xn = BIGNUM_LEN(x);
if (xn == 0)
return LONG2NUM(-y0);
@@ -5562,14 +5562,14 @@ bigsub_int(VALUE x, long y0)
if (zn < bdigit_roomof(SIZEOF_LONG))
zn = bdigit_roomof(SIZEOF_LONG);
#endif
- z = bignew(zn, RBIGNUM_SIGN(x));
+ z = bignew(zn, BIGNUM_SIGN(x));
zds = BDIGITS(z);
#if SIZEOF_BDIGITS >= SIZEOF_LONG
assert(xn == zn);
num = (BDIGIT_DBL_SIGNED)xds[0] - y;
if (xn == 1 && num < 0) {
- RBIGNUM_SET_SIGN(z, !RBIGNUM_SIGN(x));
+ BIGNUM_SET_SIGN(z, !BIGNUM_SIGN(x));
zds[0] = (BDIGIT)-num;
RB_GC_GUARD(x);
return bignorm(z);
@@ -5632,7 +5632,7 @@ bigsub_int(VALUE x, long y0)
assert(num == 0 || num == -1);
if (num < 0) {
get2comp(z);
- RBIGNUM_SET_SIGN(z, !RBIGNUM_SIGN(x));
+ BIGNUM_SET_SIGN(z, !BIGNUM_SIGN(x));
}
RB_GC_GUARD(x);
return bignorm(z);
@@ -5648,7 +5648,7 @@ bigadd_int(VALUE x, long y)
long i;
xds = BDIGITS(x);
- xn = RBIGNUM_LEN(x);
+ xn = BIGNUM_LEN(x);
if (xn == 0)
return LONG2NUM(y);
@@ -5660,7 +5660,7 @@ bigadd_int(VALUE x, long y)
#endif
zn++;
- z = bignew(zn, RBIGNUM_SIGN(x));
+ z = bignew(zn, BIGNUM_SIGN(x));
zds = BDIGITS(z);
#if SIZEOF_BDIGITS >= SIZEOF_LONG
@@ -5727,23 +5727,23 @@ bigadd(VALUE x, VALUE y, int sign)
VALUE z;
long len;
- sign = (sign == RBIGNUM_SIGN(y));
- if (RBIGNUM_SIGN(x) != sign) {
+ sign = (sign == BIGNUM_SIGN(y));
+ if (BIGNUM_SIGN(x) != sign) {
if (sign) return bigsub(y, x);
return bigsub(x, y);
}
- if (RBIGNUM_LEN(x) > RBIGNUM_LEN(y)) {
- len = RBIGNUM_LEN(x) + 1;
+ if (BIGNUM_LEN(x) > BIGNUM_LEN(y)) {
+ len = BIGNUM_LEN(x) + 1;
}
else {
- len = RBIGNUM_LEN(y) + 1;
+ len = BIGNUM_LEN(y) + 1;
}
z = bignew(len, sign);
- bary_add(BDIGITS(z), RBIGNUM_LEN(z),
- BDIGITS(x), RBIGNUM_LEN(x),
- BDIGITS(y), RBIGNUM_LEN(y));
+ bary_add(BDIGITS(z), BIGNUM_LEN(z),
+ BDIGITS(x), BIGNUM_LEN(x),
+ BDIGITS(y), BIGNUM_LEN(y));
return z;
}
@@ -5762,7 +5762,7 @@ rb_big_plus(VALUE x, VALUE y)
if (FIXNUM_P(y)) {
n = FIX2LONG(y);
- if ((n > 0) != RBIGNUM_SIGN(x)) {
+ if ((n > 0) != BIGNUM_SIGN(x)) {
if (n < 0) {
n = -n;
}
@@ -5798,7 +5798,7 @@ rb_big_minus(VALUE x, VALUE y)
if (FIXNUM_P(y)) {
n = FIX2LONG(y);
- if ((n > 0) != RBIGNUM_SIGN(x)) {
+ if ((n > 0) != BIGNUM_SIGN(x)) {
if (n < 0) {
n = -n;
}
@@ -5827,7 +5827,7 @@ bigsq(VALUE x)
VALUE z;
BDIGIT *xds, *zds;
- xn = RBIGNUM_LEN(x);
+ xn = BIGNUM_LEN(x);
zn = 2 * xn;
z = bignew(zn, 1);
@@ -5861,11 +5861,11 @@ bigmul0(VALUE x, VALUE y)
if (x == y)
return bigsq(x);
- xn = RBIGNUM_LEN(x);
- yn = RBIGNUM_LEN(y);
+ xn = BIGNUM_LEN(x);
+ yn = BIGNUM_LEN(y);
zn = xn + yn;
- z = bignew(zn, RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
+ z = bignew(zn, BIGNUM_SIGN(x)==BIGNUM_SIGN(y));
xds = BDIGITS(x);
yds = BDIGITS(y);
@@ -5906,7 +5906,7 @@ rb_big_mul(VALUE x, VALUE y)
static VALUE
bigdivrem(VALUE x, VALUE y, volatile VALUE *divp, volatile VALUE *modp)
{
- long xn = RBIGNUM_LEN(x), yn = RBIGNUM_LEN(y);
+ long xn = BIGNUM_LEN(x), yn = BIGNUM_LEN(y);
VALUE z;
BDIGIT *xds, *yds, *zds;
BDIGIT dd;
@@ -5930,12 +5930,12 @@ bigdivrem(VALUE x, VALUE y, volatile VALUE *divp, volatile VALUE *modp)
}
if (yn == 1) {
dd = yds[0];
- z = bignew(xn, RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
+ z = bignew(xn, BIGNUM_SIGN(x)==BIGNUM_SIGN(y));
zds = BDIGITS(z);
dd = bigdivrem_single(zds, xds, xn, dd);
if (modp) {
*modp = rb_uint2big((VALUE)dd);
- RBIGNUM_SET_SIGN(*modp, RBIGNUM_SIGN(x));
+ BIGNUM_SET_SIGN(*modp, BIGNUM_SIGN(x));
}
if (divp) *divp = z;
return Qnil;
@@ -5946,14 +5946,14 @@ bigdivrem(VALUE x, VALUE y, volatile VALUE *divp, volatile VALUE *modp)
BDIGIT_DBL q0 = x0 / y0;
BDIGIT_DBL r0 = x0 % y0;
if (divp) {
- z = bignew(bdigit_roomof(sizeof(BDIGIT_DBL)), RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
+ z = bignew(bdigit_roomof(sizeof(BDIGIT_DBL)), BIGNUM_SIGN(x)==BIGNUM_SIGN(y));
zds = BDIGITS(z);
zds[0] = BIGLO(q0);
zds[1] = BIGLO(BIGDN(q0));
*divp = z;
}
if (modp) {
- z = bignew(bdigit_roomof(sizeof(BDIGIT_DBL)), RBIGNUM_SIGN(x));
+ z = bignew(bdigit_roomof(sizeof(BDIGIT_DBL)), BIGNUM_SIGN(x));
zds = BDIGITS(z);
zds[0] = BIGLO(r0);
zds[1] = BIGLO(BIGDN(r0));
@@ -5964,7 +5964,7 @@ bigdivrem(VALUE x, VALUE y, volatile VALUE *divp, volatile VALUE *modp)
if (divp) {
qn = xn + BIGDIVREM_EXTRA_WORDS;
- q = bignew(qn, RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
+ q = bignew(qn, BIGNUM_SIGN(x)==BIGNUM_SIGN(y));
qds = BDIGITS(q);
}
else {
@@ -5974,7 +5974,7 @@ bigdivrem(VALUE x, VALUE y, volatile VALUE *divp, volatile VALUE *modp)
if (modp) {
rn = yn;
- r = bignew(rn, RBIGNUM_SIGN(x));
+ r = bignew(rn, BIGNUM_SIGN(x));
rds = BDIGITS(r);
}
else {
@@ -6002,7 +6002,7 @@ bigdivmod(VALUE x, VALUE y, volatile VALUE *divp, volatile VALUE *modp)
VALUE mod;
bigdivrem(x, y, divp, &mod);
- if (RBIGNUM_SIGN(x) != RBIGNUM_SIGN(y) && !BIGZEROP(mod)) {
+ if (BIGNUM_SIGN(x) != BIGNUM_SIGN(y) && !BIGZEROP(mod)) {
if (divp) *divp = bigadd(*divp, rb_int2big(1), 0);
if (modp) *modp = bigadd(mod, y, 1);
}
@@ -6159,7 +6159,7 @@ big_fdiv(VALUE x, VALUE y, long ey)
long l, ex;
bigtrunc(x);
- l = RBIGNUM_LEN(x);
+ l = BIGNUM_LEN(x);
ex = l * BITSPERDIG - nlz(BDIGITS(x)[l-1]);
ex -= 2 * DBL_BIGDIG * BITSPERDIG;
if (ex) x = big_shift(x, ex);
@@ -6181,7 +6181,7 @@ big_fdiv_int(VALUE x, VALUE y)
{
long l, ey;
bigtrunc(y);
- l = RBIGNUM_LEN(y);
+ l = BIGNUM_LEN(y);
ey = l * BITSPERDIG - nlz(BDIGITS(y)[l-1]);
ey -= DBL_BIGDIG * BITSPERDIG;
if (ey) y = big_shift(y, ey);
@@ -6261,7 +6261,7 @@ rb_big_pow(VALUE x, VALUE y)
if (y == INT2FIX(0)) return INT2FIX(1);
if (RB_FLOAT_TYPE_P(y)) {
d = RFLOAT_VALUE(y);
- if ((!RBIGNUM_SIGN(x) && !BIGZEROP(x)) && d != round(d))
+ if ((!BIGNUM_SIGN(x) && !BIGZEROP(x)) && d != round(d))
return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y);
}
else if (RB_BIGNUM_TYPE_P(y)) {
@@ -6432,7 +6432,7 @@ bigor_int(VALUE x, long xn, BDIGIT hibitsx, long y)
hibitsy = 0 <= y ? 0 : BDIGMAX;
xds = BDIGITS(x);
- zn = RBIGNUM_LEN(x);
+ zn = BIGNUM_LEN(x);
#if SIZEOF_BDIGITS < SIZEOF_LONG
if (zn < bdigit_roomof(SIZEOF_LONG))
zn = bdigit_roomof(SIZEOF_LONG);
@@ -6555,7 +6555,7 @@ bigxor_int(VALUE x, long xn, BDIGIT hibitsx, long y)
hibitsy = 0 <= y ? 0 : BDIGMAX;
xds = BDIGITS(x);
- zn = RBIGNUM_LEN(x);
+ zn = BIGNUM_LEN(x);
#if SIZEOF_BDIGITS < SIZEOF_LONG
if (zn < bdigit_roomof(SIZEOF_LONG))
zn = bdigit_roomof(SIZEOF_LONG);
@@ -6744,12 +6744,12 @@ rb_big_aref(VALUE x, VALUE y)
BDIGIT bit;
if (RB_BIGNUM_TYPE_P(y)) {
- if (!RBIGNUM_SIGN(y))
+ if (!BIGNUM_SIGN(y))
return INT2FIX(0);
bigtrunc(y);
if (BIGSIZE(y) > sizeof(long)) {
out_of_range:
- return RBIGNUM_SIGN(x) ? INT2FIX(0) : INT2FIX(1);
+ return BIGNUM_SIGN(x) ? INT2FIX(0) : INT2FIX(1);
}
shift = big2ulong(y, "long");
}
@@ -6762,10 +6762,10 @@ rb_big_aref(VALUE x, VALUE y)
s2 = shift%BITSPERDIG;
bit = (BDIGIT)1 << s2;
- if (s1 >= RBIGNUM_LEN(x)) goto out_of_range;
+ if (s1 >= BIGNUM_LEN(x)) goto out_of_range;
xds = BDIGITS(x);
- if (RBIGNUM_POSITIVE_P(x))
+ if (BIGNUM_POSITIVE_P(x))
return (xds[s1] & bit) ? INT2FIX(1) : INT2FIX(0);
if (xds[s1] & (bit-1))
return (xds[s1] & bit) ? INT2FIX(0) : INT2FIX(1);
@@ -6787,7 +6787,7 @@ rb_big_hash(VALUE x)
{
st_index_t hash;
- hash = rb_memhash(BDIGITS(x), sizeof(BDIGIT)*RBIGNUM_LEN(x)) ^ RBIGNUM_SIGN(x);
+ hash = rb_memhash(BDIGITS(x), sizeof(BDIGIT)*BIGNUM_LEN(x)) ^ BIGNUM_SIGN(x);
return INT2FIX(hash);
}
@@ -6831,9 +6831,9 @@ rb_big_coerce(VALUE x, VALUE y)
static VALUE
rb_big_abs(VALUE x)
{
- if (!RBIGNUM_SIGN(x)) {
+ if (!BIGNUM_SIGN(x)) {
x = rb_big_clone(x);
- RBIGNUM_SET_SIGN(x, 1);
+ BIGNUM_SET_SIGN(x, 1);
}
return x;
}
@@ -6910,7 +6910,7 @@ rb_big_bit_length(VALUE big)
if (numbytes == 0)
return LONG2FIX(0);
- if (RBIGNUM_NEGATIVE_P(big) && rb_absint_singlebit_p(big)) {
+ if (BIGNUM_NEGATIVE_P(big) && rb_absint_singlebit_p(big)) {
if (nlz_bits != CHAR_BIT-1) {
nlz_bits++;
}
@@ -6945,7 +6945,7 @@ rb_big_bit_length(VALUE big)
static VALUE
rb_big_odd_p(VALUE num)
{
- if (RBIGNUM_LEN(num) != 0 && BDIGITS(num)[0] & 1) {
+ if (BIGNUM_LEN(num) != 0 && BDIGITS(num)[0] & 1) {
return Qtrue;
}
return Qfalse;
@@ -6961,7 +6961,7 @@ rb_big_odd_p(VALUE num)
static VALUE
rb_big_even_p(VALUE num)
{
- if (RBIGNUM_LEN(num) != 0 && BDIGITS(num)[0] & 1) {
+ if (BIGNUM_LEN(num) != 0 && BDIGITS(num)[0] & 1) {
return Qfalse;
}
return Qtrue;
diff --git a/ext/-test-/bignum/bigzero.c b/ext/-test-/bignum/bigzero.c
index 21f8a33..a3bf8af 100644
--- a/ext/-test-/bignum/bigzero.c
+++ b/ext/-test-/bignum/bigzero.c
@@ -6,7 +6,7 @@ bug_big_zero(VALUE self, VALUE length)
{
long len = NUM2ULONG(length);
VALUE z = rb_big_new(len, 1);
- MEMZERO(RBIGNUM_DIGITS(z), BDIGIT, len);
+ MEMZERO(BIGNUM_DIGITS(z), BDIGIT, len);
return z;
}
@@ -15,7 +15,7 @@ bug_big_negzero(VALUE self, VALUE length)
{
long len = NUM2ULONG(length);
VALUE z = rb_big_new(len, 0);
- MEMZERO(RBIGNUM_DIGITS(z), BDIGIT, len);
+ MEMZERO(BIGNUM_DIGITS(z), BDIGIT, len);
return z;
}
diff --git a/ext/-test-/bignum/intpack.c b/ext/-test-/bignum/intpack.c
index 0302319..b7435b2 100644
--- a/ext/-test-/bignum/intpack.c
+++ b/ext/-test-/bignum/intpack.c
@@ -49,7 +49,7 @@ static VALUE
rb_integer_test_numbits_2comp_without_sign(VALUE val)
{
size_t size;
- int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : RBIGNUM_NEGATIVE_P(val);
+ int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : BIGNUM_NEGATIVE_P(val);
size = rb_absint_numwords(val, 1, NULL) - (neg && rb_absint_singlebit_p(val));
return SIZET2NUM(size);
}
@@ -57,7 +57,7 @@ rb_integer_test_numbits_2comp_without_sign(VALUE val)
static VALUE
rb_integer_test_numbytes_2comp_with_sign(VALUE val)
{
- int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : RBIGNUM_NEGATIVE_P(val);
+ int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : BIGNUM_NEGATIVE_P(val);
int nlz_bits;
size_t size = rb_absint_size(val, &nlz_bits);
if (nlz_bits == 0 && !(neg && rb_absint_singlebit_p(val)))
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index ffc6613..ef9debf 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -86,8 +86,8 @@ static ID id_eq;
#define DBLE_FIG (DBL_DIG+1) /* figure of double */
#endif
-#ifndef RBIGNUM_ZERO_P
-# define RBIGNUM_ZERO_P(x) rb_bigzero_p(x)
+#ifndef BIGNUM_ZERO_P
+# define BIGNUM_ZERO_P(x) rb_bigzero_p(x)
#endif
#ifndef RRATIONAL_ZERO_P
diff --git a/gc.c b/gc.c
index 265767e..763a0d3 100644
--- a/gc.c
+++ b/gc.c
@@ -1612,8 +1612,8 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
break;
case T_BIGNUM:
- if (!(RBASIC(obj)->flags & RBIGNUM_EMBED_FLAG) && RBIGNUM_DIGITS(obj)) {
- xfree(RBIGNUM_DIGITS(obj));
+ if (!(RBASIC(obj)->flags & BIGNUM_EMBED_FLAG) && BIGNUM_DIGITS(obj)) {
+ xfree(BIGNUM_DIGITS(obj));
}
break;
case T_NODE:
@@ -2506,8 +2506,8 @@ obj_memsize_of(VALUE obj, int use_tdata)
break;
case T_BIGNUM:
- if (!(RBASIC(obj)->flags & RBIGNUM_EMBED_FLAG) && RBIGNUM_DIGITS(obj)) {
- size += RBIGNUM_LEN(obj) * sizeof(BDIGIT);
+ if (!(RBASIC(obj)->flags & BIGNUM_EMBED_FLAG) && BIGNUM_DIGITS(obj)) {
+ size += BIGNUM_LEN(obj) * sizeof(BDIGIT);
}
break;
case T_NODE:
diff --git a/internal.h b/internal.h
index a3b4045..18dbef2 100644
--- a/internal.h
+++ b/internal.h
@@ -305,12 +305,12 @@ struct method_table_wrapper {
size_t serial;
};
-#define RBIGNUM_EMBED_LEN_NUMBITS 3
-#ifndef RBIGNUM_EMBED_LEN_MAX
-# if (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT) < (1 << RBIGNUM_EMBED_LEN_NUMBITS)-1
-# define RBIGNUM_EMBED_LEN_MAX (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT)
+#define BIGNUM_EMBED_LEN_NUMBITS 3
+#ifndef BIGNUM_EMBED_LEN_MAX
+# if (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT) < (1 << BIGNUM_EMBED_LEN_NUMBITS)-1
+# define BIGNUM_EMBED_LEN_MAX (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT)
# else
-# define RBIGNUM_EMBED_LEN_MAX ((1 << RBIGNUM_EMBED_LEN_NUMBITS)-1)
+# define BIGNUM_EMBED_LEN_MAX ((1 << BIGNUM_EMBED_LEN_NUMBITS)-1)
# endif
#endif
@@ -321,32 +321,32 @@ struct RBignum {
long len;
BDIGIT *digits;
} heap;
- BDIGIT ary[RBIGNUM_EMBED_LEN_MAX];
+ BDIGIT ary[BIGNUM_EMBED_LEN_MAX];
} as;
};
-#define RBIGNUM_SIGN_BIT FL_USER1
+#define BIGNUM_SIGN_BIT FL_USER1
/* sign: positive:1, negative:0 */
-#define RBIGNUM_SIGN(b) ((RBASIC(b)->flags & RBIGNUM_SIGN_BIT) != 0)
-#define RBIGNUM_SET_SIGN(b,sign) \
- ((sign) ? (RBASIC(b)->flags |= RBIGNUM_SIGN_BIT) \
- : (RBASIC(b)->flags &= ~RBIGNUM_SIGN_BIT))
-#define RBIGNUM_POSITIVE_P(b) RBIGNUM_SIGN(b)
-#define RBIGNUM_NEGATIVE_P(b) (!RBIGNUM_SIGN(b))
-
-#define RBIGNUM_EMBED_FLAG FL_USER2
-#define RBIGNUM_EMBED_LEN_MASK (FL_USER5|FL_USER4|FL_USER3)
-#define RBIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+RBIGNUM_EMBED_LEN_NUMBITS)
-#define RBIGNUM_LEN(b) \
- ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
- (long)((RBASIC(b)->flags >> RBIGNUM_EMBED_LEN_SHIFT) & \
- (RBIGNUM_EMBED_LEN_MASK >> RBIGNUM_EMBED_LEN_SHIFT)) : \
+#define BIGNUM_SIGN(b) ((RBASIC(b)->flags & BIGNUM_SIGN_BIT) != 0)
+#define BIGNUM_SET_SIGN(b,sign) \
+ ((sign) ? (RBASIC(b)->flags |= BIGNUM_SIGN_BIT) \
+ : (RBASIC(b)->flags &= ~BIGNUM_SIGN_BIT))
+#define BIGNUM_POSITIVE_P(b) BIGNUM_SIGN(b)
+#define BIGNUM_NEGATIVE_P(b) (!BIGNUM_SIGN(b))
+
+#define BIGNUM_EMBED_FLAG FL_USER2
+#define BIGNUM_EMBED_LEN_MASK (FL_USER5|FL_USER4|FL_USER3)
+#define BIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+BIGNUM_EMBED_LEN_NUMBITS)
+#define BIGNUM_LEN(b) \
+ ((RBASIC(b)->flags & BIGNUM_EMBED_FLAG) ? \
+ (long)((RBASIC(b)->flags >> BIGNUM_EMBED_LEN_SHIFT) & \
+ (BIGNUM_EMBED_LEN_MASK >> BIGNUM_EMBED_LEN_SHIFT)) : \
RBIGNUM(b)->as.heap.len)
-/* LSB:RBIGNUM_DIGITS(b)[0], MSB:RBIGNUM_DIGITS(b)[RBIGNUM_LEN(b)-1] */
-#define RBIGNUM_DIGITS(b) \
- ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
+/* LSB:BIGNUM_DIGITS(b)[0], MSB:BIGNUM_DIGITS(b)[BIGNUM_LEN(b)-1] */
+#define BIGNUM_DIGITS(b) \
+ ((RBASIC(b)->flags & BIGNUM_EMBED_FLAG) ? \
RBIGNUM(b)->as.ary : \
RBIGNUM(b)->as.heap.digits)
-#define RBIGNUM_LENINT(b) rb_long2int(RBIGNUM_LEN(b))
+#define BIGNUM_LENINT(b) rb_long2int(BIGNUM_LEN(b))
#define RBIGNUM(obj) (R_CAST(RBignum)(obj))
diff --git a/marshal.c b/marshal.c
index 7e387a8..e469b4e 100644
--- a/marshal.c
+++ b/marshal.c
@@ -764,9 +764,9 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
case T_BIGNUM:
w_byte(TYPE_BIGNUM, arg);
{
- char sign = RBIGNUM_SIGN(obj) ? '+' : '-';
- long len = RBIGNUM_LEN(obj);
- BDIGIT *d = RBIGNUM_DIGITS(obj);
+ char sign = BIGNUM_SIGN(obj) ? '+' : '-';
+ long len = BIGNUM_LEN(obj);
+ BDIGIT *d = BIGNUM_DIGITS(obj);
w_byte(sign, arg);
w_long(SHORTLEN(len), arg); /* w_short? */
diff --git a/math.c b/math.c
index e621d1a..898ccb6 100644
--- a/math.c
+++ b/math.c
@@ -446,7 +446,7 @@ math_log(int argc, VALUE *argv)
rb_scan_args(argc, argv, "11", &x, &base);
- if (RB_BIGNUM_TYPE_P(x) && RBIGNUM_POSITIVE_P(x) &&
+ if (RB_BIGNUM_TYPE_P(x) && BIGNUM_POSITIVE_P(x) &&
DBL_MAX_EXP <= (numbits = rb_absint_numwords(x, 1, NULL))) {
numbits -= DBL_MANT_DIG;
x = rb_big_rshift(x, SIZET2NUM(numbits));
@@ -506,7 +506,7 @@ math_log2(VALUE obj, VALUE x)
double d0, d;
size_t numbits;
- if (RB_BIGNUM_TYPE_P(x) && RBIGNUM_POSITIVE_P(x) &&
+ if (RB_BIGNUM_TYPE_P(x) && BIGNUM_POSITIVE_P(x) &&
DBL_MAX_EXP <= (numbits = rb_absint_numwords(x, 1, NULL))) {
numbits -= DBL_MANT_DIG;
x = rb_big_rshift(x, SIZET2NUM(numbits));
@@ -548,7 +548,7 @@ math_log10(VALUE obj, VALUE x)
double d0, d;
size_t numbits;
- if (RB_BIGNUM_TYPE_P(x) && RBIGNUM_POSITIVE_P(x) &&
+ if (RB_BIGNUM_TYPE_P(x) && BIGNUM_POSITIVE_P(x) &&
DBL_MAX_EXP <= (numbits = rb_absint_numwords(x, 1, NULL))) {
numbits -= DBL_MANT_DIG;
x = rb_big_rshift(x, SIZET2NUM(numbits));
diff --git a/numeric.c b/numeric.c
index 4bb2c3a..838ec43 100644
--- a/numeric.c
+++ b/numeric.c
@@ -145,7 +145,7 @@ rb_num_to_uint(VALUE val, unsigned int *ret)
}
if (RB_TYPE_P(val, T_BIGNUM)) {
- if (RBIGNUM_NEGATIVE_P(val)) return NUMERR_NEGATIVE;
+ if (BIGNUM_NEGATIVE_P(val)) return NUMERR_NEGATIVE;
#if SIZEOF_INT < SIZEOF_LONG
/* long is 64bit */
return NUMERR_TOOLARGE;
@@ -172,7 +172,7 @@ positive_int_p(VALUE num)
}
else if (RB_TYPE_P(num, T_BIGNUM)) {
if (method_basic_p(rb_cBignum))
- return RBIGNUM_POSITIVE_P(num);
+ return BIGNUM_POSITIVE_P(num);
}
return RTEST(rb_funcall(num, mid, 1, INT2FIX(0)));
}
@@ -188,7 +188,7 @@ negative_int_p(VALUE num)
}
else if (RB_TYPE_P(num, T_BIGNUM)) {
if (method_basic_p(rb_cBignum))
- return RBIGNUM_NEGATIVE_P(num);
+ return BIGNUM_NEGATIVE_P(num);
}
return RTEST(rb_funcall(num, mid, 1, INT2FIX(0)));
}
@@ -2066,7 +2066,7 @@ rb_num2ulong_internal(VALUE val, int *wrap_p)
{
unsigned long ul = rb_big2ulong(val);
if (wrap_p)
- *wrap_p = RBIGNUM_NEGATIVE_P(val);
+ *wrap_p = BIGNUM_NEGATIVE_P(val);
return ul;
}
}
@@ -3434,7 +3434,7 @@ fix_aref(VALUE fix, VALUE idx)
if (!FIXNUM_P(idx)) {
idx = rb_big_norm(idx);
if (!FIXNUM_P(idx)) {
- if (!RBIGNUM_SIGN(idx) || val >= 0)
+ if (!BIGNUM_SIGN(idx) || val >= 0)
return INT2FIX(0);
return INT2FIX(1);
}
diff --git a/random.c b/random.c
index e77f56e..23e84ff 100644
--- a/random.c
+++ b/random.c
@@ -938,7 +938,7 @@ rand_int(struct MT *mt, VALUE vmax, int restrictive)
else {
VALUE ret;
if (rb_bigzero_p(vmax)) return Qnil;
- if (!RBIGNUM_SIGN(vmax)) {
+ if (!BIGNUM_SIGN(vmax)) {
if (restrictive) return Qnil;
vmax = rb_big_uminus(vmax);
}
@@ -985,7 +985,7 @@ rand_range(struct MT* mt, VALUE range)
v = ULONG2NUM(r);
}
}
- else if (BUILTIN_TYPE(vmax) == T_BIGNUM && RBIGNUM_SIGN(vmax) && !rb_bigzero_p(vmax)) {
+ else if (BUILTIN_TYPE(vmax) == T_BIGNUM && BIGNUM_SIGN(vmax) && !rb_bigzero_p(vmax)) {
vmax = excl ? rb_big_minus(vmax, INT2FIX(1)) : rb_big_norm(vmax);
if (FIXNUM_P(vmax)) {
excl = 0;
diff --git a/rational.c b/rational.c
index 53bc11c..fe2d11e 100644
--- a/rational.c
+++ b/rational.c
@@ -293,14 +293,14 @@ rb_gcd_gmp(VALUE x, VALUE y)
mpz_init(mx);
mpz_init(my);
mpz_init(mz);
- mpz_import(mx, RBIGNUM_LEN(x), -1, sizeof(BDIGIT), 0, nails, RBIGNUM_DIGITS(x));
- mpz_import(my, RBIGNUM_LEN(y), -1, sizeof(BDIGIT), 0, nails, RBIGNUM_DIGITS(y));
+ mpz_import(mx, BIGNUM_LEN(x), -1, sizeof(BDIGIT), 0, nails, BIGNUM_DIGITS(x));
+ mpz_import(my, BIGNUM_LEN(y), -1, sizeof(BDIGIT), 0, nails, BIGNUM_DIGITS(y));
mpz_gcd(mz, mx, my);
zn = (mpz_sizeinbase(mz, 16) + SIZEOF_BDIGITS*2 - 1) / (SIZEOF_BDIGITS*2);
z = rb_big_new(zn, 1);
- mpz_export(RBIGNUM_DIGITS(z), &count, -1, sizeof(BDIGIT), 0, nails, mz);
+ mpz_export(BIGNUM_DIGITS(z), &count, -1, sizeof(BDIGIT), 0, nails, mz);
return rb_big_norm(z);
}
@@ -374,8 +374,8 @@ f_gcd(VALUE x, VALUE y)
{
#ifdef USE_GMP
if (RB_TYPE_P(x, T_BIGNUM) && RB_TYPE_P(y, T_BIGNUM)) {
- long xn = RBIGNUM_LEN(x);
- long yn = RBIGNUM_LEN(y);
+ long xn = BIGNUM_LEN(x);
+ long yn = BIGNUM_LEN(y);
if (GMP_GCD_DIGITS <= xn || GMP_GCD_DIGITS <= yn)
return rb_gcd_gmp(x, y);
}
diff --git a/sprintf.c b/sprintf.c
index 97b2126..6551f8f 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -853,7 +853,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
if (numdigits == 0 ||
((abs_nlz_bits != (size_t)(numbits-1) ||
!rb_absint_singlebit_p(val)) &&
- (!bignum ? v < 0 : RBIGNUM_NEGATIVE_P(val))))
+ (!bignum ? v < 0 : BIGNUM_NEGATIVE_P(val))))
numdigits++;
tmp = rb_str_new(NULL, numdigits);
valsign = rb_integer_pack(val, RSTRING_PTR(tmp), RSTRING_LEN(tmp),