Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Arbitrary-precision arithmetic for R

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

davidchall/bignum

Lifecycle: experimentalCRAN statusR build statusCoverage status

bignum provides numeric vectors with greater precision than R atomicnumeric vectors.

  • biginteger() stores any integer (i.e. arbitrary precision).
  • bigfloat() stores 50 decimal digits of precision.

They prioritize precision over performance, so computations are slowerthan those usinginteger() ordouble().

Under the hood, bignum uses thecpp_intandcpp_bin_float_50data types from the Boost.Multiprecision C++ library.

Installation

You can install the released version of bignum fromCRAN 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 seethe 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 workingwith very large integers. As an example, let’s calculate the factorialof 23. In base R, we’d calculate:

factorial(23)#> [1] 25852016738884978212864

The factorial of 23 includes a factor of 10, and so the final digitmust be zero. Usingbiginteger() yields the correct result:

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

High-precision floating-point vector

bigfloat() vectors support much higher precision thandouble()vectors:

1/3#> [1] 0.33333333333333331483bigfloat(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 aContributor CodeofConduct.By contributing to this project, you agree to abide by its terms.

About

Arbitrary-precision arithmetic for R

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Code of conduct

Contributing

Stars

Watchers

Forks

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp