bc.i: Broadcasted Integer Operations

bc.iR Documentation

Broadcasted Integer Operations

Description

The bc.i() method performs broadcasted integer operations on 2 numeric or logical arrays.

Please note that these operations will treat the input as (53 or 32 bit) integers, and will efficiently round using round2int53() when necessary.
Therefore, something like bc.i(2, 1.5, "==") returns TRUE, because round(1.5) equals 2.

For regular relational operators, see bc.rel.


Usage

bc.i(x, y, op, ...)

## S4 method for signature 'ANY'
bc.i(x, y, op)

round2int53(x)

Arguments

x, y

conformable vectors/arrays of type logical or numeric.

op

a single string, giving the operator.
Supported integer operators: gcd, %%, %/%.
Supported relational operators: ==, !=, <, >, <=, >=.
The "gcd" operator performs the "Greatest Common Divisor" operation, using the Euclidean algorithm.

...

further arguments passed to or from methods.

Details

Base 'R' supports 53 bit integers from -1 * (2^53 - 1) to 2^53 - 1, which thus range from approximately -9 quadrillion to +9 quadrillion.

The round2int53() function rounds a vector/array of type double, such that it fits an 53bit integer.
Values above 2^53 - 1 will be returned as Inf, and values below -2^53 + 1 will be returned as -Inf.

The input for bc.i() is rounded internally during broadcasting, using round2int53().

Value

For round2int53():
The vector rounded to the nearest integer (like round()), with values outside of the 53bit integer range being returned as -Inf or Inf.
All attributes are preserved.

For integer operators:
A numeric (double or integer, depending on the situation) array of whole numbers, as a result of the broadcasted arithmetic operation.
The input for bc.i() is rounded efficiently during broadcasting, using round2int53().

For relational operators:
A logical array as a result of the broadcasted integer relational comparison.
The relational operators efficiently round the input during broadcasting using round2int53().

References

On the integer division and remainder (modulo) computations, %% and %/%:
https://en.wikipedia.org/wiki/Modulo

See Also

broadcast_operators

Examples

x.dim <- c(4:2)
x.len <- prod(x.dim)
x.data <- sample(c(NA, 1.1:1000.1), x.len, TRUE)
x <- array(x.data, x.dim)
y <- array(1:50, c(4,1,1))

bc.i(x, y, "%%")
bc.i(x, y, "%/%")
bc.i(x, y, "gcd") # greatest common divisor


broadcast documentation built on Nov. 28, 2026, 1:07 a.m.

Related to bc.i in broadcast...