modular arithmetic calculator
Go to file
filifa 432566354b add scope and id 2025-12-15 21:48:44 -05:00
workers always return smallest sqrt 2025-12-11 23:49:35 -05:00
.gitignore initial commit 2025-12-11 23:49:34 -05:00
COPYING add license 2025-12-11 23:49:34 -05:00
README.md add readme 2025-12-11 23:49:35 -05:00
favicon.ico add icon and manifest.json 2025-12-15 21:05:52 -05:00
icon.svg add icon and manifest.json 2025-12-15 21:05:52 -05:00
index.html fix link 2025-12-15 21:18:12 -05:00
legal.html add icon and manifest.json 2025-12-15 21:05:52 -05:00
main.js don't switch buttons back on automatically after computation 2025-12-15 20:45:47 -05:00
manifest.json add scope and id 2025-12-15 21:48:44 -05:00
styles.css add icon and manifest.json 2025-12-15 21:05:52 -05:00

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:

  1. Leave this behavior in, even if it's not what I think most people would expect.
  2. Complicate the code by handling exponent expressions non-modularly.
  3. 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.