|
|
||
|---|---|---|
| workers | ||
| .gitignore | ||
| COPYING | ||
| README.md | ||
| index.html | ||
| main.js | ||
| styles.css | ||
README.md
mcalc
mcalc is a calculator for modular arithmetic.
Quirks
Why can't exponents be expressions? Why do they have to be integers?
This is easiest to explain with an example: what should 2^(3+4) evaluate to
modulo 7? In my opinion, it should be 2, since 2^7 = 2 (mod 7). However,
because all the operators in the calculator are implemented as modular
operators, it will first evaluate (3+4) as 0, leading to 2^0 = 1 (mod 7). I
saw three options:
- Leave this behavior in, even if it's not what I think most people would expect.
- Complicate the code by handling exponent expressions non-modularly.
- Simply don't let exponents be expressions.
I chose 3.
Why can't I compute square roots for a composite modulus?
It is certainly possible to compute modular square roots with a composite modulus, and I would like to add the capability at some point, but as implemented, the calculator only supports a prime modulus.
Why is the ord() function so slow when the modulus is large?
Partly because computing multiplicative order is a hard problem, and partly because I'm too lazy at the moment to implement a slightly more efficient algorithm.