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

On Tue, Mar 24, 2009 at 07:41:31AM -0700, Ulrike Gr?mping wrote:
> > 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.
> > 
> 
> Yes, round instead of floor should also do the job, if rounding is the
> issue. But then, with powers of 2 indeed being represented exactly (I would
> expect even on Macs), maybe rounding is not the issue? I have no possibility
> to check this, since I do not have access to a Mac with R installed. On my
> windows machine, 
> all(log2(x)==floor(log2(x))) 
> with x as defined above yields TRUE.

Christophe Dutang tested this on Mac with the result
  >  x <- 2^(0:100 + 0)
  >  all(x == floor(x))
  [1] TRUE
  >  all(log2(x) == floor(log2(x)))
  [1] TRUE
  > x
    [1] 1.000000e+00 2.000000e+00 4.000000e+00 8.000000e+00 1.600000e+01
    [6] 3.200000e+01 6.400000e+01 1.280000e+02 2.560000e+02 5.120000e+02
   [11] 1.024000e+03 2.048000e+03 4.096000e+03 8.192000e+03 1.638400e+04
   [16] 3.276800e+04 6.553600e+04 1.310720e+05 2.621440e+05 5.242880e+05
   [21] 1.048576e+06 2.097152e+06 4.194304e+06 8.388608e+06 1.677722e+07
   [26] 3.355443e+07 6.710886e+07 1.342177e+08 2.684355e+08 5.368709e+08
   [31] 1.073742e+09 2.147484e+09 4.294967e+09 8.589935e+09 1.717987e+10
   ...

Without an analysis of the error directly on Mac, it is hard to guess, what
is the problem. What could also be tested is, whether the input nruns is an
integer or not. Either strictly, 
  if (nruns != floor(nruns)) stop("nruns not an integer")
or with some tolerance
  nruns0 <- nruns
  nruns <- round(nruns)
  if (!isTRUE(all.equal(nruns, nruns0))) stop("nruns not an integer")

Petr.



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