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,] 369 899 780
#> [2,] 374 836 258
#> [3,] 252 673 365
#> [4,] 603 535 256
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 190 275 330
#> [2,] 266 676 189
#> [3,] 979 343 758
#> [4,] 558 459 455
bc.i(x, y, "-")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 367 897 778
#> [2,] 370 832 254
#> [3,] 246 667 359
#> [4,] 595 527 248
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 188 273 328
#> [2,] 262 672 185
#> [3,] 973 337 752
#> [4,] 550 451 447
bc.i(x, y, "*")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 368 898 779
#> [2,] 744 1668 512
#> [3,] 747 2010 1086
#> [4,] 2396 2124 1008
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 189 274 329
#> [2,] 528 1348 374
#> [3,] 2928 1020 2265
#> [4,] 2216 1820 1804
bc.i(x, y, "gcd") # greatest common divisor
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 2 2 2
#> [3,] 3 1 1
#> [4,] 1 1 4
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 2 2 1
#> [3,] 1 1 1
#> [4,] 2 1 1
bc.i(x, y, "^")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 368 898 779
#> [2,] 138384 695556 65536
#> [3,] 15438249 300763000 47437928
#> [4,] 128738157601 79502005521 4032758016
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 189 274 329
#> [2,] 69696 454276 34969
#> [3,] 929714176 39304000 430368875
#> [4,] 94197431056 42859350625 41371966801
bc.i(x, y, "==")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#> [3,] FALSE FALSE FALSE
#> [4,] FALSE FALSE FALSE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#> [3,] FALSE FALSE FALSE
#> [4,] FALSE FALSE FALSE
bc.i(x, y, "!=")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE TRUE TRUE
#> [3,] TRUE TRUE TRUE
#> [4,] TRUE TRUE TRUE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE TRUE TRUE
#> [3,] TRUE TRUE TRUE
#> [4,] TRUE TRUE TRUE
bc.i(x, y, "<")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#> [3,] FALSE FALSE FALSE
#> [4,] FALSE FALSE FALSE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#> [3,] FALSE FALSE FALSE
#> [4,] FALSE FALSE FALSE
bc.i(x, y, ">")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE TRUE TRUE
#> [3,] TRUE TRUE TRUE
#> [4,] TRUE TRUE TRUE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE TRUE TRUE
#> [3,] TRUE TRUE TRUE
#> [4,] TRUE TRUE TRUE
bc.i(x, y, "<=")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#> [3,] FALSE FALSE FALSE
#> [4,] FALSE FALSE FALSE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE FALSE FALSE
#> [3,] FALSE FALSE FALSE
#> [4,] FALSE FALSE FALSE
bc.i(x, y, ">=")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE TRUE TRUE
#> [3,] TRUE TRUE TRUE
#> [4,] TRUE TRUE TRUE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE TRUE TRUE
#> [3,] TRUE TRUE TRUE
#> [4,] TRUE TRUE TRUEbc.i
Broadcasted Integer Numeric Operations with Extra Overflow Protection
Description
The bc.i() method performs broadcasted integer numeric operations on 2 numeric or logical arrays.
Please note that these operations will treat the input as (double typed) integers, and will efficiently truncate when necessary.
Therefore, something like bc.i(1, 1.5, β==β) returns TRUE, because trunc(1.5) equals 1.
For regular relational operators, see bc.rel.
Usage
bc.i(x, y, op, ...)
## S4 method for signature 'ANY'
bc.i(x, y, op)
Arguments
x, y
|
conformable vectors/arrays of type logical or numeric. |
op
|
a single string, giving the operator. Supported simple arithmetic operators: +, -, *, ^, pmin, pmax. Supported special division arithmetic 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. |
Value
For arithmetic operators:
A numeric array of whole numbers, as a result of the broadcasted arithmetic operation.
Base βRβ supports integers from -2^53 to 2^53, which thus range from approximately -9 quadrillion to +9 quadrillion.
Values outside of this range will be returned as -Inf or Inf, as an extra protection against integer overflow.
For relational operators:
A logical array as a result of the broadcasted integer relational comparison.