On May 6, 2005, at 09:00 am, Prof Brian Ripley wrote:

On Fri, 6 May 2005, Robin Hankin wrote:

[snip]

I worry about the use of identical() here, because I am comparing two floats for equality
as discussed in FAQ 7.31. Perhaps all.equal() would be better:


all.equal(1e99,1e99+1e83, tol=.Machine$double.eps)

Well, probably 2*.Machine$double.eps since each of two numbers could be one bit from the truth.



Yes, this makes a lot of sense, and will likely prevent me from flogging a dead horse by executing
dozens of pointless iterations in pursuit of the dregs of those last few binary digits at the tail end of
some float (not to mention infinite loops).


I would have thought that if x, y are scalars then identical(x,y) would be the same as
all.equal(x,y,tol=.Machine$double.eps).


And it is, most of the time.

But this caught me out just now:

R>  x <- 5352970674736366
R>  identical(x,x+1)
[1] FALSE

R> all.equal(x,x+1,tol=.Machine$double.eps)
[1] TRUE


Thus x and x+1 are not identical but nevertheless agree to within my machine precision, and
evidently my understanding of "machine precision" doesn't tally with Rreality.


Any comments?


The registers on ix86 machines have more precision than the representation stored in RAM. So it is possible that out.new has more precision because it has been kept in registers and out.old has been retrieved from RAM and so has less. The result may well be continued looping.

I think the scenario in the previous para is quite unlikely (it would need a very clever C compiler), but it is theoretically possible and may become likely with semi-compiled versions of R. The C-level equivalent is quite common.



--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
 tel  023-8059-7743

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to