diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-06-30 06:20:09 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-06-30 06:20:09 +0000 |
commit | 639bd5e78fa7d83b44c892afccb99869a886e533 (patch) | |
tree | d33ef363870dccb8536cbcc1ab3a8780df92ff7f /bignum.c | |
parent | 00433666fd12d7e08c4c7c51593fc30265dd4508 (diff) |
* eval.c (rb_eval): pre-evaluate argument for unambiguous
evaluation order. [ruby-dev:26383]
* lib/delegate.rb (Delegator::method_missing): forward unknown
method to the destination. suggested by
<christophe.poucet@gmail.com>. [ruby-talk:146776]
* process.c (detach_process_watcher): terminate process watcher
thread right after rb_waitpid() succeed. [ruby-talk:146430]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 44 |
1 files changed, 22 insertions, 22 deletions
@@ -65,10 +65,9 @@ rb_big_clone(x) return z; } +/* modify a bignum by 2's complement */ static void -get2comp(x, carry) /* get 2's complement */ - VALUE x; - int carry; +get2comp(VALUE x) { long i = RBIGNUM(x)->len; BDIGIT *ds = BDIGITS(x); @@ -81,11 +80,10 @@ get2comp(x, carry) /* get 2's complement */ ds[i++] = BIGLO(num); num = BIGDN(num); } while (i < RBIGNUM(x)->len); - if (!carry) return; - if ((ds[RBIGNUM(x)->len-1] & (1<<(BITSPERDIG-1))) == 0) { + if (num != 0) { REALLOC_N(RBIGNUM(x)->digits, BDIGIT, ++RBIGNUM(x)->len); ds = BDIGITS(x); - ds[RBIGNUM(x)->len-1] = RBIGNUM(x)->sign ? ~0 : 1; + ds[RBIGNUM(x)->len-1] = 1; } } @@ -93,7 +91,7 @@ void rb_big_2comp(x) /* get 2's complement */ VALUE x; { - get2comp(x, Qtrue); + get2comp(x); } static VALUE @@ -1038,6 +1036,8 @@ rb_big_uminus(x) return bignorm(z); } +static VALUE bigadd _((VALUE,VALUE,char)); + /* * call-seq: * ~big => integer @@ -1055,15 +1055,15 @@ rb_big_neg(x) VALUE x; { VALUE z = rb_big_clone(x); - long i = RBIGNUM(x)->len; BDIGIT *ds = BDIGITS(z); + long i = RBIGNUM(x)->len; - if (!RBIGNUM(x)->sign) get2comp(z, Qtrue); + if (!RBIGNUM(x)->sign) get2comp(z); while (i--) { ds[i] = ~ds[i]; } RBIGNUM(z)->sign = !RBIGNUM(z)->sign; - if (RBIGNUM(x)->sign) get2comp(z, Qtrue); + if (RBIGNUM(x)->sign) get2comp(z); return bignorm(z); } @@ -1655,11 +1655,11 @@ rb_big_and(xx, yy) } if (!RBIGNUM(y)->sign) { y = rb_big_clone(y); - get2comp(y, Qtrue); + get2comp(y); } if (!RBIGNUM(x)->sign) { x = rb_big_clone(x); - get2comp(x, Qtrue); + get2comp(x); } if (RBIGNUM(x)->len > RBIGNUM(y)->len) { l1 = RBIGNUM(y)->len; @@ -1684,7 +1684,7 @@ rb_big_and(xx, yy) for (; i<l2; i++) { zds[i] = sign?0:ds2[i]; } - if (!RBIGNUM(z)->sign) get2comp(z, Qtrue); + if (!RBIGNUM(z)->sign) get2comp(z); return bignorm(z); } @@ -1712,11 +1712,11 @@ rb_big_or(xx, yy) if (!RBIGNUM(y)->sign) { y = rb_big_clone(y); - get2comp(y, Qtrue); + get2comp(y); } if (!RBIGNUM(x)->sign) { x = rb_big_clone(x); - get2comp(x, Qtrue); + get2comp(x); } if (RBIGNUM(x)->len > RBIGNUM(y)->len) { l1 = RBIGNUM(y)->len; @@ -1741,7 +1741,7 @@ rb_big_or(xx, yy) for (; i<l2; i++) { zds[i] = sign?ds2[i]:(BIGRAD-1); } - if (!RBIGNUM(z)->sign) get2comp(z, Qtrue); + if (!RBIGNUM(z)->sign) get2comp(z); return bignorm(z); } @@ -1771,11 +1771,11 @@ rb_big_xor(xx, yy) if (!RBIGNUM(y)->sign) { y = rb_big_clone(y); - get2comp(y, Qtrue); + get2comp(y); } if (!RBIGNUM(x)->sign) { x = rb_big_clone(x); - get2comp(x, Qtrue); + get2comp(x); } if (RBIGNUM(x)->len > RBIGNUM(y)->len) { l1 = RBIGNUM(y)->len; @@ -1802,7 +1802,7 @@ rb_big_xor(xx, yy) for (; i<l2; i++) { zds[i] = sign?ds2[i]:~ds2[i]; } - if (!RBIGNUM(z)->sign) get2comp(z, Qtrue); + if (!RBIGNUM(z)->sign) get2comp(z); return bignorm(z); } @@ -1874,7 +1874,7 @@ rb_big_rshift(x, y) } if (!RBIGNUM(x)->sign) { x = rb_big_clone(x); - get2comp(x, Qtrue); + get2comp(x); } xds = BDIGITS(x); i = RBIGNUM(x)->len; j = i - s1; @@ -1889,7 +1889,7 @@ rb_big_rshift(x, y) num = BIGUP(xds[i]); } if (!RBIGNUM(x)->sign) { - get2comp(z, Qfalse); + get2comp(z); } return bignorm(z); } @@ -1934,7 +1934,7 @@ rb_big_aref(x, y) if (!RBIGNUM(x)->sign) { if (s1 >= RBIGNUM(x)->len) return INT2FIX(1); x = rb_big_clone(x); - get2comp(x, Qtrue); + get2comp(x); } else { if (s1 >= RBIGNUM(x)->len) return INT2FIX(0); |