This can mark a number as either "probably prime", or "definitely
composite". The first parameter is the base, and the second is the
number to test.
Future PRs will build up the Strong Lucas test which complements this,
and then form the Baillie-PSW test by composing the two.
Helps #506.
The prime-testing techniques we will use (Miller-Rabin, Strong Lucas)
all make heavy usage of modular arithmetic. Therefore, we lay those
foundations here, adding utilities to perform the basic arithmetic
operations robustly.
Since these are internal-only helper functions, we don't bother checking
the preconditions, although we state them clearly in the contract
comment for each utility. After C++26, we could add contracts for
these.
Helps #509.