# Modulo of complex numbers

#### erroneum

##### Banned
Hello,
I am familiar with the modulo (division remainder) operator on real numbers, but I am needing to implement (in software) modulo on complex numbers, and am wondering if there is a general, universally accepted method for getting the same thing, and if so, what it is.

#### daon2

##### Full Member
Nonzero complex numbers always divide evenly into each other. By "evenly" of course I mean for any complex x and y (y not 0) there always exists a unique complex number z such that zy=x. This is true of any field. So the remainder is always zero...

If you mean the Gaussian Integers, you'll first need to define your norm. Typically |x+iy| = sqrt(x^2+y^2). Then if a+bi and x+iy are Gaussian Integers, then there always exists unique r,q in Z such that (a+bi) = (x+yi)*q + r, where 0<= |r| < |x+yi|. See here for the division algorithm: http://fermatslasttheorem.blogspot.com/2005/06/division-algorithm-for-gaussian.html

Last edited:

#### erroneum

##### Banned
Interesting. I went to WolframAlpha, and entered "(6+4i)mod(3+5i)" and was given the answer "-2+2i." Assuming what you said to be true, I don't know how that answer was generated, but it is more like what I am looking for than 0 for any complex number.

To explain why I ask this, I am writing a calculator. It uses postfix notation, and operates on arbitrary precision complex numbers. One of the operations that is defined is modulus, and I would like it to work for all inputs, rather than just all real inputs. Since WolframAlpha does not tell me how it arrived at it's result, I can only hope that someone here can.

#### Subhotosh Khan

##### Super Moderator
Staff member
I think the problem is that the MOD operation is only defined in Integer field. If you consider all the real numbers - then there is no residue. Similar situation is in complex field. Now if you restrict the field such that (a,b) are integers only, then you'll get modulo result.

Last edited by a moderator:

#### erroneum

##### Banned
I have seen mod extended to support all real numbers, and WolframAlpha will compute it for all complex numbers as well. As I have seen it in software, the modulus of non-integer real numbers a and b is something like a-floor(a/b)*b.

Actually, now that I look at the extended list of alternate representations, it appears that WolframAlpha uses the method that I saw in software.

Last edited: