Skip to content

matrix() can't handle NaN (PR#193)

3 messages · Brian Ripley, Peter Dalgaard

#
Can we backtrack here. I have just tried the original example on Solaris,
and matrix() _can_ handle NaN with a mature ANSI C library.

toucan% cat > junk.dat
x y z
1 1 1
1 2 2
2 1 NaN
2 2 4
toucan% R

R : Copyright 1999, The R Development Core Team
Version 0.64.1  (May 8, 1999)
...
[,1] [,2]
[1,]    1  NaN
[2,]    2    4

So on Solaris NaNs are read as such, and on Linux they are not.
and so does my R on Solaris. On Linux
Warning: NAs introduced by coercion
[1] FALSE

so I think there is a problem with Linux versions specifically. The
conversion is done by strtod. Solaris says (same man page)

     If str is NaN, then atof() returns NaN.

This sort of mess is my underlying objection: should we be assuming
IEEE arithmetic, let alone a particular implementation of it?
#
ripley@stats.ox.ac.uk writes:
Aha! I wonder if that is a Solaris specialty or actually conforming to
standards? A little digging on deja.com turned up a couple of blanket
statements to the effect that "any implementation where strtod can
return NaN is broken", but I'm not too sure about their authority.
Even the textual representation "NaN" is IEEE-854, not 754....

Whatever. I think we should fix as.double() (really: as.vector(x,
"double")) to accept the IEEE extended values in the same way that the
language itself does.
2 days later
#
Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:
Fixed now, for what is to become 0.65.0.