stgries at gmail.com
2007-Dec-01 00:40 UTC
[Rd] NAs produced by integer overflow (PR#10482)
Full_Name: Stefan Th. Gries Version: R version 2.6.1 (2007-11-26) OS: Windows XP Home SP2 Submission from: (NULL) (68.6.47.105) Hi A simple computation results in integer overflow: These are the relevant vectors:> sum(cur.obs)[1] 110231> colfreqother past perfect present progressive 14845 1222 4776 101347 2863> sum(colfreq)[1] 125053 Now ... # this works ...> sum(cur.obs)*(colfreq/sum(colfreq)) # note: brackets around the divisionother past perfect present progressive 13085.485 1077.162 4209.921 89334.771 2523.661 # and this doesn't ...> sum(cur.obs)*colfreq/sum(colfreq) # note: no brackets around the divisionother past perfect present progressive 13085.485 1077.162 4209.921 2523.661 Warning message: In sum(cur.obs) * colfreq : NAs produced by integer overflow I saw this was reported for R 2.3.0 and 2.6.0 before, but I don't know whether it ever got dealt with. Here's my version information: # ------------------------------------- platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 6.1 year 2007 month 11 day 26 svn rev 43537 language R version.string R version 2.6.1 (2007-11-26) # ------------------------------------- STG
stgries at gmail.com wrote:> Full_Name: Stefan Th. Gries > Version: R version 2.6.1 (2007-11-26) > OS: Windows XP Home SP2 > Submission from: (NULL) (68.6.47.105) > > > Hi > > A simple computation results in integer overflow: > > These are the relevant vectors: > > >> sum(cur.obs) >> > [1] 110231 > > >> colfreq >> > other past perfect present progressive > 14845 1222 4776 101347 2863 > > >> sum(colfreq) >> > [1] 125053 > > Now ... > > # this works ... > >> sum(cur.obs)*(colfreq/sum(colfreq)) # note: brackets around the division >> > other past perfect present progressive > 13085.485 1077.162 4209.921 89334.771 2523.661 > > # and this doesn't ... > >> sum(cur.obs)*colfreq/sum(colfreq) # note: no brackets around the division >> > other past perfect present progressive > 13085.485 1077.162 4209.921 2523.661 > Warning message: > In sum(cur.obs) * colfreq : NAs produced by integer overflow > > > > I saw this was reported for R 2.3.0 and 2.6.0 before, but I don't know whether > it ever got dealt with.Well, it is what happens when you multiply two large integers. How would you expect it to be "dealt with"? If we are to have a rule that the product of two integers is an integer, there's no alternative. Alternatively, the result could be automatically coerced to double and would then unpredictably be either integer or double.> Here's my version information: > > # ------------------------------------- > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 6.1 > year 2007 > month 11 > day 26 > svn rev 43537 > language R > version.string R version 2.6.1 (2007-11-26) > # ------------------------------------- > > STG > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
ripley at stats.ox.ac.uk
2007-Dec-01 13:55 UTC
[Rd] NAs produced by integer overflow (PR#10482)
What is the bug here? You haven't told us what you think it is, and> 110231L * 101347L[1] NA Warning message: In 110231L * 101347L : NAs produced by integer overflow is both intentional and documented: see ?Arithmetic. Please do give a reproducible example (as we ask): yours is not as we have to guess the types of the objects (I can get similar results if I guess "integer", but not quite the same). cur.obs <- 110231L colfreq <- as.integer(c(14845,1222,4776,101347,2863)) names(colfreq) <- c("other","past","perfect","present","progressive") sum(cur.obs)*(colfreq/sum(colfreq)) other past perfect present progressive 13085.485 1077.162 4209.921 89334.771 2523.661 sum(cur.obs)*colfreq/sum(colfreq) other past perfect present progressive 13085.485 1077.162 4209.921 NA 2523.661 Warning message: In sum(cur.obs) * colfreq : NAs produced by integer overflow Note the fourth entry. On Sat, 1 Dec 2007, stgries at gmail.com wrote:> Full_Name: Stefan Th. Gries > Version: R version 2.6.1 (2007-11-26) > OS: Windows XP Home SP2 > Submission from: (NULL) (68.6.47.105) > > > Hi > > A simple computation results in integer overflow: > > These are the relevant vectors: > >> sum(cur.obs) > [1] 110231 > >> colfreq > other past perfect present progressive > 14845 1222 4776 101347 2863 > >> sum(colfreq) > [1] 125053 > > Now ... > > # this works ... >> sum(cur.obs)*(colfreq/sum(colfreq)) # note: brackets around the division > other past perfect present progressive > 13085.485 1077.162 4209.921 89334.771 2523.661 > > # and this doesn't ... >> sum(cur.obs)*colfreq/sum(colfreq) # note: no brackets around the division > other past perfect present progressive > 13085.485 1077.162 4209.921 2523.661 > Warning message: > In sum(cur.obs) * colfreq : NAs produced by integer overflow > > > > I saw this was reported for R 2.3.0 and 2.6.0 before, but I don't know whether > it ever got dealt with. Here's my version information:Please don't be vague: you need to give URLs for claims that something is 'reported'.> # ------------------------------------- > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 6.1 > year 2007 > month 11 > day 26 > svn rev 43537 > language R > version.string R version 2.6.1 (2007-11-26) > # ------------------------------------- > > STG > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- 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 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595