On Wed, Feb 11, 2009 at 6:20 AM, Robin Hankin <rk...@cam.ac.uk> wrote:
>> library(Brobdingnag)
>> exp(1000)/(exp(1007)+5)
> [1] NaN
>
>> as.numeric(exp(as.brob(1000))/(exp(as.brob(1007))+5))
> [1] 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
[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, but in general I don't think it's wise to abdicate
responsibility to one's tools. Though numerical analysis is a field in
itself, I think it's worthwhile to learn the basics.

           -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.

Reply via email to