Hi everybody, given a fresh rgui.exe load on winxp OS, I enter (a minimal exaple)
n <- 12.357531 Then the following command: n <- (n - floor(n))*10; n gives the following outputs: [1] 3.57531 [1] 5.7531 [1] 7.531 [1] 5.31 [1] 3.1 [1] 1 === still as expected [1] 10 === not expected, count with me: 1 - floor(1) is zero, times 10 gives 0, not 10!!!! [1] 10 === should stay forever zero (0) [1] 10 [1] 9.999998 [1] 9.999982 [1] 9.999821 [1] 9.998212 The sama happens with trunc(). e.g. (a minimal exaple) n <- 0.245 n <- (n - trunc(n))*10; n [1] 2.45 [1] 4.5 [1] 5 [1] 1.776357e-13 ===== zero expected!!! [1] 1.776357e-12 And I'm asking "what the heck?!" and where is the bug in my examples? Any suggestion well appreciated. p.s. The expression with floor() and trunc() are to be implemented in a function which gives a value equal precision order of the given number. e.g. 12.345 would have (-3), 12.1 would have (-1), 12 would have (0) and e.g. 12000 would have the order of the precision (4). Basically, it is the order of the last given non-zero digit. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.