Re: R-alpha: Probably <float.h> instead of <values.h> for an automatic .Machine

Peter Dalgaard BSA (pd@kubism.ku.dk)
05 Dec 1996 00:42:24 +0100

```To: Ross Ihaka <ihaka@stat.auckland.ac.nz>
Subject: Re: R-alpha: Probably <float.h> instead of <values.h> for an automatic .Machine
From: Peter Dalgaard BSA <pd@kubism.ku.dk>
Date: 05 Dec 1996 00:42:24 +0100
In-Reply-To: Ross Ihaka's message of Thu, 5 Dec 1996 11:11:58 +1300 (NZDT)
Message-Id: <x2sp5lnafz.fsf@bush.kubism.ku.dk>

Ross Ihaka <ihaka@stat.auckland.ac.nz> writes:

> I think the solution to the seq problem is just to add a small slop
> factor before rounding.  My empirical experiments with Splus indicate
> that they use a value of about 1.e-7.  I would propose using
> FLT_EPSILON from <float.h>.  Does this seem reasonable?

Not quite. I seem to recall that float/double is like int/long in C -
it is only guaranteed that the former contains at most as many bits as
the latter. It won't work if you actually get DBL_EPSILON in there!
Besides, there is no particular reason to use a machine constant
("mark with chalk and cut with a microtome...") , you might as well
just set it at 1e-7, with the implicit assumption that doubles on all
machines now and in the future will be much more accurate than that.

It is all a bit sticky: Absolute slop will get you in trouble with e.g.

seq(1e-9, 3e-9, by=1e-10)

relative slop could get you in trouble with from=0. The right thing
is probably like

fuzz = 1 + 1e-7
n = (to - from) * fuzz / by + 1
...
while (n--) ...

--
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
```