[Rd] Representation of floating point numbers (PR#1281)

theis@statistik.uni-dortmund.de theis@statistik.uni-dortmund.de
Thu, 24 Jan 2002 14:06:07 +0100 (MET)


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.

Thank you -- and of course the whole core-team -- for your efforts to make this
great software!

Regards,

Winfried Theis
----------------------------------
E-Mail: Winfried Theis <theis@statistik.uni-dortmund.de>
Date: 24-Jan-02
Time: 12:50:35
Dipl.-Math. Winfried Theis, Fachbereich Statistik, Graduiertenkolleg
"Angewandte Statistik"
Universität Dortmund, 44221 Dortmund
Tel.: +49-231-755-5903  FAX: +49-231-755-4387
----------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._