[Rd] integer overflow

roger koenker rkoenker at uiuc.edu
Wed Sep 1 18:16:36 CEST 2004


I had a question from a SparseM  user this morning who wanted to do 
something
like this:  (his dimensions, my data)

require(SparseM)
ia <- sample(1:52993,351718,replace=TRUE)
ja <- sample(1:52993,351718,replace=TRUE)
ra <- rnorm(351718)
dim <- as.integer(rep(52993,2))
A <- new("matrix.coo",ra=ra,ia=ia,ja=ja,dim=dim)

The last step failed because validity checking for objects of class 
matrix.coo
wanted to test whether  length(ra)  > prod(dim), but unfortunately I'd 
implemented
the test as nrow*ncol and both were integers of size 52993 so the 
product
produced an integer overflow.  I see in R-help that there was some 
discussion
of this sort of thing with sum() and it appears that perhaps prod was 
also adapted
to avoid this problem.  I'm just wondering whether there was some more 
general
lesson to be learned here.  Other than the well-known "expect the 
unexpected."


url:	www.econ.uiuc.edu/~roger        	Roger Koenker
email	rkoenker at uiuc.edu			Department of Economics
vox: 	217-333-4558				University of Illinois
fax:   	217-244-6678				Champaign, IL 61820



More information about the R-devel mailing list