# Definition of Mod and Quotient with complex arguments

How are Mod and Quotient defined for three real/complex arguments? I wasn't able to find the definition.

My main surprise so far when investigating their behavior is a discontinuity between real and complex arguments. For real x, Mod[x,1,0] gives a result between 0 and 1. As soon as one adds a small imaginary part, the result's real part is now between -1/2 and 1/2.

Plot[Re[Mod[x, 1, 0]], {x, -1, 1}] Plot[Re[Mod[x+.001I, 1, 0]], {x, -1, 1}]    (* or (x-.001I) *) I can't find any confirmations in the documentation, but through numerical and visual checks I think when at least one input to Mod is not real, we have This definition doesn't equal the definition one would think to have over the reals, so my guess is a piecewise definition is used to modify the function over the real line.

# Testing

mod[z_, n_, d_] := z - n (Round[Re[(z - d)/n]] + I Round[Im[(z - d)/n]])


### Numerical check

rand = RandomComplex[{-10-10I, 10+10I}, {1000, 3}];

(mod @@@ rand) == (Mod @@@ rand)

True


### Visual check

Plot the argument in the complex plane of mod and Mod:

With[{z = x + I y, n = 1 + I/2, d = 0.1 + 0.2 I},
DensityPlot[
Arg[#[z, n, d]],
{x, -Re[n], Re[n]}, {y, -Re[n], Re[n]},
ColorFunction -> Hue,
Exclusions -> None,
PlotPoints -> 100
] & /@ {mod, Mod}
] Plot the absolute value of both in the complex plane:

With[{z = x + I y, n = 1 + I/2, d = 0.1 + 0.2 I},
Plot3D[
Abs[#[z, n, d]],
{x, -Re[n], Re[n]}, {y, -Re[n], Re[n]},
Exclusions -> None,
PlotPoints -> 100
] & /@ {mod, Mod}
] • Isn't it supposed to be Floor[] and not Round[]? May 5, 2016 at 13:43
• I thought so too but for d == 0, Round has cuts as a box centered at z == 0 rather than having cuts on the real line like Floor would leave. So maybe that's why it's chosen? May 5, 2016 at 13:46