0

I have a list of numerator and denominator that I want to see if the numerator is divisible by the denominator (i.e. remainder being zero), please see the dataset in R as below:

structure(list(numerator = c(40.77, 38.88, 117.6, 
                         591.9, 592.9, 165.2, 164.1, 568.8, 802.8, 11.4, 862.6, 106.4, 
                         583.872, 4.44, 5.61, 25.4, 3.9, 29.2, 19.2),
           denominator = c(0.09, 
                           0.09, 0.1, 0.1, 0.1, 0.1, 0.1, 3.6, 3.6, 3.8, 3.8, 3.8, 0.024, 
                           0.03, 0.03, 0.1, 0.1, 0.1, 0.1)), 
      class = c("tbl", "data.frame"), 
      row.names = c(NA, -19L), 
      .Names = c("numerator", 
                 "denominator")) %>%
mutate(quotient=numerator%/%denominator,
       remainder=numerator%%denominator)

I found all rows have remainder calculated, but this should not be, because for example 5.61 should be divisible by 0.1.

I have somehow heard that this is related to issues related to "flowing number", but I only have a faint idea on that, can someone:

  1. explain why this will happen (I am not trained in computer science, sorry for asking something stupid)

  2. how can I fix this?

Thanks!

lokheart
  • 23,743
  • 39
  • 98
  • 169
  • It's unclear why this needs to be fixed. You could simply round. Or you could use arbitrary precision numbers. – Roland Oct 19 '18 at 10:37
  • Your row with `5.610` has denominator `0.030` in the current data set. The result here, `8.8e-16` is simply a floating number result that is very close to zero. – MrGumble Oct 19 '18 at 10:37

0 Answers0