Skip to content
Prev 366064 / 398502 Next

Log plus one transformation in R

On 12/12/2016 12:26 PM, John Sorkin wrote:
I don't think anyone has directly answered these questions.  The problem 
isn't with log(), it's with the representation of floating point numbers 
in R.  The log of 1 + 10^(-100) is very close to 10^(-100), but since 1 
+ 1e-100 evaluates to 1 (we only keep 15 or 16 digits of precision), 
log(1 + 1e-100) will come out as zero.  On the other hand, log1p(1e-100) 
evaluates correctly to 1e-100.
R is open source, so you could, but those are likely coming from system 
libraries, so it isn't easy to see how the approximations are being done.

Duncan Murdoch