mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* bignum.c (DIGSPERLONG): Don't define if BDIGIT is bigger than long.
(DIGSPERLL): Don't define if BDIGIT is bigger than LONG_LONG (rb_absint_size): Consider environments BDIGIT is bigger than long. Use BIGLO and BIGDN. (rb_absint_singlebit_p): Ditto. (rb_integer_pack): Ditto. (bigsub_int): Consider environments BDIGIT is bigger than long. Use SIZEOF_BDIGITS instead of sizeof(BDIGIT). (bigadd_int): Ditto. (bigand_int): Ditto. (bigor_int): Ditto. (bigxor_int): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9f473df72a
commit
9cff4e30c6
2 changed files with 39 additions and 22 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
Wed Jun 19 19:31:30 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* bignum.c (DIGSPERLONG): Don't define if BDIGIT is bigger than long.
|
||||
(DIGSPERLL): Don't define if BDIGIT is bigger than LONG_LONG
|
||||
(rb_absint_size): Consider environments BDIGIT is bigger than long.
|
||||
Use BIGLO and BIGDN.
|
||||
(rb_absint_singlebit_p): Ditto.
|
||||
(rb_integer_pack): Ditto.
|
||||
(bigsub_int): Consider environments BDIGIT is bigger than long.
|
||||
Use SIZEOF_BDIGITS instead of sizeof(BDIGIT).
|
||||
(bigadd_int): Ditto.
|
||||
(bigand_int): Ditto.
|
||||
(bigor_int): Ditto.
|
||||
(bigxor_int): Ditto.
|
||||
|
||||
Wed Jun 19 15:14:30 2013 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* include/ruby/ruby.h (struct rb_data_type_struct), gc.c: add
|
||||
|
|
46
bignum.c
46
bignum.c
|
@ -37,8 +37,10 @@ static VALUE big_three = Qnil;
|
|||
#define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT)
|
||||
#define BIGRAD ((BDIGIT_DBL)1 << BITSPERDIG)
|
||||
#define BIGRAD_HALF ((BDIGIT)(BIGRAD >> 1))
|
||||
#define DIGSPERLONG (SIZEOF_LONG/SIZEOF_BDIGITS)
|
||||
#if HAVE_LONG_LONG
|
||||
#if SIZEOF_LONG >= SIZEOF_BDIGITS
|
||||
# define DIGSPERLONG (SIZEOF_LONG/SIZEOF_BDIGITS)
|
||||
#endif
|
||||
#if defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG >= SIZEOF_BDIGITS
|
||||
# define DIGSPERLL (SIZEOF_LONG_LONG/SIZEOF_BDIGITS)
|
||||
#endif
|
||||
#define BIGUP(x) ((BDIGIT_DBL)(x) << BITSPERDIG)
|
||||
|
@ -526,14 +528,14 @@ rb_absint_size(VALUE val, int *nlz_bits_ret)
|
|||
if (v < 0) {
|
||||
v = -v;
|
||||
}
|
||||
#if SIZEOF_BDIGITS == SIZEOF_LONG
|
||||
#if SIZEOF_BDIGITS >= SIZEOF_LONG
|
||||
fixbuf[0] = v;
|
||||
#else
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < numberof(fixbuf); i++) {
|
||||
fixbuf[i] = (BDIGIT)(v & ((1L << (SIZEOF_BDIGITS * CHAR_BIT)) - 1));
|
||||
v >>= SIZEOF_BDIGITS * CHAR_BIT;
|
||||
fixbuf[i] = BIGLO(v);
|
||||
v = BIGDN(v);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -690,14 +692,14 @@ rb_absint_singlebit_p(VALUE val)
|
|||
if (v < 0) {
|
||||
v = -v;
|
||||
}
|
||||
#if SIZEOF_BDIGITS == SIZEOF_LONG
|
||||
#if SIZEOF_BDIGITS >= SIZEOF_LONG
|
||||
fixbuf[0] = v;
|
||||
#else
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < numberof(fixbuf); i++) {
|
||||
fixbuf[i] = (BDIGIT)(v & ((1L << (SIZEOF_BDIGITS * CHAR_BIT)) - 1));
|
||||
v >>= SIZEOF_BDIGITS * CHAR_BIT;
|
||||
fixbuf[i] = BIGLO(v);
|
||||
v = BIGDN(v);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1098,14 +1100,14 @@ rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t
|
|||
else {
|
||||
sign = 1;
|
||||
}
|
||||
#if SIZEOF_BDIGITS == SIZEOF_LONG
|
||||
#if SIZEOF_BDIGITS >= SIZEOF_LONG
|
||||
fixbuf[0] = v;
|
||||
#else
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < numberof(fixbuf); i++) {
|
||||
fixbuf[i] = (BDIGIT)(v & ((1L << (SIZEOF_BDIGITS * CHAR_BIT)) - 1));
|
||||
v >>= SIZEOF_BDIGITS * CHAR_BIT;
|
||||
fixbuf[i] = BIGLO(v);
|
||||
v = BIGDN(v);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -2908,7 +2910,7 @@ bigsub_int(VALUE x, long y0)
|
|||
z = bignew(xn, RBIGNUM_SIGN(x));
|
||||
zds = BDIGITS(z);
|
||||
|
||||
#if SIZEOF_BDIGITS == SIZEOF_LONG
|
||||
#if SIZEOF_BDIGITS >= SIZEOF_LONG
|
||||
num = (BDIGIT_DBL_SIGNED)xds[0] - y;
|
||||
if (xn == 1 && num < 0) {
|
||||
RBIGNUM_SET_SIGN(z, !RBIGNUM_SIGN(x));
|
||||
|
@ -2921,7 +2923,7 @@ bigsub_int(VALUE x, long y0)
|
|||
i = 1;
|
||||
#else
|
||||
num = 0;
|
||||
for (i=0; i<(int)(sizeof(y)/sizeof(BDIGIT)); i++) {
|
||||
for (i=0; i<(int)(sizeof(y)/SIZEOF_BDIGITS); i++) {
|
||||
num += (BDIGIT_DBL_SIGNED)xds[i] - BIGLO(y);
|
||||
zds[i] = BIGLO(num);
|
||||
num = BIGDN(num);
|
||||
|
@ -2965,14 +2967,14 @@ bigadd_int(VALUE x, long y)
|
|||
z = bignew(zn, RBIGNUM_SIGN(x));
|
||||
zds = BDIGITS(z);
|
||||
|
||||
#if SIZEOF_BDIGITS == SIZEOF_LONG
|
||||
#if SIZEOF_BDIGITS >= SIZEOF_LONG
|
||||
num = (BDIGIT_DBL)xds[0] + y;
|
||||
zds[0] = BIGLO(num);
|
||||
num = BIGDN(num);
|
||||
i = 1;
|
||||
#else
|
||||
num = 0;
|
||||
for (i=0; i<(int)(sizeof(y)/sizeof(BDIGIT)); i++) {
|
||||
for (i=0; i<(int)(sizeof(y)/SIZEOF_BDIGITS); i++) {
|
||||
num += (BDIGIT_DBL)xds[i] + BIGLO(y);
|
||||
zds[i] = BIGLO(num);
|
||||
num = BIGDN(num);
|
||||
|
@ -4369,7 +4371,7 @@ bigand_int(VALUE x, long y)
|
|||
sign = (y > 0);
|
||||
xds = BDIGITS(x);
|
||||
zn = xn = RBIGNUM_LEN(x);
|
||||
#if SIZEOF_BDIGITS == SIZEOF_LONG
|
||||
#if SIZEOF_BDIGITS >= SIZEOF_LONG
|
||||
if (sign) {
|
||||
y &= xds[0];
|
||||
return LONG2NUM(y);
|
||||
|
@ -4379,14 +4381,14 @@ bigand_int(VALUE x, long y)
|
|||
z = bignew(zn, RBIGNUM_SIGN(x) || sign);
|
||||
zds = BDIGITS(z);
|
||||
|
||||
#if SIZEOF_BDIGITS == SIZEOF_LONG
|
||||
#if SIZEOF_BDIGITS >= SIZEOF_LONG
|
||||
i = 1;
|
||||
zds[0] = xds[0] & y;
|
||||
#else
|
||||
{
|
||||
BDIGIT_DBL num = y;
|
||||
|
||||
for (i=0; i<(int)(sizeof(y)/sizeof(BDIGIT)); i++) {
|
||||
for (i=0; i<(int)(sizeof(y)/SIZEOF_BDIGITS); i++) {
|
||||
zds[i] = xds[i] & BIGLO(num);
|
||||
num = BIGDN(num);
|
||||
}
|
||||
|
@ -4475,14 +4477,14 @@ bigor_int(VALUE x, long y)
|
|||
z = bignew(zn, RBIGNUM_SIGN(x) && sign);
|
||||
zds = BDIGITS(z);
|
||||
|
||||
#if SIZEOF_BDIGITS == SIZEOF_LONG
|
||||
#if SIZEOF_BDIGITS >= SIZEOF_LONG
|
||||
i = 1;
|
||||
zds[0] = xds[0] | y;
|
||||
#else
|
||||
{
|
||||
BDIGIT_DBL num = y;
|
||||
|
||||
for (i=0; i<(int)(sizeof(y)/sizeof(BDIGIT)); i++) {
|
||||
for (i=0; i<(int)(sizeof(y)/SIZEOF_BDIGITS); i++) {
|
||||
zds[i] = xds[i] | BIGLO(num);
|
||||
num = BIGDN(num);
|
||||
}
|
||||
|
@ -4571,14 +4573,14 @@ bigxor_int(VALUE x, long y)
|
|||
z = bignew(zn, !(RBIGNUM_SIGN(x) ^ sign));
|
||||
zds = BDIGITS(z);
|
||||
|
||||
#if SIZEOF_BDIGITS == SIZEOF_LONG
|
||||
#if SIZEOF_BDIGITS >= SIZEOF_LONG
|
||||
i = 1;
|
||||
zds[0] = xds[0] ^ y;
|
||||
#else
|
||||
{
|
||||
BDIGIT_DBL num = y;
|
||||
|
||||
for (i=0; i<(int)(sizeof(y)/sizeof(BDIGIT)); i++) {
|
||||
for (i=0; i<(int)(sizeof(y)/SIZEOF_BDIGITS); i++) {
|
||||
zds[i] = xds[i] ^ BIGLO(num);
|
||||
num = BIGDN(num);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue