a nasty error --> patch to seq.R
Martin Maechler
Martin Maechler <maechler@stat.math.ethz.ch>
Fri, 4 Sep 1998 15:26:29 +0200
>>>>> "Peter" == Peter Holzer <holzer@stat.math.ethz.ch> writes:
Peter> ... The basic function seq doesn't work properly:
>> seq(1,6,by=3)
Peter> [1] 1 4 7
Peter> Looking at the source code of seq.default I found that strange
Peter> fuzz thing "+ 0.4". Taking that away the seq works fine.
Peter> My question is: Why has this fuzz thing been added?
Peter> If it was for some rounding problems I would suggest to replace
Peter> "0.4" by something much smaller.
This bug was introduced between 0.62.1 and 0.62.2 --
with the aim to fix another one.
After some thinking and some experimentation, I conclude that there is no
easy architecture-independent ``fudge constant'' that can be used here
instead of 0.4. One needs to use a subsequent test.
Here is a patch that seems "robust" (and passes my tests):
--- ../R-0.62.3/src/library/base/R/seq.R Tue Jun 16 14:32:08 1998
+++ src/library/base/R/seq.R Fri Sep 4 15:23:11 1998
@@ -16,9 +16,11 @@
if(missing(by))
from:to
else {
- n <- (to - from)/by + 0.4 # fuzz needed
+ n <- (to - from)/by
if(n < 0)
stop("Wrong sign in by= argument")
+ n <- as.integer(n + 1e-10)
+ if(n*by + from > to) n <- n - 1
from + (0:n) * by
}
else if(length.out < 0)
---
Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum SOL G1; Sonneggstr.33
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1086 <><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._