From c9d5d2554c210fec9b75aa86cdf8dc08400f5f17 Mon Sep 17 00:00:00 2001 From: shigek Date: Thu, 25 Mar 2004 12:45:07 +0000 Subject: [PATCH] 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 --- ext/bigdecimal/bigdecimal.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 0d339c9cfc..2af1da06ef 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -2213,8 +2213,7 @@ VpAddAbs(Real *a, Real *b, Real *c) while(b_pos + word_shift > a_pos) { --c_pos; if(b_pos > 0) { - --b_pos; - c->frac[c_pos] = b->frac[b_pos]; + c->frac[c_pos] = b->frac[--b_pos]; } else { --word_shift; c->frac[c_pos] = 0; @@ -2225,19 +2224,14 @@ VpAddAbs(Real *a, Real *b, Real *c) /* corresponding digits to be added. */ bv = b_pos + word_shift; while(a_pos > bv) { - --c_pos; - --a_pos; - c->frac[c_pos] = a->frac[a_pos]; + c->frac[--c_pos] = a->frac[--a_pos]; } carry = 0; /* set first carry be zero */ /* Now perform addition until every digits of b will be */ /* exhausted. */ while(b_pos > 0) { - --a_pos; - --b_pos; - --c_pos; - c->frac[c_pos] = a->frac[a_pos] + b->frac[b_pos] + carry; + c->frac[--c_pos] = a->frac[--a_pos] + b->frac[--b_pos] + carry; if(c->frac[c_pos] >= BASE) { c->frac[c_pos] -= BASE; carry = 1; @@ -2249,9 +2243,7 @@ VpAddAbs(Real *a, Real *b, Real *c) /* Just assign the first few digits of a with considering */ /* the carry obtained so far because b has been exhausted. */ while(a_pos > 0) { - --a_pos; - --c_pos; - c->frac[c_pos] = a->frac[a_pos] + carry; + c->frac[--c_pos] = a->frac[--a_pos] + carry; if(c->frac[c_pos] >= BASE) { c->frac[c_pos] -= BASE; carry = 1; @@ -2320,14 +2312,10 @@ VpSubAbs(Real *a, Real *b, Real *c) /* corresponding digits to be subtracted. */ if(b_pos + word_shift > a_pos) { borrow = 1; - --c_pos; - --b_pos; - c->frac[c_pos] = BASE - b->frac[b_pos]; while(b_pos + word_shift > a_pos) { --c_pos; 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 { --word_shift; c->frac[c_pos] = BASE - borrow; @@ -2339,18 +2327,14 @@ VpSubAbs(Real *a, Real *b, Real *c) bv = b_pos + word_shift; while(a_pos > bv) { - --c_pos; - --a_pos; - c->frac[c_pos] = a->frac[a_pos]; + c->frac[--c_pos] = a->frac[--a_pos]; } /* Now perform subtraction until every digits of b will be */ /* exhausted. */ while(b_pos > 0) { - --a_pos; - --b_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; borrow = 1; } else { @@ -2363,8 +2347,7 @@ VpSubAbs(Real *a, Real *b, Real *c) /* the borrow obtained so far because b has been exhausted. */ while(a_pos > 0) { --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; borrow = 1; } else {