Update to imath-1.8 from Michael Fromberger

Fixed a bug in s_udiv() affecting the computation of quotient digits.
Thanks to Love Åstrand for isolating this bug.  Also in this release,
defining USELLONG=Y or USELLONG=N on the command line for make will
switch support for the "long long" data type on or off without having
to edit the Makefile.  The default is still to permit use of "long
long", even though the type is not standard ANSI C90.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19854 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2007-01-11 20:23:15 +00:00
parent 62e1610b02
commit 4ccc092c18

View File

@@ -34,7 +34,6 @@
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
@@ -2994,7 +2993,7 @@ static mp_result s_udiv(mp_int a, mp_int b)
k = s_norm(a, b);
ua = MP_USED(a); ub = MP_USED(b); btop = b->digits[ub - 1];
if((res = mp_int_init_size(&q, ua + 1)) != MP_OK) return res;
if((res = mp_int_init_size(&q, ua)) != MP_OK) return res;
if((res = mp_int_init_size(&t, ua + 1)) != MP_OK) goto CLEANUP;
da = MP_DIGITS(a);
@@ -3012,7 +3011,7 @@ static mp_result s_udiv(mp_int a, mp_int b)
r.digits -= 1;
r.used += 1;
if(++skip > 1)
if(++skip > 1 && qpos > 0)
q.digits[qpos++] = 0;
CLAMP(&r);
@@ -3021,15 +3020,19 @@ static mp_result s_udiv(mp_int a, mp_int b)
mp_word pfx = r.digits[r.used - 1];
mp_word qdigit;
if(r.used > 1 && (pfx < btop || r.digits[r.used - 2] == 0)) {
if(r.used > 1 && pfx <= btop) {
pfx <<= MP_DIGIT_BIT / 2;
pfx <<= MP_DIGIT_BIT / 2;
pfx |= r.digits[r.used - 2];
}
qdigit = pfx / btop;
if(qdigit > MP_DIGIT_MAX)
qdigit = 1;
if(qdigit > MP_DIGIT_MAX) {
if(qdigit & MP_DIGIT_MAX)
qdigit = MP_DIGIT_MAX;
else
qdigit = 1;
}
s_dbmul(MP_DIGITS(b), (mp_digit) qdigit, t.digits, ub);
t.used = ub + 1; CLAMP(&t);
@@ -3046,7 +3049,7 @@ static mp_result s_udiv(mp_int a, mp_int b)
skip = 0;
}
}
/* Put quotient digits in the correct order, and discard extra zeroes */
q.used = qpos;
REV(mp_digit, q.digits, qpos);