| ... | @@ -1015,21 +1015,29 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn | ... | @@ -1015,21 +1015,29 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn |
| 1015 | | 1015 | |
| 1016 | // If the caller wants the quotient | 1016 | // If the caller wants the quotient |
| 1017 | if (Quotient) { | 1017 | if (Quotient) { |
| 1018 | Quotient->digit_count = lhsWords; | | |
| 1019 | Quotient->data.digits = allocate<uint64_t>(lhsWords); | | |
| 1020 | Quotient->is_negative = false; | 1018 | Quotient->is_negative = false; |
| 1021 | for (size_t i = 0; i < lhsWords; i += 1) { | 1019 | Quotient->digit_count = lhsWords; |
| 1022 | Quotient->data.digits[i] = Make_64(Q[i*2+1], Q[i*2]); | 1020 | if (lhsWords == 1) { |
| | 1021 | Quotient->data.digit = Make_64(Q[1], Q[0]); |
| | 1022 | } else { |
| | 1023 | Quotient->data.digits = allocate<uint64_t>(lhsWords); |
| | 1024 | for (size_t i = 0; i < lhsWords; i += 1) { |
| | 1025 | Quotient->data.digits[i] = Make_64(Q[i*2+1], Q[i*2]); |
| | 1026 | } |
| 1023 | } | 1027 | } |
| 1024 | } | 1028 | } |
| 1025 | | 1029 | |
| 1026 | // If the caller wants the remainder | 1030 | // If the caller wants the remainder |
| 1027 | if (Remainder) { | 1031 | if (Remainder) { |
| 1028 | Remainder->digit_count = rhsWords; | | |
| 1029 | Remainder->data.digits = allocate<uint64_t>(rhsWords); | | |
| 1030 | Remainder->is_negative = false; | 1032 | Remainder->is_negative = false; |
| 1031 | for (size_t i = 0; i < rhsWords; i += 1) { | 1033 | Remainder->digit_count = rhsWords; |
| 1032 | Remainder->data.digits[i] = Make_64(R[i*2+1], R[i*2]); | 1034 | if (rhsWords == 1) { |
| | 1035 | Remainder->data.digit = Make_64(R[1], R[0]); |
| | 1036 | } else { |
| | 1037 | Remainder->data.digits = allocate<uint64_t>(rhsWords); |
| | 1038 | for (size_t i = 0; i < rhsWords; i += 1) { |
| | 1039 | Remainder->data.digits[i] = Make_64(R[i*2+1], R[i*2]); |
| | 1040 | } |
| 1033 | } | 1041 | } |
| 1034 | } | 1042 | } |
| 1035 | } | 1043 | } |