Modulo operator in Python
Question: What does modulo in the following piece of code do?

    
    
    from math import *
    3.14 % 2 * pi
    

How do we calculate modulo on a floating point number?


Answer: Mathematically, the modulo operator can be represented as:

    
    
    a % b = c
    a - n*b = c
    

Where `n` is an integer that makes `c` as small as possible, but positive.

In this case:

    
    
      3.14 % 2
    = 3.14 - 1 * 2
    = 1.14
    

Also, `3.14 % 2 * pi` is interpreted as `(3.14 % 2) * pi`. I'm not sure if you
meant to write `3.14 % (2 * pi)` (in either case, the algorithm is the same.
Just subtract/add until the number is as small as possible).

