[R] How to handle large numbers?
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Wed Feb 11 22:38:58 CET 2009
Stavros Macrakis wrote:
> On Wed, Feb 11, 2009 at 6:20 AM, Robin Hankin <rksh1 at cam.ac.uk> wrote:
>>  NaN
>>  0.000911882
> Though brob is certainly useful in many cases, it can't substitute for
> thinking about numeric issues (roundoff, cancellation, overflow,
> underflow) in general.
> For example:
>> x<-40; log(exp(x)+1)-x
>  0
>> x<-as.brob(40); log(exp(x)+1)-x
>  -exp(-Inf)
> The correct answer is about 4e-18. Perhaps Ryacas or some other tool
> gets this right,
bc gets it arbitrarily right:
bc -l <<END
as does, e.g., mathematica (which appears to be using the *foss* gmp
> but in general I don't think it's wise to abdicate
> responsibility to one's tools.
interestingly, perl's bignum gets it slowly and actually wrong (or do i
perl -Mbignum=p,-50 -le 'print (log(exp(40)+1)-40'
More information about the R-help