Why doesn't the following expression evaluate to zero?
In[1]:=Mod[1.2, 0.2]
Out[1]=0.2
Edit:
This is what I wanted to do:
xgrid = Table[{i,If[Mod[i, 0.2] == 0 , GrayLevel[0.5], GrayLevel[0.8]]}, {i, 0, 1.5, 0.05}]
I haven't programmed in a while so I forgot this happens. It was probably an error due to floating point arithmetic (0.2 cannot be fully represented by binary digits) so this was my solution:
xgrid = Table[{i*0.05, If[Mod[i, 4] == 0 , GrayLevel[0.5], GrayLevel[0.8]]}, {i, 0, 30, 1}]
This may also be the reason this solution for plotting minor and major grid lines didn't work for me
Mod[6/5, 1/5]
gives0
. $\endgroup$In[1]:= Mod[1.2, 0.2] // InputForm Out[1]//InputForm= 0.1999999999999999
$\endgroup$mod2pi
for modulus under exact 2*pi. From the documentation, "mod2pi(x): This function computes a floating point representation of the modulus after division by numerically exact 2pi, and is therefore not exactly the same as mod(x,2pi), which would compute the modulus of x relative to division by the floating-point number 2pi." This is an unpleasant but unavoidable feature of floating-point arithmetic. $\endgroup$Possible Issues
section of theMod
documentation, but there are no warnings of the behavior listed there. Maybe the OP can suggest it to bug support as a feature request for the documentation? $\endgroup$