Re: [Rd] double/integer (PR#7687)

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Sat 12 Feb 2005 - 08:13:15 EST

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



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Feb 12 07:26:24 2005

This archive was generated by hypermail 2.1.8 : Sat 12 Feb 2005 - 08:27:39 EST