1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Bug in + and - reported by Bret Jolly fixed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6026 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shigek 2004-03-25 12:45:07 +00:00
parent ec37ab2efe
commit c9d5d2554c

View file

@ -2213,8 +2213,7 @@ VpAddAbs(Real *a, Real *b, Real *c)
while(b_pos + word_shift > a_pos) { while(b_pos + word_shift > a_pos) {
--c_pos; --c_pos;
if(b_pos > 0) { if(b_pos > 0) {
--b_pos; c->frac[c_pos] = b->frac[--b_pos];
c->frac[c_pos] = b->frac[b_pos];
} else { } else {
--word_shift; --word_shift;
c->frac[c_pos] = 0; c->frac[c_pos] = 0;
@ -2225,19 +2224,14 @@ VpAddAbs(Real *a, Real *b, Real *c)
/* corresponding digits to be added. */ /* corresponding digits to be added. */
bv = b_pos + word_shift; bv = b_pos + word_shift;
while(a_pos > bv) { while(a_pos > bv) {
--c_pos; c->frac[--c_pos] = a->frac[--a_pos];
--a_pos;
c->frac[c_pos] = a->frac[a_pos];
} }
carry = 0; /* set first carry be zero */ carry = 0; /* set first carry be zero */
/* Now perform addition until every digits of b will be */ /* Now perform addition until every digits of b will be */
/* exhausted. */ /* exhausted. */
while(b_pos > 0) { while(b_pos > 0) {
--a_pos; c->frac[--c_pos] = a->frac[--a_pos] + b->frac[--b_pos] + carry;
--b_pos;
--c_pos;
c->frac[c_pos] = a->frac[a_pos] + b->frac[b_pos] + carry;
if(c->frac[c_pos] >= BASE) { if(c->frac[c_pos] >= BASE) {
c->frac[c_pos] -= BASE; c->frac[c_pos] -= BASE;
carry = 1; carry = 1;
@ -2249,9 +2243,7 @@ VpAddAbs(Real *a, Real *b, Real *c)
/* Just assign the first few digits of a with considering */ /* Just assign the first few digits of a with considering */
/* the carry obtained so far because b has been exhausted. */ /* the carry obtained so far because b has been exhausted. */
while(a_pos > 0) { while(a_pos > 0) {
--a_pos; c->frac[--c_pos] = a->frac[--a_pos] + carry;
--c_pos;
c->frac[c_pos] = a->frac[a_pos] + carry;
if(c->frac[c_pos] >= BASE) { if(c->frac[c_pos] >= BASE) {
c->frac[c_pos] -= BASE; c->frac[c_pos] -= BASE;
carry = 1; carry = 1;
@ -2320,14 +2312,10 @@ VpSubAbs(Real *a, Real *b, Real *c)
/* corresponding digits to be subtracted. */ /* corresponding digits to be subtracted. */
if(b_pos + word_shift > a_pos) { if(b_pos + word_shift > a_pos) {
borrow = 1; borrow = 1;
--c_pos;
--b_pos;
c->frac[c_pos] = BASE - b->frac[b_pos];
while(b_pos + word_shift > a_pos) { while(b_pos + word_shift > a_pos) {
--c_pos; --c_pos;
if(b_pos > 0) { if(b_pos > 0) {
--b_pos; c->frac[c_pos] = BASE - b->frac[--b_pos] - borrow;
c->frac[c_pos] = BASE - b->frac[b_pos] - borrow;
} else { } else {
--word_shift; --word_shift;
c->frac[c_pos] = BASE - borrow; c->frac[c_pos] = BASE - borrow;
@ -2339,18 +2327,14 @@ VpSubAbs(Real *a, Real *b, Real *c)
bv = b_pos + word_shift; bv = b_pos + word_shift;
while(a_pos > bv) { while(a_pos > bv) {
--c_pos; c->frac[--c_pos] = a->frac[--a_pos];
--a_pos;
c->frac[c_pos] = a->frac[a_pos];
} }
/* Now perform subtraction until every digits of b will be */ /* Now perform subtraction until every digits of b will be */
/* exhausted. */ /* exhausted. */
while(b_pos > 0) { while(b_pos > 0) {
--a_pos;
--b_pos;
--c_pos; --c_pos;
if(a->frac[a_pos] < b->frac[b_pos] + borrow) { if(a->frac[--a_pos] < b->frac[--b_pos] + borrow) {
c->frac[c_pos] = BASE + a->frac[a_pos] - b->frac[b_pos] - borrow; c->frac[c_pos] = BASE + a->frac[a_pos] - b->frac[b_pos] - borrow;
borrow = 1; borrow = 1;
} else { } else {
@ -2363,8 +2347,7 @@ VpSubAbs(Real *a, Real *b, Real *c)
/* the borrow obtained so far because b has been exhausted. */ /* the borrow obtained so far because b has been exhausted. */
while(a_pos > 0) { while(a_pos > 0) {
--c_pos; --c_pos;
--a_pos; if(a->frac[--a_pos] < borrow) {
if(a->frac[a_pos] < borrow) {
c->frac[c_pos] = BASE + a->frac[a_pos] - borrow; c->frac[c_pos] = BASE + a->frac[a_pos] - borrow;
borrow = 1; borrow = 1;
} else { } else {