From murdoch@stats.uwo.ca  Wed Jan  8 14:49:05 2003
From: murdoch@stats.uwo.ca (Duncan Murdoch)
Date: Wed Jan  8 14:49:05 2003
Subject: [Rd] Undocumented bahavior of as.integer() (PR#2430)
In-Reply-To: <MABBLJDICACNFOLGIHJOOEGCDCAA.phgrosjean@sciviews.org>
References: <15900.623.369015.370021@gargle.gargle.HOWL> <MABBLJDICACNFOLGIHJOOEGCDCAA.phgrosjean@sciviews.org>
Message-ID: <faao1vckacru52gd5j9po3af58psoepoh9@4ax.com>

On Wed, 8 Jan 2003 14:19:20 +0100, you wrote in message
<MABBLJDICACNFOLGIHJOOEGCDCAA.phgrosjean@sciviews.org>:

>The problem is that it can lead to bugs in code using X[y] with y being a
>vector of doubles, and these bugs are very difficult to track. It is teach
>to R users that they do not need to bother too much about the storage mode.
>For instance, in the 'Introduction to R' manual, p.8:

I agree that this should be mentioned in the help page, but I don't
know any real code where it's likely to be a problem.  The main place
where people calculate indices is in array indexing schemes, and those
calculations work only on integers.  Even if they're stored as
doubles, integer calculations are exact, so the truncation wouldn't be
a problem.

The other place where floating point values might be used as indices
would be in interpolation schemes, and there it probably doesn't
matter much whether you use i-1, i, or i+1 as the index, as long as
identities like

   as.integer(x)  - 1 == as.integer(x-1)

hold.  That particular identity fails for x in (0, 1), but I think it
holds everywhere else that as.integer works; variations on it also
hold just about everywhere except near 0.

Do you know real examples where this really matters?

Duncan Murdoch



[Rd] Undocumented bahavior of as.integer() (PR#2430)
Duncan Murdoch