forked from mpusz/mp-units
Handle edge case
Subtracting from `n` doesn't work in literally every case: it fails for `0` input.
This commit is contained in:
@@ -100,7 +100,7 @@ namespace mp_units::detail {
|
|||||||
return add_mod(
|
return add_mod(
|
||||||
// Transform into "negative space" to make the first parameter as small as possible;
|
// Transform into "negative space" to make the first parameter as small as possible;
|
||||||
// then, transform back.
|
// then, transform back.
|
||||||
n - mul_mod(n % a, num_batches, n),
|
(n - mul_mod(n % a, num_batches, n)) % n,
|
||||||
|
|
||||||
// Handle the leftover product (which is guaranteed to fit in the integer type).
|
// Handle the leftover product (which is guaranteed to fit in the integer type).
|
||||||
(a * (b % batch_size)) % n,
|
(a * (b % batch_size)) % n,
|
||||||
|
Reference in New Issue
Block a user