Search code examples
rvectorsequencegmp

Create a sequence from big power numbers


I'm trying to create a sequence of integers from big numbers and couldn't find a way to suceed. Is there a way to do this ?

I tried :

(2^128):(2^128+3000) which returns: [1] 3.402824e+38

So I tried to use the gmp library :

library(gmp)
as.bigz(2^128):as.bigz(2^128+3000)

and got

messages: 1: In as.bigz(2^128):as.bigz(2^128 + 3000) :   numerical
expression has 32 elements: only the first used 2: In
as.bigz(2^128):as.bigz(2^128 + 3000) :   numerical expression has 32
elements: only the first used

Solution

  • Add your sequence to your "big number":

    library(gmp)
    as.bigz(2^128) + 0:3000
    
    Big Integer ('bigz') object of length 3001:
    [1] 340282366920938463463374607431768211456 340282366920938463463374607431768211457 
    [3] 340282366920938463463374607431768211458 340282366920938463463374607431768211459
    [5] 340282366920938463463374607431768211460 340282366920938463463374607431768211461
    # ...