[R] integer overflow error problem

Martin Maechler maechler at stat.math.ethz.ch
Tue Apr 1 09:35:08 CEST 2003

>>>>> "BDR" == Prof Brian Ripley <ripley at stats.ox.ac.uk>
>>>>>     on Mon, 31 Mar 2003 21:57:12 +0100 (BST) writes:

    BDR> On Tue, 1 Apr 2003, Robin Hankin wrote:
    BDR> [...]

    >> Now _why_ does colon have this behaviour, when it seems that very few
    >> other functions return integers; help(":") gives no clue to the
    >> motivation.  Splus does the same thing (apparently), so there must be
    >> some rationale.  What is it?

    BDR> If you mean integers, it helps to have them to avoid rounding errors.
    BDR> S-PLUS (sic) currently thinks 20 is integer and 20. is double.

Other good rationales for "m:n" integers are
- it's half the size; at least useful if  |n-m| is big.
- when used   for(i in m:n)  {  ... x[i] ... }
  `i' is integer and will be used as such in almost all cases.

    >> Also, it would appear, both "if(2+2==4)" and "(1:10)==4" are
    >> inadvisable, because in both cases, at least one side of the "==" is a
    >> double.  How do I get round this?

    BDR> ?identical
    BDR> ?as.equal
          ^^^  typo, meant

    BDR> BTW, == does coerce as needed, so 2+2==as.integer(4) is fine.

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/

More information about the R-help mailing list