On Thu, 24 Jan 2002, Winfried Theis wrote:
Dear Prof. Ripley, On 24-Jan-02 Prof Brian Ripley wrote:
0.1 cannot be represented exactly in binary arithmetic. You asked for the representation to 22 digits, and at most 17 are used in IEEE arithmetic. This is not a bug in R, which does not claim to have arbitrary precision.
Okay, I do not expect arbitrary precision, but maybe a warning in some way would be in order, to tell non-experts, what can be expected... As I said I came across this, when I searched for an error and this might be the reason for it. When comparing distances in one dimension within the sequence seq(0,1,by=0.1), I found that R does not take the distances between (0.3, 0.5) and (0.5,0.7) to be equal.
abs(0.5-0.3)==abs(0.5-0.7)
[1] FALSE Checking this now a bit closer with your information I found:
round(abs(0.5-0.3),digits=17)==round(abs(0.5-0.7),digits=17)
[1] FALSE
round(abs(0.5-0.3),digits=16)==round(abs(0.5-0.7),digits=16)
[1] TRUE Would it be possible to restrict "==" as well to the maximum number of digits used in the arithmetics? It would be very convenient to get the expected result from such a comparison.
There is a function all.equal provided for this purpose: it is a misuse of ==.
Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._