[R] Basic question on function "identical"

Paul Johnson pauljohn at ku.edu
Mon Dec 15 22:34:11 CET 2003


I hope I am not telling you things you already know. If so, I apologize 
in advance.

There are several C-library addons available to try to deal with the 
problem that comparisons of floating point numbers can be 
unpredictable.  I think your example with the greater than sign would 
not be a source of the trouble, but if you ended it with a comparison like

if (xmax == 10.7)

then you would be in trouble because the internal representation of the 
float xmax might not be precisely equal to 10.7.

Until I hear otherwise, I am thinking that ordinal comparisons like (x > 
xmax) are accurate, but that equality comparisons like (x==xmax) are not. 

Here's one of the C library projects dealing with the subject:

http://fcmp.sourceforge.net/

The author of that library, Ted Belding, did this paper, "Numerical 
Replication of Computer Simulations: Some Pitfalls...", which is 
informative (IMHO):
http://alife.ccp14.ac.uk/ftp-mirror/alife/zooland/pub/research/ci/EC/GA/papers/gecco2000.ps.gz

Also check this web page, which I bookmarked:
http://vision.eng.shu.ac.uk/C++/c/c-faq/cfaq14.html#r14.6

I know I've seen more, but can't remember where.

Ted Harding wrote:

>For instance,
>in C-speak, to find the maximum of an array of double x[], of
>length n, something like the following code could be written:
>
>  xmax=x[1];
>  for(i=1;i<n;i++) if(x[i+1]>x[i]) xmax=x[i+1];
>
>Regardless of the accuracy of the comparison, each assignment
>xmax = ... should make xmax an internally exact copy of the
>thing on the righthand side. However, your reply suggests that this
>may not happen, as a result of "unpredictable use of 10-byte wide
>floating point registers on Intel chips".
>  
>


-- 
Paul E. Johnson                       email: pauljohn at ku.edu
Dept. of Political Science            http://lark.cc.ku.edu/~pauljohn
1541 Lilac Lane, Rm 504                              
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66044-3177           FAX: (785) 864-5700




More information about the R-help mailing list