[Rd] integer overflow

From: roger koenker <rkoenker_at_uiuc.edu>
Date: Thu 02 Sep 2004 - 02:16:36 EST


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@uiuc.edu			Department of Economics
vox: 	217-333-4558				University of Illinois
fax:   	217-244-6678				Champaign, IL 61820

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu Sep 02 02:19:35 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:45:12 EST