Skip to content

Commit

Permalink
Handle edge case
Browse files Browse the repository at this point in the history
Subtracting from `n` doesn't work in literally every case: it fails for
`0` input.
  • Loading branch information
chiphogg committed Nov 15, 2024
1 parent d963ce8 commit 82040c1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/include/mp-units/ext/prime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 82040c1

Please sign in to comment.