Search code examples
pythonmodular-arithmeticmodulo

How can I do modular arithmetic with decimal values in Python?


Say I want to do something like

9.9 % 13

The normal python modulo will give me an output of 9.9. Are there any modules I can import that will instead give me an output of 6 (or more generally an integer value)?


Solution

  • Just do (99 mod 13 * inverse modulo ( 10, 13)) modulo 13

    99 mod 13 = 8, inverse modulo (10,13) = 4