@@ -267,7 +267,9 @@ namespace operations {
267267
268268 [[nodiscard]] std::vector<std::uint8_t > div (
269269 const std::vector<std::uint8_t > dividend,
270- const std::vector<std::uint8_t > &divisor) noexcept {
270+ const std::vector<std::uint8_t > &divisor,
271+ std::vector<std::uint8_t > *remaining = nullptr ) noexcept
272+ {
271273 std::vector<std::uint8_t > quotient;
272274 std::uint8_t quotientBuffer = 0 ;
273275 std::uint16_t quotientBitIndex = 0 ;
@@ -289,6 +291,17 @@ namespace operations {
289291 }
290292
291293 if (isEqual (dividendMask, divisor) || isBigger (dividendMask, divisor)) {
294+
295+ /* Stop the loop if the dividend is smaller than the divisor, because fractional
296+ * digits are not supported */
297+ if (dividendIndex < 0 ) {
298+ quotientBuffer <<= 1 ;
299+
300+ // If remaining pointer is passed, set the remaining value
301+ if (remaining != nullptr ) *remaining = dividendMask;
302+ break ;
303+ }
304+
292305 // Shift the dividend and set the new bit as high
293306 quotientBuffer <<= 1 ;
294307 quotientBuffer++;
@@ -301,6 +314,9 @@ namespace operations {
301314 * digits are not supported */
302315 if (dividendIndex < 0 ) {
303316 quotientBuffer <<= 1 ;
317+
318+ // If remaining pointer is passed, set the remaining value
319+ if (remaining != nullptr ) *remaining = dividendMask;
304320 break ;
305321 }
306322
0 commit comments