[R] integer overflow error problem

Martin Maechler maechler at stat.math.ethz.ch
Mon Mar 31 09:12:00 CEST 2003


>>>>> "Robin" == Robin Hankin <r.hankin at auckland.ac.nz>
>>>>>     on Mon, 31 Mar 2003 16:00:23 +1200 writes:

    Robin> Hi List Try the following simple set of functions
    Robin> (R-1.6.1):

    Robin>  square <- function(x){x*x} cube <- function(x)
    Robin> {x*x*x} f1 <- function(x){square(x)*(x+1)} f2 <-
    Robin> function(x){square(x)+cube(x)} error <-
    Robin> function(x){f1(x)-f2(x)}

    Robin> [see how f1() and f2() are algebraically identical].
    Robin> Then:

    R> error(cube(20))
    Robin> [1] 0
    >>

    Robin> no problem.  Then:

    R> error(cube(1:20))
    Robin>  [1] 0 0 0 0 0 0 0 0 0 0 NA NA NA NA NA NA NA NA NA
    Robin> NA Warning message: NAs produced by integer overflow
    Robin> in: x * x * x


    Robin> See how error() fails for the vector but not for the
    Robin> single number argument.  Is R being reasonable here?

yes,  `as always' :-)

The clue is:  20 is not integer, but 20:20 or as.integer(20) is

Martin






    Robin> --

    Robin> Robin Hankin, Lecturer, School of Geography and
    Robin> Environmental Science Tamaki Campus Private Bag 92019
    Robin> Auckland New Zealand

    Robin> r.hankin at auckland.ac.nz tel 0064-9-373-7599 x6820;
    Robin> FAX 0064-9-373-7042

    Robin> ______________________________________________
    Robin> R-help at stat.math.ethz.ch mailing list
    Robin> https://www.stat.math.ethz.ch/mailman/listinfo/r-help



More information about the R-help mailing list