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,] 316 660 538
#> [2,] 185 563 481
#> [3,] 513 605 36
#> [4,] 104 615 167
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 150 951 722
#> [2,] 471 564 558
#> [3,] 208 674 410
#> [4,] 482 831 94
bc.i(x, y, "-")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 314 658 536
#> [2,] 181 559 477
#> [3,] 507 599 30
#> [4,] 96 607 159
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 148 949 720
#> [2,] 467 560 554
#> [3,] 202 668 404
#> [4,] 474 823 86
bc.i(x, y, "*")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 315 659 537
#> [2,] 366 1122 958
#> [3,] 1530 1806 99
#> [4,] 400 2444 652
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 149 950 721
#> [2,] 938 1124 1112
#> [3,] 615 2013 1221
#> [4,] 1912 3308 360
bc.i(x, y, "gcd") # greatest common divisor
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 1 1 1
#> [3,] 3 1 3
#> [4,] 4 1 1
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 1 1 1
#> [2,] 1 2 2
#> [3,] 1 1 1
#> [4,] 2 1 2
bc.i(x, y, "^")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 315 659 537
#> [2,] 33489 314721 229441
#> [3,] 132651000 218167208 35937
#> [4,] 100000000 139368569041 705911761
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 149 950 721
#> [2,] 219961 315844 309136
#> [3,] 8615125 302111711 67419143
#> [4,] 52204938256 467758877041 65610000
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.