On Wed, Feb 11, 2009 at 4:38 PM, Wacek Kusnierczyk <waclaw.marcin.kusnierc...@idi.ntnu.no> wrote: > Stavros Macrakis wrote: >> For example: >>> x<-40; log(exp(x)+1)-x >> [1] 0 >>> x<-as.brob(40); log(exp(x)+1)-x >> [1] -exp(-Inf) >> The correct answer is about 4e-18. Perhaps Ryacas or some other tool gets >> this right, > > bc gets it arbitrarily right:...
Yes, any arbitrary-precision systems should get it right if you specify the right number of digits to calculate. But why use expensive multiple-precision when you don't need it? The 'right' way to calculate things like log(exp(x)+1)-x and exp(x)/(exp(x+k)+a) for large values of x is to understand their asymptotic behavior, easy to do by hand or in a CAS like Maxima (and presumably yacas, though I don't have any experience with it) -- for large x, the first looks like exp(-x)-exp(-2*x)/2+...; the second looks like exp(-k)-a*exp(-(x+k)) + ... No need for arbitrary-precision arithmetic once you know this. -s ______________________________________________ R-help@r-project.org 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.