On Fri, 11 Feb 2005 spencer@stats.ox.ac.uk wrote:
> Full_Name: Chris Spencer
> Version: 2.0.1
> OS: Linux
> Submission from: (NULL) (163.1.211.93)
>
>
> Dear R team,
>
> I realise that the following is a bit unsafe (the combination of doubles
and
> integers), however I wondered whether the following behaviour is expected:
>
>> #Test R
>> test <- vector(length=100000);
>> for(i in 1:100000){temp = i/1000; test[i] = (i == temp*1000);}
>> table(test);
> test
> FALSE TRUE
> 1472 98528
Certainly. You might even expect worse behaviour than that.
temp can be exactly represented in double precision only when i is a
multiple of 125. Depending on exactly how the computations are done and
how many extra guard digits are carried you could get FALSE for nearly all
i not a multiple of 125. The fact that you get TRUE 98% of the time is
better accuracy than you should expect.
-thomas