[R] surprising difference in log()

Moshe Olshansky m_olshansky at yahoo.com
Wed Jun 27 02:28:34 CEST 2007


This is not surprizing at all!
The exact result is log(8,2) = 3, but the numerical
procedure which calculates the logarithm may produce a
result which is a few ULPs different from the exact
one, i.e. you can get that log(8,2) = 2.99999999999999
and then floor(2.99999999999999) = 2.

--- Fausto Galli <fausto.galli at lu.unisi.ch> wrote:

> 
> Hello everybody
> 
> My collegue and I noticed a strange behaviour of R
> on different  
> platforms. It's a simple computation, but results
> are rather different.
> 
> On Windows XP:
> 
>  > floor(log(8,2))
> [1] 3
> 
> which is what one should expect.
> Here's instead the result with Mac OS X (same
> version, 2.5.0  
> (2007-04-23))
> 
>  > floor(log(8,2))
> [1] 2
> 
> Is it a "bug" in R or in the operating system?
> Anyway, it's quite a surprising one.
> 
> 
> 
> 
> 
> _____________________________________
> Fausto Galli
> Institute of Finance
> University of Lugano
> Via G. Buffi 13
> CH-6904 Lugano, Switzerland.
> +41 (0)58 666 4497
> http://www.people.lu.unisi.ch/gallif
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>



More information about the R-help mailing list