Introducing the `tapir` package: Text-based Arbitrary Precision Integers in R

Rationale

This is a toy library written in order bootstrap another idea, without having to carry a dependency on a real arbitrary precision library like gmp or Rmpfr.

The algorithms are straight-forward implementations of naive algorithms and are orders of magnitute slower than gmp even for small/moderate sized integers.

Installation

devtools::install_github('coolbutuseless/tapir')

Supported data types

The only supported datatype is an unsigned integer represented in a character string. e.g.

  • “1234”
  • “9237409238740928374029374293”

Supported operations

  • %add% - Addition
  • %sub% - Subtration
  • %sub% - Multiplication
  • %div% - Division
  • %mod% - Modulo operator
  • Logical
    • %gt% - greater than
    • %gte% - greater than or equal to
    • %eq% - equal to
    • %lt% - less than
    • %lte% - less than or equal to

Helper functions

  • rbigint(digits)
    • Create a big integer with the given number of digits

Examples

a <- rbigint(30)
b <- rbigint(20)
a
[1] "481566380993563946785704271523"
b
[1] "36545007522668563750"
a %mul% b
[1] "17598847016074070094422556163003416290166435091250"
a %div% b
[1] "13177350714"
a %mod% b
[1] "21591977069287254023"
a %add% b
[1] "481566381030108954308372835273"
a %sub% b
[1] "481566380957018939263035707773"