mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-31 19:04:27 +02:00
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(
|
||||
// Transform into "negative space" to make the first parameter as small as possible;
|
||||
// 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).
|
||||
(a * (b % batch_size)) % n,
|
||||
|
Reference in New Issue
Block a user