On Thu, Oct 20, 2011 at 10:37 AM, peter dalgaard <pda...@gmail.com> wrote:
> > On Oct 20, 2011, at 16:50 , David Winsemius wrote: > > > That does seem to be an infelicity that ought to be fixed. Using the > infix addition operator does that same sort of coercions, so why would one > expect the infix multiplication operator to refuse to do it? > > > > > (sum(1000:1205))*(sum(1000:1204) +1205) > > [1] 51581223225 > > The addition operator doesn't either: > > > (sum(1000:1205))*(sum(1000:1204) +1205L) > [1] NA > Warning message: > In (sum(1000:1205)) * (sum(1000:1204) + 1205L) : > NAs produced by integer overflow > > Beware that 1:1 is integer but 1 is not. > Exactly. In order to prevent calculations from overflow, "as.real(...)" may be used for manual coercion (sometimes the machine is not that intelligent to do automatic coercing) or users can check the type of constants/variables as follows: > typeof(1) [1] "double" > typeof(sum(1:100)) [1] "integer" > -- > Peter Dalgaard, Professor > Center for Statistics, Copenhagen Business School > Solbjerg Plads 3, 2000 Frederiksberg, Denmark > Phone: (+45)38153501 > Email: pd....@cbs.dk Priv: pda...@gmail.com > > -- Lei Jiang Center for Computation and Technology/ Department of Computer Science Louisiana State University E-mail: lji...@cct.lsu.edu [[alternative HTML version deleted]] ______________________________________________ R-help@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.