biginteger and bigfloat vectors support the standard arithmetic operations. The base R documentation can be found at Arithmetic.
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 |
Other bignum operations:
bignum-compare
,
bignum-math
,
bignum-special
x <- biginteger(5)
y <- bigfloat(2)
+x
#> <biginteger[1]>
#> [1] 5
-x
#> <biginteger[1]>
#> [1] -5
x + y
#> <bigfloat[1]>
#> [1] 7
x - y
#> <bigfloat[1]>
#> [1] 3
x * y
#> <bigfloat[1]>
#> [1] 10
x / y
#> <bigfloat[1]>
#> [1] 2.5
x^y
#> <bigfloat[1]>
#> [1] 25
x %% y
#> <bigfloat[1]>
#> [1] 1
x %/% y
#> <biginteger[1]>
#> [1] 2