Commit a874a0ab authored by Davis King's avatar Davis King

Fixed a bug in the bigint object that caused division to sometimes produce

incorrect results.
parent f0d01c44
......@@ -1284,17 +1284,13 @@ namespace dlib
++r;
}
// if we are using one less digit
if (*(r-1) == 0)
{
if (lhs->digits_used != 1)
result->digits_used = lhs->digits_used - 1;
else
result->digits_used = 1;
}
else
result->digits_used = lhs->digits_used;
// adjust the number of digits used appropriately
--r;
while (*r == 0 && result->digits_used > 1)
{
result->digits_used = lhs->digits_used;
--r;
--result->digits_used;
}
}
......@@ -1344,7 +1340,7 @@ namespace dlib
// shift rhs left until it is one shift away from being larger than lhs and
// put the number of left shifts necessary into shifts
uint32 shifts;
shifts = (lhs->digits_used - rhs->digits_used) * 8;
shifts = (lhs->digits_used - rhs->digits_used) * 16;
shift_left(rhs,&temp,shifts);
......
......@@ -1285,17 +1285,13 @@ namespace dlib
++r;
}
// if we are using one less digit
if (*(r-1) == 0)
{
if (lhs->digits_used != 1)
result->digits_used = lhs->digits_used - 1;
else
result->digits_used = 1;
}
else
result->digits_used = lhs->digits_used;
// adjust the number of digits used appropriately
--r;
while (*r == 0 && result->digits_used > 1)
{
result->digits_used = lhs->digits_used;
--r;
--result->digits_used;
}
}
......@@ -1345,7 +1341,7 @@ namespace dlib
// shift rhs left until it is one shift away from being larger than lhs and
// put the number of left shifts necessary into shifts
uint32 shifts;
shifts = (lhs->digits_used - rhs->digits_used) * 8;
shifts = (lhs->digits_used - rhs->digits_used) * 16;
shift_left(rhs,&temp,shifts);
......@@ -1523,7 +1519,7 @@ namespace dlib
// that should happen.
ifft(a,size);
// loop over the result and propigate any carries that need to take place.
// loop over the result and propagate any carries that need to take place.
// We will also be moving the resulting numbers into result->number at
// the same time.
uint64 carry = 0;
......
......@@ -473,6 +473,15 @@ namespace
a = 10000;
a = a*a*a*a; a = a*a; a = a*a;
b = 2;
DLIB_TEST((a/b)*b == a);
a = 10000*5;
a = a*a*a*a; a = a*a; a = a*a;
b = 5;
DLIB_TEST((a/b)*b == a);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment