Re: [Rd] Inaccuracy in seq() function (PR#7503)

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Thu 13 Jan 2005 - 07:40:26 EST

And the bug is?

You don't expect 1.60 + 0.05 == 1.65 do you? None of those numbers can be represented exactly in a binary computer, so there are bound to be small errors as you have noted.

See the warning in help("=="), and the section on BUGS in the FAQ.

On Wed, 12 Jan 2005 vstolin@lordabbett.com wrote:

> Full_Name: Vlad Stolin
> Version: R 2.0.0
> OS: Windows 2000
> Submission from: (NULL) (204.128.232.211)
>
>
> When generating the sequence using seq() function with non-integer numbers
> result is somewhat unpredictable. Example:
>> v1<-seq(1.60,1.90,.05)
>> v2<-c(1.60,1.65,1.70,1.75,1.80,1.85,1.90)
>> v1-v2
> [1] 0.000000e+00 2.220446e-16 2.220446e-16 0.000000e+00 0.000000e+00
> 0.000000e+00 2.220446e-16
>> v1==v2
> [1] TRUE FALSE FALSE TRUE TRUE TRUE FALSE
>> v1>1.70 & v2<1.80
> [1] FALSE FALSE TRUE TRUE FALSE FALSE FALSE

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu Jan 13 06:47:53 2005

This archive was generated by hypermail 2.1.8 : Thu 13 Jan 2005 - 07:20:24 EST