MyNixOS website logo
Description

Arbitrary-Precision Integer and Floating-Point Mathematics.

Classes for storing and manipulating arbitrary-precision integer vectors and high-precision floating-point vectors. These extend the range and precision of the 'integer' and 'double' data types found in R. This package utilizes the 'Boost.Multiprecision' C++ library. It is specifically designed to work well with the 'tidyverse' collection of R packages.

bignum

Lifecycle:experimental CRANstatus R buildstatus Coveragestatus

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().

Under the hood, bignum uses the cpp_int and cpp_bin_float_50 data types from the Boost.Multiprecision C++ library.

Installation

You can install the released version of bignum from CRAN with:

install.packages("bignum")

Or you can install the development version from GitHub:

# install.packages("remotes")
remotes::install_github("davidchall/bignum")

Usage

Before starting, we’ll increase the displayed precision so we can see the benefits of bignum.

options(digits = 20)
options(bignum.sigfig = 50)
options(bignum.max_dec_width = 52)

Arbitrary-precision integer vector

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:

factorial(23)
#> [1] 25852016738884978212864

The factorial of 23 includes a factor of 10, and so the final digit must be zero. Using biginteger() yields the correct result:

prod(biginteger(1:23))
#> <biginteger[1]>
#> [1] 25852016738884976640000

High-precision floating-point vector

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:

bigfloat(1 / 3)
#> <bigfloat[1]>
#> [1] 0.333333333333333

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.

Metadata

Version

0.3.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows