[R] noncommutative addition: NA+NaN != NaN+NA
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Sep 7 14:22:35 CEST 2004
On 7 Sep 2004, Peter Dalgaard wrote:
> 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?
Certainly over NA vs 0+NA, as in this excerpt from reg-tests-1.R
## matching NAs on Solaris (MM 2002-08-02)
# x <- as.double(NA)
# identical(x + 0, x)
# stopifnot(match(x + 0, x, 0) == 1)
## match failed on Solaris with some compiler settings
## NA+0 is not guaranteed to be NA: could be NaN
> 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.
--
Brian D. Ripley, ripley at 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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list