Re: [R] Integer / floating point question

From: Berwin A Turlach <statba_at_nus.edu.sg>
Date: Sat, 17 May 2008 04:03:05 +0800

G'day Brian,

On Fri, 16 May 2008 19:28:59 +0100 (BST) Prof Brian Ripley <ripley_at_stats.ox.ac.uk> wrote:

> 'numeric' is a class but not a type -- so I think the FAQ is wrongly
> worded but the concept is well defined

Though there may be multiple definitions. :-)

Reading a bit in "R Language Definition" (yes, I am aware that it is a draft), 'numeric' seems to be also used as a mode. I guess this comes from S3, the mode (no pun intended) that I am still using and thinking in mostly, and that 'numeric' being a class came in with S4. And I notice that mode(1L) and class(1L) gives different results, the former returns "numeric" while the latter returns "integer".  

Hence, when I read "R's numeric type" in the FAQ, I take this as referring to those basic types that are of mode numeric, i.e. integer and real. I am not sure whether changing this to "R's object of mode 'numeric'" or "R's object class 'numeric'" will make the answer more readable/understandable.

> But it does not say that all such numbers can be represented
> exactly, and only some can.

I am well aware that integers and reals can only hold "integers and fractions whose denominator is a power of 2" from a limited range; in particular, the former will not hold any fractions. However, given the discussion in Goldberg (which FAQ 7.31 points to) on changing from binary to decimal representation and back, I would expect that given any such number (within the appropriate range) in decimal representation, it would be transformed into the correct, exact binary representation. However, I also know that if I stumble across an example where this is not the case, I shall only complain after ensuring that documented behaviour is violated and that the FAQ not necessarily documents expected behaviour.

I guess Duncan's answer said it all, at the extreme ends of the appropriate ranges surprises might lurk, but it would be considered a serious bug if R did not transform small integers into their exact binary representation.

Cheers,

        Berwin



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 16 May 2008 - 20:08:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 16 May 2008 - 21:30:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive