[R] noncommutative addition: NA+NaN != NaN+NA
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Tue Sep 7 13:45:15 CEST 2004
Robin Hankin <rksh at soc.soton.ac.uk> writes:
> Dear Professor Ripley
>
> thank you for your reply.
>
> >
> >> > NaN +NA
> >> [1] NaN
> >> > NA + NaN
> >> [1] NA
> >>
> >> I thought "+" was commutative by definition. What's going on?
> >
> >It is clearly not under your compiler/OS. We could add a configure test
> >for broken systems and fix it in arithmetic.c but it hardly seems
> >worthwhile.
Didn't we do this discussion before? AFAIR, the thing is that IEEE
specifies that NaN + whatever == whatever + NaN == NaN, but NaN is
only specified a bit pattern in the first couple of bytes. R uses a
special value in the lower bytes (1954 -- BTW, when *is* Ross'
birthday?) to signal the NA, but we can't really expect that chip
makers do what we hope they'd do with that part of the value. I think
we resolved that specific checking for this issue would be too much of
a performance killer, especially since R generally treats NaN as NA
anyway.
> [snip]
>
> > > (Both give NA under linux, so it looks like a version-specific issue).
> >
> >Linux on that hardware? It might be a chip issue.
>
>
> Sorry, that should read "Both give NA under linux on an i686 system,
> RedHat Linux 2.4.18"
>
> In any event, "+" appears to be associative (which is what I was
> interested in).
Eh? That is something that is almost certainly not true for FP
arithmetic, e.g.
> (1 + 1e-16) + 1e-16 == 1 + (1e-16 + 1e-16)
[1] FALSE
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list