[R] big numbers

Roger D. Peng rdpeng at gmail.com
Tue Aug 22 15:58:37 CEST 2006


The 'gmp' package may be of use here, but I'm not sure.

-roger

Robin Hankin wrote:
> Hi
> 
> Can I get R to handle really big numbers?    I am not interested
> in more than (say) 10 sig figs, but I would like to deal with numbers
> up to, say, 10^10000.
> 
> If
> 
> a <- 10^10000
> b <- pi* a
> 
> I would like  "a+b" to return 3.1415926e10000.
> 
> 
> Toy example, illustrating why I can't deal with log(a) and log(b),   
> follows.
> 
> 
> 
> f <- function(a,n=100){
>    out <- rep(0,n)
>    out[1] <- a
>    for(i in 2:n){
>      out[i] <- sum(exp(out[1:i])) + rexp(1)
>    }
>    return(log(out))
> }
> 
> 
> then f(1,10)  has infinities in it, even though the values should be  
> moderate size.
> 
> What are my options here?
> 
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
>   tel  023-8059-7743
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
> 

-- 
Roger D. Peng  |  http://www.biostat.jhsph.edu/~rpeng/



More information about the R-help mailing list