long bigdiv(unsigned v, unsigned q[], unsigned const u[], int m)
{
long long k = 0; // the case of a
- for (int j = m - 1; j >= 0; j--) { // single-digit
+ for (int j = m - 1; j >= 0; j--)
+ { // single-digit
unsigned long d2 = (k << 32) | u[j];
q[j] = d2 / v; // divisor here.
- k = d2 % v;
+ k = d2 % v;
}
return k;
}
if (m < n || n <= 0 || v[n - 1] == 0)
return 1; // Return if invalid param.
- if (n == 1) { // Take care of
+ if (n == 1)
+ { // Take care of
k = bigdiv(v[0], q, u, m);
if (r != NULL)
r[0] = k;
un[m] = (unsigned long long)u[m - 1] >> (32 - s); // extra digit
biglsh(s, un, u, m);
- for (j = m - n; j >= 0; j--) { // Main loop.
+ for (j = m - n; j >= 0; j--)
+ { // Main loop.
// Compute estimate qhat of q[j] from top 2 digits
uint64_t dig2 = ((uint64_t)un[j + n] << 32) | un[j + n - 1];
qhat = dig2 / vn[n - 1];
rhat = dig2 % vn[n - 1];
again:
// use 3rd-from-top digit to obtain better accuracy
- if (qhat >= b || qhat * vn[n - 2] > b * rhat + un[j + n - 2]) {
+ if (qhat >= b || qhat * vn[n - 2] > b * rhat + un[j + n - 2])
+ {
qhat = qhat - 1;
rhat = rhat + vn[n - 1];
if (rhat < b)
bool need_fixup = bigmulsub(qhat, vn, un_j, j, m, n);
q[j] = qhat; // Store quotient digit.
- if (need_fixup) { // If we subtracted too
+ if (need_fixup)
+ { // If we subtracted too
q[j] = q[j] - 1; // much, add back.
bigadd(un_j, vn, un_j, m, n, 0);
}