On Tue, Mar 24, 2009 at 02:45:57PM +0100, Uwe Ligges wrote:
> >gives the custom error message "nruns must be a power of 2.", which is
> >generated in the first check within function FrF2:
> >
> > if (!is.null(nruns)){
> > k <- floor(log2(nruns))
> > if (!2^k==nruns) stop("nruns must be a power of 2.")}
>
>
> Probably a rounding issue on different platforms?
> I guess the test should be something like:
>
> if (!is.null(nruns)){
> if(!isTRUE(all.equal(log2(nruns) %% 1, 0)))
> stop("nruns must be a power of 2.")
> }
Probably, k is needed also later. Assumig that 2^k works correctly,
the following could be sufficient
if (!is.null(nruns)){
k <- round(log2(nruns))
if (!2^k==nruns) stop("nruns must be a power of 2.")}
In order to test the assumption, one can use
x <- 2^(0:100 + 0) # use double exponent to be sure
all(x == floor(x))
Powers of two are represented exactly, since they have only one significant bit.
Petr.
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel