1

The third line of code in the below example is giving 11 while all the other lines give 12. Any reason why this should happen? If there is a reason, any way to fix it?

> .03 %/% 0.0025
[1] 12
> .03 / 0.0025
[1] 12


> .3 %/% 0.025
[1] 11
> .3 / 0.025
[1] 12

> 3 %/% 0.25
[1] 12
> 3 / 0.25
[1] 12

This happens with multiple numbers btw, some more examples below -

> 0.35 %/% 0.025
[1] 13
> 0.35 / 0.025
[1] 14

> 0.85 %/% 0.025
[1] 33
> 0.85 / 0.025
[1] 34

> 0.425 %/% 0.025
[1] 16
> 0.425 / 0.025
[1] 17

> 0.975 %/% 0.025
[1] 38
> 0.975 / 0.025
[1] 39
TheComeOnMan
  • 12,535
  • 8
  • 39
  • 54

1 Answers1

1

I am not sure, but it was too long for a comment. From ?"%%":

%% and x %/% y can be used for non-integer y, e.g. 1 %/% 0.2, but the results are subject to representation error and so may be platform-dependent. Because the IEC 60059 representation of 0.2 is a binary fraction slightly larger than 0.2, the answer to 1 %/% 0.2 should be 4 but most platforms give 5.

Christoph
  • 6,841
  • 4
  • 37
  • 89