mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
7f27543b3b
commit
3c99764bcd
13 changed files with 256 additions and 217 deletions
39
ChangeLog
39
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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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
|
||||
|
|
8
gc.c
8
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:
|
||||
|
|
48
internal.h
48
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 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 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_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))
|
||||
|
||||
|
|
|
@ -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? */
|
||||
|
|
6
math.c
6
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));
|
||||
|
|
10
numeric.c
10
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);
|
||||
}
|
||||
|
|
4
random.c
4
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;
|
||||
|
|
10
rational.c
10
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);
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Reference in a new issue