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,] 854 631 919
#> [2,] 663 805 72
#> [3,] 926 927 1003
#> [4,] 851 885 416
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 612 221 174
#> [2,] 910 18 561
#> [3,] 414 63 356
#> [4,] 395 765 652
bc.i(x, y, "-")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 852 629 917
#> [2,] 659 801 68
#> [3,] 920 921 997
#> [4,] 843 877 408
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 610 219 172
#> [2,] 906 14 557
#> [3,] 408 57 350
#> [4,] 387 757 644
bc.i(x, y, "*")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 853 630 918
#> [2,] 1322 1606 140
#> [3,] 2769 2772 3000
#> [4,] 3388 3524 1648
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 611 220 173
#> [2,] 1816 32 1118
#> [3,] 1233 180 1059
#> [4,] 1564 3044 2592
bc.i(x, y, "gcd") # greatest common divisor
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 1 1 2
#> [3,] 1 3 1
#> [4,] 1 1 4
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 2 2 1
#> [3,] 3 3 1
#> [4,] 1 1 4
bc.i(x, y, "^")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 853 630 918
#> [2,] 436921 644809 4900
#> [3,] 786330467 788889024 1000000000
#> [4,] 514675673281 602425897921 28813025536
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 611 220 173
#> [2,] 824464 256 312481
#> [3,] 69426531 216000 43986977
#> [4,] 23372600161 335381132641 176319369216
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.