[R] integer overflow error problem
Robin Hankin
r.hankin at auckland.ac.nz
Mon Mar 31 06:00:23 CEST 2003
Hi List
Try the following simple set of functions (R-1.6.1):
square <- function(x){x*x}
cube <- function(x) {x*x*x}
f1 <- function(x){square(x)*(x+1)}
f2 <- function(x){square(x)+cube(x)}
error <- function(x){f1(x)-f2(x)}
[see how f1() and f2() are algebraically identical]. Then:
R> error(cube(20))
[1] 0
>
no problem. Then:
R> error(cube(1:20))
[1] 0 0 0 0 0 0 0 0 0 0 NA NA NA NA NA NA NA NA NA NA
Warning message:
NAs produced by integer overflow in: x * x * x
See how error() fails for the vector but not for the single number
argument. Is R being reasonable here?
--
Robin Hankin, Lecturer,
School of Geography and Environmental Science
Tamaki Campus
Private Bag 92019 Auckland
New Zealand
r.hankin at auckland.ac.nz
tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042
More information about the R-help
mailing list