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,] 24 833 569
#> [2,] 11 612 793
#> [3,] 23 852 870
#> [4,] 751 239 181
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 701 952 969
#> [2,] 551 152 723
#> [3,] 269 805 395
#> [4,] 478 44 963
bc.i(x, y, "-")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 22 831 567
#> [2,] 7 608 789
#> [3,] 17 846 864
#> [4,] 743 231 173
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 699 950 967
#> [2,] 547 148 719
#> [3,] 263 799 389
#> [4,] 470 36 955
bc.i(x, y, "*")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 23 832 568
#> [2,] 18 1220 1582
#> [3,] 60 2547 2601
#> [4,] 2988 940 708
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 700 951 968
#> [2,] 1098 300 1442
#> [3,] 798 2406 1176
#> [4,] 1896 160 3836
bc.i(x, y, "gcd") # greatest common divisor
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 1 2 1
#> [3,] 1 3 3
#> [4,] 1 1 1
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 1 2 1
#> [3,] 1 1 1
#> [4,] 2 4 1
bc.i(x, y, "^")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 2.30000e+01 832 568
#> [2,] 8.10000e+01 372100 625681
#> [3,] 8.00000e+03 611960049 651714363
#> [4,] 3.11374e+11 3049800625 981506241
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 700 951 968
#> [2,] 301401 22500 519841
#> [3,] 18821096 515849608 60236288
#> [4,] 50479304976 2560000 845813141761
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() function 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.