summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-08 03:20:09 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-08 03:20:09 +0000
commitf105a01a3ef5c4d6f9484be1a3779b1358e0f86c (patch)
tree819cf9ed82c084267ecb3b352be082c4a7252b2f /bignum.c
parentaac8fbf09ff2bec1b2a0dfa0b484a422f7cf78da (diff)
* bignum.c (get2comp): calculate proper 2's complement for
negative numbers. a bug in normalizing negative numbers reported from Honda Hiroki <hhonda@ipflex.com>. * ext/socket/socket.c (ruby_getaddrinfo__aix): merged a patch from KUBO Takehiro <kubo@jiubao.org> to support AIX. [ruby-list:40832] * lib/yaml/rubytypes.rb (Array::to_yaml): merged a patch from Tilman Sauerbeck <tilman@code-monkey.de>. [ruby-core:05055] * lib/yaml/rubytypes.rb (Hash::to_yaml): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/bignum.c b/bignum.c
index b6cb7b65b4..9272816fc9 100644
--- a/bignum.c
+++ b/bignum.c
@@ -85,7 +85,7 @@ get2comp(x, carry) /* get 2's complement */
if ((ds[RBIGNUM(x)->len-1] & (1<<(BITSPERDIG-1))) == 0) {
REALLOC_N(RBIGNUM(x)->digits, BDIGIT, ++RBIGNUM(x)->len);
ds = BDIGITS(x);
- ds[RBIGNUM(x)->len-1] = ~0;
+ ds[RBIGNUM(x)->len-1] = RBIGNUM(x)->sign ? ~0 : 1;
}
}
@@ -1055,8 +1055,8 @@ rb_big_neg(x)
if (!RBIGNUM(x)->sign) get2comp(z, Qtrue);
while (i--) ds[i] = ~ds[i];
- if (RBIGNUM(x)->sign) get2comp(z, Qfalse);
RBIGNUM(z)->sign = !RBIGNUM(z)->sign;
+ if (RBIGNUM(x)->sign) get2comp(z, Qtrue);
return bignorm(z);
}
@@ -1677,7 +1677,7 @@ rb_big_and(xx, yy)
for (; i<l2; i++) {
zds[i] = sign?0:ds2[i];
}
- if (!RBIGNUM(z)->sign) get2comp(z, Qfalse);
+ if (!RBIGNUM(z)->sign) get2comp(z, Qtrue);
return bignorm(z);
}
@@ -1734,7 +1734,7 @@ rb_big_or(xx, yy)
for (; i<l2; i++) {
zds[i] = sign?ds2[i]:(BIGRAD-1);
}
- if (!RBIGNUM(z)->sign) get2comp(z, Qfalse);
+ if (!RBIGNUM(z)->sign) get2comp(z, Qtrue);
return bignorm(z);
}
@@ -1795,7 +1795,7 @@ rb_big_xor(xx, yy)
for (; i<l2; i++) {
zds[i] = sign?ds2[i]:~ds2[i];
}
- if (!RBIGNUM(z)->sign) get2comp(z, Qfalse);
+ if (!RBIGNUM(z)->sign) get2comp(z, Qtrue);
return bignorm(z);
}