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,] 679 183 473
#> [2,] 45 808 526
#> [3,] 956 189 313
#> [4,] 666 779 112
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 385 284 108
#> [2,] 763 112 675
#> [3,] 696 88 542
#> [4,] 647 96 7
bc.i(x, y, "-")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 677 181 471
#> [2,] 41 804 522
#> [3,] 950 183 307
#> [4,] 658 771 104
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 383 282 106
#> [2,] 759 108 671
#> [3,] 690 82 536
#> [4,] 639 88 -1
bc.i(x, y, "*")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 678 182 472
#> [2,] 86 1612 1048
#> [3,] 2859 558 930
#> [4,] 2648 3100 432
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 384 283 107
#> [2,] 1522 220 1346
#> [3,] 2079 255 1617
#> [4,] 2572 368 12
bc.i(x, y, "gcd") # greatest common divisor
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 1 2 2
#> [3,] 1 3 1
#> [4,] 2 1 4
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 1 2 1
#> [3,] 3 1 1
#> [4,] 1 4 1
bc.i(x, y, "^")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 678 182 472
#> [2,] 1849 649636 274576
#> [3,] 865523177 6434856 29791000
#> [4,] 192057803536 360750390625 136048896
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 384 283 107
#> [2,] 579121 12100 452929
#> [3,] 332812557 614125 156590819
#> [4,] 170940075601 71639296 81
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 TRUE
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 FALSE
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 TRUE
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 FALSEbc.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.