Re: R-alpha: seq

Peter Dalgaard BSA (pd@kubism.ku.dk)
04 Dec 1996 11:49:46 +0100


To: Kurt.Hornik@ci.tuwien.ac.at
Subject: Re: R-alpha: seq
From: Peter Dalgaard BSA <pd@kubism.ku.dk>
Date: 04 Dec 1996 11:49:46 +0100
In-Reply-To: Kurt Hornik's message of Wed, 4 Dec 1996 10:17:19 +0100
Message-Id: <x2ybfe7fed.fsf@bush.kubism.ku.dk>

Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> writes:

> 
> >>>>> On Wed, 4 Dec 1996 09:37:30 +0100 (MET),
> >>>>> Jim Lindsey <jlindsey@luc.ac.be> said:
> 
> > 1. seq does not all give what is expected, apparently due to rounding.
> >   Something like seq(0.1,0.9,by=0.01) may stop at 0.9 or 0.89
> >   depending on what the end value is (i.e. if 0.9 is replace by 0.5)
> >   Sorry I forgot to note exactly what values workor not.
> 
> I can confirm that (Debian GNU/Linux ELF):
> 
> R> seq(0.1,0.2,by=0.01)
>  [1] 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20
> R> seq(0.1,0.3,by=0.01)
>  [1] 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24
> [16] 0.25 0.26 0.27 0.28 0.29
> 

This is of course quite logical. Never trust equality with floating
point. Splus doesn't seem to do it, though. In fact:

> seq(0.1,0.3,by=0.01000001)
 [1] 0.1000000 0.1100000 0.1200000 0.1300000 0.1400000 0.1500000 0.1600001
 [8] 0.1700001 0.1800001 0.1900001 0.2000001 0.2100001 0.2200001 0.2300001
[15] 0.2400001 0.2500001 0.2600002 0.2700002 0.2800002 0.2900002
> seq(0.1,0.3,by=0.010000001)
 [1] 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24
[16] 0.25 0.26 0.27 0.28 0.29 0.30
> seq(0.1,0.3,by=0.010000001)[21]-0.3
[1] 2e-08

So it must work with a slight fuzz factor inside, which is probably a
good thing. Is the pragmatic convention to declare numbers "equal" if
they print out identically?

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-