Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

bignum

Big number arithmetic


Description

Basic operations for working with large integers. The bignum function converts a positive integer, string or raw vector into a bignum type. All basic Arithmetic and Comparison operators such as +, -, *, ^, %%, %/%, ==, !=, <, <=, > and >= are implemented for bignum objects. The Modular exponent (a^b %% m) can be calculated using bignum_mod_exp when b is too large for calculating a^b directly.

Usage

bignum(x, hex = FALSE)

bignum_mod_exp(a, b, m)

bignum_mod_inv(a, m)

Arguments

x

an integer, string (hex or dec) or raw vector

hex

set to TRUE to parse strings as hex rather than decimal notation

a

bignum value for (a^b %% m)

b

bignum value for (a^b %% m)

m

bignum value for (a^b %% m)

Examples

# create a bignum
x <- bignum(123L)
y <- bignum("123456789123456789")
z <- bignum("D41D8CD98F00B204E9800998ECF8427E", hex = TRUE)

# Basic arithmetic
div <- z %/% y
mod <- z %% y
z2 <- div * y + mod
stopifnot(z2 == z)
stopifnot(div < z)

openssl

Toolkit for Encryption, Signatures and Certificates Based on OpenSSL

v1.4.4
MIT + file LICENSE
Authors
Jeroen Ooms [aut, cre] (<https://orcid.org/0000-0002-4035-0289>), Oliver Keyes [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.