mirror of
https://github.com/mpusz/mp-units.git
synced 2025-06-25 01:01:33 +02:00
The Strong Lucas test coming in the next PR will already be complicated enough. It'll be convenient, and less distracting, if we already have functions for certain operations we'll need. One thing we'll need to do is detect inputs that are perfect squares. Fortunately, this is pretty easy to do robustly and quickly, with Newton's method. We _don't_ want to use `std::sqrt`, because that takes us into the floating point domain for no good reason, which could give us wrong answers for larger integers. The other thing we need is Jacobi symbols. These are a lot more obscure, but thankfully, still resonably straightforward to compute. The Wikipedia page (https://en.wikipedia.org/wiki/Jacobi_symbol) has a good explanation, and in particular, good instructions for computing values. With these utilities in place, the Strong Lucas code should be easier to review.