On 4/19/2007 4:29 PM, Bernhard Klingenberg wrote: > Thank you! Is floating point arithmetic also the reason why > > 1 %% 0.1 > > gives the "surprising" answer 0.1 (because 0.1 cannot be written as a > fraction with denominator a power of 2, e.g. 1%%0.5 correctly gives 0). > > This seems to go a bit against the statement in the help for '%%', which > states "For real arguments, '%%' can be subject to catastrophic loss of > accuracy if 'x' is much larger than 'y', and a warning is given if this > is detected."
I don't see the contradiction. The statement is talking about one way to get imprecise results; you may have found another. However, I'm not sure if you can blame %% in your example: the loss of precision probably came from the translation of "0.1" to the internal representation. I think "0.1" ends up a little bit larger than 0.1 after string conversion and rounding, so 1 %/% 0.1 should give 9, and 1 %% 0.1 should give something very close to 0.1, as you saw. Duncan Murdoch ______________________________________________ [email protected] 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.
