Re: [R] surprising difference in log()

2007-06-26 Thread Moshe Olshansky
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.99
and then floor(2.99) = 2.

--- Fausto Galli <[EMAIL PROTECTED]> 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@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.
>

__
R-help@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.


Re: [R] surprising difference in log()

2007-06-26 Thread Prof Brian Ripley
On Tue, 26 Jun 2007, Fausto Galli 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.

It is a minor problem in the OS.  Given that log(8, 2) is a floating point 
calculation, it is unreasonable to expect it in general to be exact.  For 
those OSes that have log2, log2(8) is used and one might reasonably expect 
that to be exactly 3.  So either MacOS X is lacking log2 or its log2 is 
not exact.

Taking 'floor' of a floating-point computation without a fuzz is unwise.

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
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, UKFax:  +44 1865 272595

__
R-help@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.


Re: [R] surprising difference in log()

2007-06-26 Thread Mike Lawrence
Sorry, my mistake. I should really leave looking at the help list  
until AFTER my morning coffee :P

On 26-Jun-07, at 11:31 AM, Duncan Murdoch wrote:

> On 6/26/2007 10:20 AM, Mike Lawrence wrote:
>> According to the description of floor(), the latter result is the
>> correct one:
>>
>> 'floor takes a single numeric argument x and returns a numeric vector
>> containing the largest integers *not greater than* the corresponding
>> elements of x.' (emphasis added)
>>
>> floor(3) == 2
>>> True
>
> 3 is not greater than 3, but it is greater than 2, so the result you
> quote above is wrong.  You should see
>
>> floor(3)
>   [1] 3
>
>> floor(3) == 2
> [1] FALSE
>
> Do you really see the result you posted?
>
> Duncan Murdoch
>
> __
> R-help@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.

--
Mike Lawrence
Graduate Student, Department of Psychology, Dalhousie University

Website: http://memetic.ca

Public calendar: http://icalx.com/public/informavore/Public

"The road to wisdom? Well, it's plain and simple to express:
Err and err and err again, but less and less and less."
- Piet Hein

__
R-help@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.


Re: [R] surprising difference in log()

2007-06-26 Thread Duncan Murdoch
On 6/26/2007 10:20 AM, Mike Lawrence wrote:
> According to the description of floor(), the latter result is the  
> correct one:
> 
> 'floor takes a single numeric argument x and returns a numeric vector  
> containing the largest integers *not greater than* the corresponding  
> elements of x.' (emphasis added)
> 
> floor(3) == 2
>  >True

3 is not greater than 3, but it is greater than 2, so the result you 
quote above is wrong.  You should see

> floor(3)
  [1] 3

 > floor(3) == 2
[1] FALSE

Do you really see the result you posted?

Duncan Murdoch

__
R-help@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.


Re: [R] surprising difference in log()

2007-06-26 Thread Mike Lawrence
According to the description of floor(), the latter result is the  
correct one:

'floor takes a single numeric argument x and returns a numeric vector  
containing the largest integers *not greater than* the corresponding  
elements of x.' (emphasis added)

floor(3) == 2
 >True


On 26-Jun-07, at 11:09 AM, Fausto Galli 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@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.

--
Mike Lawrence
Graduate Student, Department of Psychology, Dalhousie University

Website: http://memetic.ca

Public calendar: http://icalx.com/public/informavore/Public

"The road to wisdom? Well, it's plain and simple to express:
Err and err and err again, but less and less and less."
- Piet Hein

__
R-help@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.