From a882a3fbaf4e62750532ca3e37d64edbeccc43c6 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 8 Jun 2005 03:20:09 +0000 Subject: * bignum.c (get2comp): calculate proper 2's complement for negative numbers. a bug in normalizing negative numbers reported from Honda Hiroki . * ext/socket/socket.c (ruby_getaddrinfo__aix): merged a patch from KUBO Takehiro to support AIX. [ruby-list:40832] * lib/yaml/rubytypes.rb (Array::to_yaml): merged a patch from Tilman Sauerbeck . [ruby-core:05055] * lib/yaml/rubytypes.rb (Hash::to_yaml): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@8592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- bignum.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bignum.c') diff --git a/bignum.c b/bignum.c index b6cb7b65b..9272816fc 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 (; isign) get2comp(z, Qfalse); + if (!RBIGNUM(z)->sign) get2comp(z, Qtrue); return bignorm(z); } @@ -1734,7 +1734,7 @@ rb_big_or(xx, yy) for (; isign) get2comp(z, Qfalse); + if (!RBIGNUM(z)->sign) get2comp(z, Qtrue); return bignorm(z); } @@ -1795,7 +1795,7 @@ rb_big_xor(xx, yy) for (; isign) get2comp(z, Qfalse); + if (!RBIGNUM(z)->sign) get2comp(z, Qtrue); return bignorm(z); } -- cgit