| bc.i | R Documentation |
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.
bc.i(x, y, op, ...)
## S4 method for signature 'ANY'
bc.i(x, y, op)
round2int53(x)
x, y |
conformable vectors/arrays of type logical or numeric. |
op |
a single string, giving the operator. |
... |
further arguments passed to or from methods. |
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().
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().
On the integer division and remainder (modulo) computations, %% and %/%:
https://en.wikipedia.org/wiki/Modulo
broadcast_operators
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.