Supported operations

This document lists the numeric operations supported by biginteger() and bigfloat() vectors. We recommend reading the base R documentation to understand the function of each operation.

library(bignum)

Check for special values

biginteger() and bigfloat() support missing values (via NA_biginteger_ and NA_bigfloat_ respectively).

bigfloat() supports positive and negative infinity and ‘Not a Number’ values. Usually these are the result of a calculation, but they can also be created manually:

bigfloat(c(1, -1, 0)) / 0
#> <bigfloat[3]>
#> [1] Inf  -Inf NaN
bigfloat(c(Inf, -Inf, NaN))
#> <bigfloat[3]>
#> [1] Inf  -Inf NaN

You can check for these special values using:

is.na(x)
is.finite(x)
is.infinite(x)
is.nan(x)

Comparison operations

biginteger() and bigfloat() vectors support the standard comparison operations. The base R documentation for these can be found via help("Comparison").

x < y
x > y
x <= y
x >= y
x == y
x != y

These operations always return a logical vector.

Arithmetic operations

biginteger() and bigfloat() vectors support the standard arithmetic operations. The base R documentation for these can be found via help("Arithmetic").

+ x
- x
x + y
x - y
x * y
x / y
x ^ y
x %% y
x %/% y

These arithmetic operations are type-stable, which means the output type depends only on the input types (not the input values). A biginteger vector is returned when the result must be an integer (e.g., addition of two integers). Otherwise a bigfloat vector is returned.

The following table summarizes the return type for each combination, where “integer-like” refers to integer and biginteger vectors and “float-like” refers to double and bigfloat vectors.

Input 1 Operator Input 2 Result
Integer-like +, -, *, ^, %% Integer-like -> biginteger
Integer-like +, -, *, ^, %% Float-like -> bigfloat
Float-like +, -, *, ^, %% Integer-like -> bigfloat
Float-like +, -, *, ^, %% Float-like -> bigfloat
Any / Any -> bigfloat
Any %/% Any -> biginteger

Mathematical operations

biginteger() and bigfloat() vectors support the following mathematical operations:

# summary
sum(..., na.rm = FALSE)
prod(..., na.rm = FALSE)
max(x, ..., na.rm = FALSE)
min(x, ..., na.rm = FALSE)
range(x, ..., na.rm = FALSE)
mean(x, ..., na.rm = FALSE)

# cumulative
cumsum(x)
cumprod(x)
cummax(x)
cummin(x)

# rounding
floor(x)
ceiling(x)
trunc(x)

# miscellaneous
abs(x)
sign(x)
sqrt(x)

# logarithms and exponentials
log(x, base = exp(1))
log10(x)
log2(x)
log1p(x)
exp(x)
expm1(x)

# trigonometric
cos(x)
sin(x)
tan(x)
acos(x)
asin(x)
atan(x)
cospi(x)
sinpi(x)
tanpi(x)

# hyperbolic
cosh(x)
sinh(x)
tanh(x)
acosh(x)
asinh(x)
atanh(x)

# special functions
gamma(x)
lgamma(x)
digamma(x)
trigamma(x)
factorial(x)
lfactorial(x)