From savicky at cs.cas.cz  Tue Mar 24 15:17:28 2009
From: savicky at cs.cas.cz (Petr Savicky)
Date: Tue, 24 Mar 2009 15:17:28 +0100
Subject: [Rd] Error in FrF2 example on Mac OS
In-Reply-To: <49C8E415.3060702@statistik.tu-dortmund.de>
References: <22675998.post@talk.nabble.com>
	<49C8E415.3060702@statistik.tu-dortmund.de>
Message-ID: <20090324141728.GC4963@cs.cas.cz>

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.



[Rd] Error in FrF2 example on Mac OS
Petr Savicky