On Fri, 4 Nov 2005, Uwe Ligges wrote: > 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 >
This is a less satisfactory answer than usual, because both 2^3 and log(2^3) are integers and thus exactly representable in the R numeric type. You could reasonably expect log(8) to be exactly 2, just as sqrt(4) is exactly 2. The problem is that we compute all logarithms via the natural log, and this introduces the problem of limited precision. -thomas ______________________________________________ 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