[Rd] Abnormal behavior of log function (PR#9155)

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Aug 16 17:53:26 CEST 2006


You do not tell us what log(2^a, a) is on your system.
It is likely this is a case of the warning given in ?"==", but we cannot 
tell from the output shown.

R does log(x, 2) more accurately on platforms with a working C function 
log2: you can see from the configure results if yours is one of those.
(Windows is, and Linux normally is.)

On Wed, 16 Aug 2006, bayes.gene at gmail.com wrote:

> Full_Name: Biao Li
> Version: 2.3.1
> OS: Mac OS X 10.4.7 (Intel)
> Submission from: (NULL) (132.192.4.18)
> 
> 
> I installed R 2.3.1 on my MacBook Pro (Tiger 10.4.7) and found strange behavior
> of log function:
> 
> > a <- 1:20
> > log(2^a, 2) == a
>  [1]  TRUE  TRUE FALSE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE
> FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
> > a[log(2^a, 2) != a]
>  [1]   3  6  7 12 13 14
> 
> But on Linux or Windows XP there is no such a problem, and log(2^a, 2) always
> equals a.

Have you really tested all possible values?  It is not true:

> a <- 1e10
> log(2^a, 2)
[1] Inf
> a <- -1e10
> log(2^a, 2)
[1] -Inf

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list