From rkoenker at uiuc.edu  Wed Sep  1 18:16:36 2004
From: rkoenker at uiuc.edu (roger koenker)
Date: Wed Sep  1 18:16:34 2004
Subject: [Rd] integer overflow
Message-ID: <4C7F60F4-FC32-11D8-9730-000A95A7E3AA@uiuc.edu>

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


[Rd] integer overflow
roger koenker