long/bigint/decimal equivalent datatype in R

I understood your question a little differently vs the two who posted before i did.

If R’s largest default value is not big enough for you, you have a few choices (disclaimer: I have used each of the libraries i mention below, but not through the R bindings, instead through other language bindings or the native library)

The Brobdingnag package: uses natural logs to store the values; (like Rmpfr, implemented using R’s new class structure). I’m always impressed by anyone whose work requires numbers of this scale.

library(Brobdingnag)

googol <- as.brob(1e100)   

The gmp package: R bindings to the venerable GMP (GNU Multi-precision library). This must go back 20 years because i used it in University. This Library’s motto is “Arithmetic Without Limits,” which is a credible claim–integers, rationals, floats, whatever, right up to the limits of the RAM on your box.

library(gmp)

x = as.bigq(8000, 21)

The Rmpfr package: R bindings which interface to both gmp (above) and MPFR, (MPFR is in turn a contemporary implementation of gmp. I have used the Python bindings (‘bigfloat’) and can recommend it highly. This might be your best option of the three, given its scope, given that it appears to be the most actively maintained, and and finally given what appears to be the most thorough documentation.

Note: to use either of the last two, you’ll need to install the native libraries, GMP and MPFR.

Leave a Comment