# [R] How to handle large numbers?

Gabor Grothendieck ggrothendieck at gmail.com
Wed Feb 11 15:09:54 CET 2009

```Try Ryacas.  N means numerically evaluate in
yacas (as we don't want it evaluated on
the R side where we already know we get NaN).

> library(Ryacas)
> Eval(yacas("N(Exp(1000)/(Exp(1007)+5))")
 0.000911882

You can explore it somewhat in R via:

curve(exp(x)/(exp(x+7)+5), 1, 500)

On Wed, Feb 11, 2009 at 5:40 AM, Feng Li <840116 at gmail.com> wrote:
> Dear R,
>
> I have two questions:
>
> 1, Why both R and Matlab give 0*Inf==NaN? To my knowledge, it should be zero
> mathematically. Am I right?
>
> 2, I need to calculate e.g. exp(a)/(exp(b)+c), where both a and b are very
> large numbers (>>1000, e.g a=1000, b=1007, and c=5). R gives me NaN when I
> use the following command:
>
>> exp(1000)/(exp(1007)+5)
>  NaN
>
> I am pretty sure this should be close to zero. My question is whether there
> is a general way to solve this kind of question or should I do some settings
> before computing?
>
>
>
>
> Feng
>
>
>
> --
> Feng Li
> Department of Statistics
> Stockholm University
> 106 91 Stockholm, Sweden
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help