[R] binary coding of NA, Nan etc.
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Sep 28 17:33:09 CEST 2001
On Fri, 28 Sep 2001, Laurent Gautier wrote:
> Thanks to the Pr. Ripley for the precise explanations.
> Not so long long ago, I have been generating numerical binary data file
> using java, and noticed that Double.NaN in java was just something very
> big (1.797693e+308) when read in R through readBin. Being too lazy/in a
> hurry to look for the reason I just turned the values greater than or
> equal to that into NA when read in R.
> As that is a rather dirty way of doing things, and as I am ignorant in
> numbers binary representation, I was thinking a paramater to readBin or
> writeBin specifying the convention wanted for the could be nifty.
> Does it makes (any) sense ?
How would you specify it? You would need a way to specify the bit pattern
(of the source or target endianness?) of Inf, -Inf, NA, the class of NaNs
(there are many of them) for doubles and perhaps floats too. And R
has no type to represent such bit patterns.
I would expect all compiled languages to be using the same representations
on modern hardware. However, Java is not in that sense compiled and may
well be different: I have no idea.
One thing I did not say before: R's standard NA is the NaN with low word
of 1954. I have no idea how to generate that on another system except
via the sort of sneaky tricks arithmetic.c plays. The multiplicity
of NaNs complicates this enormously.
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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
r-help 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-help-request at stat.math.ethz.ch
More information about the R-help