[Rd] [R] big numbers

Robin Hankin r.hankin at noc.soton.ac.uk
Tue Aug 22 16:56:59 CEST 2006


[[shifting to R-devel]]

Hi Roger

yes, I'm aware of gmp, but although it does handle big
numbers, it uses exact integer arithmetic, which would be
too slow for me.

My example of 10^10000 *(1+pi) ~= 4.14259*10^10000
would require gmp to process 10000 digits, which would be
time consuming.

My best idea so far is to define a new class of objects
that have a signed floating point mantissa M in the range 1-10 and a
signed integer exponent E.   Then (E,M) would be E*10^M.

So the ordered pair (M,E) would be able to represent positive numbers  
from
something like 10^(-10^9) to something like 10^(10^9), and negative
numbers of the same magnitude.

Perhaps it would be possible to write a little C program that would
implement this that would be as fast as regular floating-point
arithmetic to within an order of magnitude?

Anyone got any advice here?




On 22 Aug 2006, at 14:58, Roger D. Peng wrote:

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

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743



More information about the R-devel mailing list