From ripley@stats.ox.ac.uk  Wed May 12 12:07:00 1999
From: ripley@stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Wed, 12 May 1999 13:07:00 +0200 (MET DST)
Subject: matrix() can't handle NaN (PR#193)
Message-ID: <199905121107.NAA29025@pubhealth.ku.dk>

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)
...

> data <- read.table("junk.dat",header=TRUE)
> x<-unique(data$x)
> y<-unique(data$y)
> matrix(data$z,length(y),length(x)) 
     [,1] [,2]
[1,]    1  NaN
[2,]    2    4

So on Solaris NaNs are read as such, and on Linux they are not.


> From: Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk>
> Date: 12 May 1999 11:27:17 +0200

> We do allow them as constants in the language itself, so I suppose we
> could do it in read.table as well - this really means inside
> as.double, I suppose. The prototype does this:
> 
> Splus> is.nan(as.double("NaN"))
> [1] T

and so does my R on Solaris. On Linux

> is.nan(as.double("NaN"))
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?

-- 
Brian D. Ripley,                  ripley@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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


matrix() can't handle NaN (PR#193)
ripley@stats.ox.ac.uk