aboutsummaryrefslogtreecommitdiffstats
path: root/bignum.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-20 13:23:33 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-20 13:23:33 +0000
commita9c71d1139fcf4c478f28f979c32441bbf96b524 (patch)
tree93309256af46dc85126d9797b2c57b79a8adae10 /bignum.c
parent6ea1aee76e2642aa0d532a00e0b971dede02d818 (diff)
downloadruby-a9c71d1139fcf4c478f28f979c32441bbf96b524.tar.gz
* bignum.c (big2ulong): Change the return type to unsigned long.
(rb_big2ulong_pack): Follow the above change. (rb_big2long): Ditto. (rb_big_lshift): Ditto. (rb_big_rshift): Ditto. (rb_big_aref): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/bignum.c b/bignum.c
index cba044250b..e7bfe4a054 100644
--- a/bignum.c
+++ b/bignum.c
@@ -2275,7 +2275,7 @@ rb_big_to_s(int argc, VALUE *argv, VALUE x)
return rb_big2str(x, base);
}
-static VALUE
+static unsigned long
big2ulong(VALUE x, const char *type, int check)
{
long len = RBIGNUM_LEN(x);
@@ -2293,13 +2293,13 @@ big2ulong(VALUE x, const char *type, int check)
num = BIGUP(num);
num += ds[len];
}
- return (VALUE)(unsigned long)num;
+ return (unsigned long)num;
}
VALUE
rb_big2ulong_pack(VALUE x)
{
- VALUE num = big2ulong(x, "unsigned long", FALSE);
+ unsigned long num = big2ulong(x, "unsigned long", FALSE);
if (!RBIGNUM_SIGN(x)) {
return (VALUE)(-(SIGNED_VALUE)num);
}
@@ -2309,7 +2309,7 @@ rb_big2ulong_pack(VALUE x)
VALUE
rb_big2ulong(VALUE x)
{
- VALUE num = big2ulong(x, "unsigned long", TRUE);
+ unsigned long num = big2ulong(x, "unsigned long", TRUE);
if (RBIGNUM_POSITIVE_P(x)) {
return num;
@@ -2326,7 +2326,7 @@ rb_big2ulong(VALUE x)
SIGNED_VALUE
rb_big2long(VALUE x)
{
- VALUE num = big2ulong(x, "long", TRUE);
+ unsigned long num = big2ulong(x, "long", TRUE);
if (RBIGNUM_POSITIVE_P(x)) {
if (num <= LONG_MAX)
@@ -4729,15 +4729,18 @@ check_shiftdown(VALUE y, VALUE x)
VALUE
rb_big_lshift(VALUE x, VALUE y)
{
- long shift;
+ unsigned long shift;
int neg = 0;
for (;;) {
if (FIXNUM_P(y)) {
- shift = FIX2LONG(y);
- if (shift < 0) {
+ long l = FIX2LONG(y);
+ if (0 <= l) {
+ shift = l;
+ }
+ else {
neg = 1;
- shift = -shift;
+ shift = 1+(unsigned long)(-(l+1));
}
break;
}
@@ -4801,15 +4804,18 @@ big_lshift(VALUE x, unsigned long shift)
VALUE
rb_big_rshift(VALUE x, VALUE y)
{
- long shift;
+ unsigned long shift;
int neg = 0;
for (;;) {
if (FIXNUM_P(y)) {
- shift = FIX2LONG(y);
- if (shift < 0) {
+ long l = FIX2LONG(y);
+ if (0 <= l) {
+ shift = l;
+ }
+ else {
neg = 1;
- shift = -shift;
+ shift = 1+(unsigned long)(-(l+1));
}
break;
}
@@ -4908,7 +4914,7 @@ rb_big_aref(VALUE x, VALUE y)
{
BDIGIT *xds;
BDIGIT_DBL num;
- VALUE shift;
+ unsigned long shift;
long i, s1, s2;
if (RB_TYPE_P(y, T_BIGNUM)) {
@@ -4924,7 +4930,7 @@ rb_big_aref(VALUE x, VALUE y)
else {
i = NUM2LONG(y);
if (i < 0) return INT2FIX(0);
- shift = (VALUE)i;
+ shift = i;
}
s1 = shift/BITSPERDIG;
s2 = shift%BITSPERDIG;