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

Ross Ihaka (ihaka@stat.auckland.ac.nz)
Thu, 5 Dec 1996 13:47:44 +1300 (NZDT)


From: Ross Ihaka <ihaka@stat.auckland.ac.nz>
Date: Thu, 5 Dec 1996 13:47:44 +1300 (NZDT)
Message-Id: <199612050047.NAA20586@stat13.stat.auckland.ac.nz>
To: Peter Dalgaard BSA <pd@kubism.ku.dk>
Subject: Re: R-alpha: Probably <float.h> instead of <values.h> for an automatic .Machine
In-Reply-To: <x2sp5lnafz.fsf@bush.kubism.ku.dk>
 <199612042211.LAA20451@stat13.stat.auckland.ac.nz>

Peter Dalgaard writes: 
 > 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. 

1e-7 sounds just peachy keen.

 > 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--) ...

The place I was going to fix was in the internal code for a:b.
We seem to compute an integer n as:
	n = b - a + 1;
I am just going to add the slop amount there:
	n = b - a + 1 + slop;
so that when n is computed marginally too small, all will be well.

This produces:
> seq(1e-9, 3e-9, by=1e-10)
 [1] 1.0e-09 1.1e-09 1.2e-09 1.3e-09 1.4e-09 1.5e-09 1.6e-09 1.7e-09 1.8e-09
[10] 1.9e-09 2.0e-09 2.1e-09 2.2e-09 2.3e-09 2.4e-09 2.5e-09 2.6e-09 2.7e-09
[19] 2.8e-09 2.9e-09 3.0e-09
> seq(0,3e-9, by=1e-10)
 [1] 0.0e+00 1.0e-10 2.0e-10 3.0e-10 4.0e-10 5.0e-10 6.0e-10 7.0e-10 8.0e-10
[10] 9.0e-10 1.0e-09 1.1e-09 1.2e-09 1.3e-09 1.4e-09 1.5e-09 1.6e-09 1.7e-09
[19] 1.8e-09 1.9e-09 2.0e-09 2.1e-09 2.2e-09 2.3e-09 2.4e-09 2.5e-09 2.6e-09
[28] 2.7e-09 2.8e-09 2.9e-09 3.0e-09

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