From tlumley at u.washington.edu  Fri Feb 11 22:13:15 2005
From: tlumley at u.washington.edu (Thomas Lumley)
Date: Fri Feb 11 22:13:29 2005
Subject: [Rd] double/integer (PR#7687)
In-Reply-To: <20050211191349.E8D1CDEE7@slim.kubism.ku.dk>
References: <20050211191349.E8D1CDEE7@slim.kubism.ku.dk>
Message-ID: <Pine.A41.4.61b.0502111302430.306218@homer11.u.washington.edu>

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


[Rd] double/integer (PR#7687)
Thomas Lumley