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
Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– Nov 23 '14 at 17:03Mod[6/5, 1/5]gives0. – DumpsterDoofus Nov 23 '14 at 17:04Out[1]//InputForm= 0.1999999999999999`
– Daniel Lichtblau Nov 23 '14 at 17:06Rationalize. – Kuba Nov 23 '14 at 17:07The arguments of Mod can be any numeric quantities, not necessarily integers. So I don't think it is expected. – Kuba Nov 23 '14 at 17:09mod2pifor 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. – DumpsterDoofus Nov 23 '14 at 17:24Possible Issuessection of theModdocumentation, 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? – DumpsterDoofus Nov 23 '14 at 17:38