I am trying to find a way to do (w+xi) % (y+zi)
in Python.
I have tried cmath
but it doesn't seem to have support for this. I have made sure it is mathematically possible and attempted to program it, however it didn't work. The code is below, I found that the issue was sometime after dividing numbers would need to be rounded but at other times this produced an incorrect result.
def ComplexModulo(a,b):
x = a/b
x = round(x.real) + (round(x.imag)*1j)
z = x*b
return a-z
I need a better way to figure this out, as right now if I do (8+2j)%(2+1j)
I should get (1+1j)
, but I instead get (-1+0j)
. I tried also changing round
to int
, and different combinations of that, and although it worked in some instances it failed in others.