library("broadcast")
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, "%%")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 0 0 0
#> [2,] 1 1 0
#> [3,] 2 2 1
#> [4,] 0 3 0
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 0 0 0
#> [2,] 1 1 1
#> [3,] 1 1 2
#> [4,] 3 1 2
bc.i(x, y, "%/%")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 606 133 153
#> [2,] 192 236 500
#> [3,] 82 309 63
#> [4,] 119 232 178
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 708 214 622
#> [2,] 447 486 294
#> [3,] 234 241 98
#> [4,] 149 121 240
bc.i(x, y, "gcd") # greatest common divisor
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 1 1 2
#> [3,] 1 1 1
#> [4,] 4 1 4
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 1 1 1
#> [3,] 1 1 1
#> [4,] 1 1 2bc.i
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