0

I noticed recently a weird behavior when I wanted to differentiate a variable by the remainder.

x <- ifelse(48.002 %% 1 == 0.002, 1, 0)

However, testing the logic operation above showed this is not true.

48.002 %% 1 == 0.002
[1] FALSE

While if I use >= instead of ==, it could identify correctly:

48.002 %% 1 >= 0.002
[1] TRUE
 48.001 %% 1 >= 0.002
[1] FALSE

Could someone please help me understand why this is happening? Thanks.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
Xinting WANG
  • 1,905
  • 2
  • 15
  • 20

0 Answers0