I have a silly question.

k = 0.15;
kf = 0.03;
Mod[k, kf]

is giving me 0 as it should but when I change kf to 0.05 like

k = 0.15;
kf = 0.05;
Mod[k, kf]

it is giving me 0.05 when it should also be zero.

In short: while does Mathematica think that Mod[0.15, 0.05] = 0.05?

  • $\begingroup$ Machine numbers in a computer are not the same as decimal numbers for pen and paper. Here you need exact numbers, so use k=15/100, kf=3/100, 5/100. The answer to your question is: numerical noise. $\endgroup$ Oct 19 '16 at 11:53
  • $\begingroup$ Also related. $\endgroup$
    – corey979
    Oct 19 '16 at 11:58
  • $\begingroup$ Thank you Fred, that helps though it is still unclear why it does it correctly in one case and incorrectly in another $\endgroup$
    – Sayak
    Oct 19 '16 at 15:25

Browse other questions tagged or ask your own question.