[R] question about precision, floor, and powers of two.

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Nov 4 15:12:49 CET 2005


Dr Carbon wrote:

> At the risk of being beaten about the face and body, can somebody explain
> why the middle example: log2(2^3); floor(log2(2^3)) is different than
> examples 1 and 3?


Because

 > log2(2^3) - 3
[1] -4.440892e-16

see the R FAQ "Why doesn't R think these numbers are equal?".

Uwe Ligges

> 
>>log2(2^2); floor(log2(2^2))
> 
> [1] 2
> [1] 2
> 
>>log2(2^3); floor(log2(2^3))
> 
> [1] 3
> [1] 2
> 
>>log2(2^4); floor(log2(2^4))
> 
> [1] 4
> [1] 4
> 
> 
> DrC
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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




More information about the R-help mailing list