bignum provides numeric vectors with greater precision than R atomic numeric vectors.
biginteger()
stores any integer (i.e. arbitrary precision).bigfloat()
stores 50 decimal digits of precision.They prioritize precision over performance, so computations are slower than those using integer()
or double()
.
You can install the released version of bignum from CRAN with:
Or you can install the development version from GitHub:
Before starting, we’ll increase the displayed precision so we can see the benefits of bignum.
The limited precision of atomic vectors introduces errors when working with very large integers. As an example, let’s calculate the factorial of 23. In base R, we’d calculate:
The factorial of 23 includes a factor of 10, and so the final digit must be zero. Using biginteger()
yields the correct result:
bigfloat()
vectors support much higher precision than double()
vectors:
1 / 3
#> [1] 0.33333333333333331483
bigfloat(1) / 3
#> <bigfloat[1]>
#> [1] 0.33333333333333333333333333333333333333333333333333
However, you need to be careful not to limit the precision accidentally:
Please note that the bignum project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.