@@ -20,7 +20,7 @@ typedef unsigned short USHORT;
20
20
#define BIGRAD (1L << BITSPERDIG)
21
21
#define DIGSPERINT ((unsigned int)(sizeof(long)/sizeof(short)))
22
22
#define BIGUP (x ) ((unsigned int)(x) << BITSPERDIG)
23
- #define BIGDN (x ) RSHIFT((x), BITSPERDIG)
23
+ #define BIGDN (x ) (((x)<0) ? ~((~(x))>>BITSPERDIG) : (x)>> BITSPERDIG)
24
24
#define BIGLO (x ) ((x) & (BIGRAD-1))
25
25
26
26
static VALUE
@@ -61,7 +61,7 @@ big_2comp(x) /* get 2's complement */
61
61
while (i -- ) ds [i ] = ~ds [i ];
62
62
i = 0 ; num = 1 ;
63
63
do {
64
- num += ( long ) ds [i ];
64
+ num += ds [i ];
65
65
ds [i ++ ] = BIGLO (num );
66
66
num = BIGDN (num );
67
67
} while (i < RBIGNUM (x )-> len );
@@ -441,7 +441,7 @@ big_cmp(x, y)
441
441
442
442
switch (TYPE (y )) {
443
443
case T_FIXNUM :
444
- y = int2big (FIX2INT (y ));
444
+ y = int2big (FIX2LONG (y ));
445
445
break ;
446
446
447
447
case T_BIGNUM :
@@ -585,7 +585,7 @@ bigadd(x, y, sign)
585
585
586
586
len = RBIGNUM (x )-> len ;
587
587
for (i = 0 , num = 0 ; i < len ; i ++ ) {
588
- num += ( long )( BDIGITS (x )[i ] + BDIGITS (y )[i ]) ;
588
+ num += BDIGITS (x )[i ] + BDIGITS (y )[i ];
589
589
BDIGITS (z )[i ] = BIGLO (num );
590
590
num = BIGDN (num );
591
591
}
@@ -610,7 +610,7 @@ big_plus(x, y)
610
610
{
611
611
switch (TYPE (y )) {
612
612
case T_FIXNUM :
613
- y = int2big (FIX2INT (y ));
613
+ y = int2big (FIX2LONG (y ));
614
614
/* fall through */
615
615
case T_BIGNUM :
616
616
return bigadd (x , y , 1 );
@@ -629,7 +629,7 @@ big_minus(x, y)
629
629
{
630
630
switch (TYPE (y )) {
631
631
case T_FIXNUM :
632
- y = int2big (FIX2INT (y ));
632
+ y = int2big (FIX2LONG (y ));
633
633
/* fall through */
634
634
case T_BIGNUM :
635
635
return bigadd (x , y , 0 );
@@ -651,10 +651,10 @@ big_mul(x, y)
651
651
VALUE z ;
652
652
USHORT * zds ;
653
653
654
- if (FIXNUM_P (x )) x = int2big (FIX2INT (x ));
654
+ if (FIXNUM_P (x )) x = int2big (FIX2LONG (x ));
655
655
switch (TYPE (y )) {
656
656
case T_FIXNUM :
657
- y = int2big (FIX2INT (y ));
657
+ y = int2big (FIX2LONG (y ));
658
658
break ;
659
659
660
660
case T_BIGNUM :
@@ -737,15 +737,15 @@ bigdivmod(x, y, div, mod, modulo)
737
737
j = 0 ;
738
738
num = 0 ;
739
739
while (j < ny ) {
740
- num += (unsigned long )yds [j ]* dd ;
740
+ num += (long )yds [j ]* dd ;
741
741
tds [j ++ ] = BIGLO (num );
742
742
num = BIGDN (num );
743
743
}
744
744
yds = tds ;
745
745
j = 0 ;
746
746
num = 0 ;
747
747
while (j < nx ) {
748
- num += (unsigned long )xds [j ]* dd ;
748
+ num += (long )xds [j ]* dd ;
749
749
zds [j ++ ] = BIGLO (num );
750
750
num = BIGDN (num );
751
751
}
@@ -764,7 +764,7 @@ bigdivmod(x, y, div, mod, modulo)
764
764
i = 0 ; num = 0 ; t2 = 0 ;
765
765
do { /* multiply and subtract */
766
766
int ee ;
767
- t2 += (unsigned long )yds [i ] * q ;
767
+ t2 += (long )yds [i ] * q ;
768
768
ee = num - BIGLO (t2 );
769
769
num = zds [j - ny + i ] + ee ;
770
770
if (ee ) zds [j - ny + i ] = BIGLO (num );
@@ -827,7 +827,7 @@ big_div(x, y)
827
827
828
828
switch (TYPE (y )) {
829
829
case T_FIXNUM :
830
- y = int2big (FIX2INT (y ));
830
+ y = int2big (FIX2LONG (y ));
831
831
break ;
832
832
833
833
case T_BIGNUM :
@@ -854,7 +854,7 @@ big_modulo(x, y, modulo)
854
854
855
855
switch (TYPE (y )) {
856
856
case T_FIXNUM :
857
- y = int2big (FIX2INT (y ));
857
+ y = int2big (FIX2LONG (y ));
858
858
break ;
859
859
860
860
case T_BIGNUM :
@@ -894,7 +894,7 @@ big_divmod(x, y)
894
894
895
895
switch (TYPE (y )) {
896
896
case T_FIXNUM :
897
- y = int2big (FIX2INT (y ));
897
+ y = int2big (FIX2LONG (y ));
898
898
break ;
899
899
900
900
case T_FLOAT :
@@ -931,8 +931,8 @@ big_pow(x, y)
931
931
break ;
932
932
933
933
case T_FIXNUM :
934
- if (FIX2INT (y ) > 0 ) goto pos_big ;
935
- d = (double )FIX2INT (y );
934
+ if (FIX2LONG (y ) > 0 ) goto pos_big ;
935
+ d = (double )FIX2LONG (y );
936
936
break ;
937
937
938
938
default :
@@ -964,7 +964,7 @@ big_and(x, y)
964
964
char sign ;
965
965
966
966
if (FIXNUM_P (y )) {
967
- y = int2big (FIX2INT (y ));
967
+ y = int2big (FIX2LONG (y ));
968
968
}
969
969
else {
970
970
Check_Type (y , T_BIGNUM );
@@ -1015,7 +1015,7 @@ big_or(x, y)
1015
1015
char sign ;
1016
1016
1017
1017
if (FIXNUM_P (y )) {
1018
- y = int2big (FIX2INT (y ));
1018
+ y = int2big (FIX2LONG (y ));
1019
1019
}
1020
1020
else {
1021
1021
Check_Type (y , T_BIGNUM );
@@ -1067,7 +1067,7 @@ big_xor(x, y)
1067
1067
char sign ;
1068
1068
1069
1069
if (FIXNUM_P (y )) {
1070
- y = int2big (FIX2INT (y ));
1070
+ y = int2big (FIX2LONG (y ));
1071
1071
}
1072
1072
else {
1073
1073
Check_Type (y , T_BIGNUM );
@@ -1219,7 +1219,7 @@ big_coerce(x, y)
1219
1219
VALUE x , y ;
1220
1220
{
1221
1221
if (FIXNUM_P (y )) {
1222
- return assoc_new (int2big (FIX2INT (y )), x );
1222
+ return assoc_new (int2big (FIX2LONG (y )), x );
1223
1223
}
1224
1224
else {
1225
1225
TypeError ("can't coerce %s to Bignum" , rb_class2name (CLASS_OF (y )));
0 commit comments