bc.d

Broadcasted Decimal Numeric Operations

Description

The bc.d() method performs broadcasted decimal numeric operations on 2 numeric or logical arrays.


Usage

bc.d(x, y, op, ...)

## S4 method for signature 'ANY'
bc.d(x, y, op, tol = sqrt(.Machine$double.eps))

Arguments

x, y conformable vectors/arrays of type logical or numeric.
op a single string, giving the operator.
Supported arithmetic operators: +, -, *, /, ^, pmin, pmax.
Supported relational operators: ==, !=, <, >, <=, >=, d==, d!=, d<, d>, d<=, d>=.
further arguments passed to or from methods.

tol a single number between 0 and 0.1, giving the machine tolerance to use for the relational operators.
Only relevant for the following operators:
d==, d!=, d<, d>, d<=, d>=
See the %d==%, %d!=%, %d<%, %d>%, %d<=%, %d>=% operators from the ‘tinycodet’ package for details.

Value

For arithmetic operators:
A numeric array as a result of the broadcasted decimal arithmetic operation.

For relational operators:
A logical array as a result of the broadcasted decimal relational comparison.

See Also

broadcast_operators

Examples

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.d(x, y, "+")
#> , , 1
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 508.1 296.1 551.1
#> [2,] 406.1 992.1 737.1
#> [3,] 776.1 852.1  64.1
#> [4,] 837.1  62.1 321.1
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 107.1 781.1 874.1
#> [2,] 929.1 500.1 616.1
#> [3,] 718.1 376.1 985.1
#> [4,] 139.1 970.1 729.1
bc.d(x, y, "-")
#> , , 1
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 506.1 294.1 549.1
#> [2,] 402.1 988.1 733.1
#> [3,] 770.1 846.1  58.1
#> [4,] 829.1  54.1 313.1
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 105.1 779.1 872.1
#> [2,] 925.1 496.1 612.1
#> [3,] 712.1 370.1 979.1
#> [4,] 131.1 962.1 721.1
bc.d(x, y, "*")
#> , , 1
#> 
#>        [,1]   [,2]   [,3]
#> [1,]  507.1  295.1  550.1
#> [2,]  808.2 1980.2 1470.2
#> [3,] 2319.3 2547.3  183.3
#> [4,] 3332.4  232.4 1268.4
#> 
#> , , 2
#> 
#>        [,1]   [,2]   [,3]
#> [1,]  106.1  780.1  873.1
#> [2,] 1854.2  996.2 1228.2
#> [3,] 2145.3 1119.3 2946.3
#> [4,]  540.4 3864.4 2900.4
bc.d(x, y, "/")
#> , , 1
#> 
#>         [,1]     [,2]      [,3]
#> [1,] 507.100 295.1000 550.10000
#> [2,] 202.050 495.0500 367.55000
#> [3,] 257.700 283.0333  20.36667
#> [4,] 208.275  14.5250  79.27500
#> 
#> , , 2
#> 
#>          [,1]     [,2]     [,3]
#> [1,] 106.1000 780.1000 873.1000
#> [2,] 463.5500 249.0500 307.0500
#> [3,] 238.3667 124.3667 327.3667
#> [4,]  33.7750 241.5250 181.2750
bc.d(x, y, "^")
#> , , 1
#> 
#>              [,1]        [,2]         [,3]
#> [1,] 5.071000e+02       295.1 5.501000e+02
#> [2,] 1.632968e+05    980298.0 5.403720e+05
#> [3,] 4.620692e+08 612176314.8 2.280991e+05
#> [4,] 4.817132e+11  11394742.9 1.011079e+10
#> 
#> , , 2
#> 
#>             [,1]         [,2]         [,3]
#> [1,]       106.1 7.801000e+02 8.731000e+02
#> [2,]    859514.4 2.481036e+05 3.771188e+05
#> [3,] 365679264.0 5.193687e+07 9.472555e+08
#> [4,] 333135869.0 8.711407e+11 2.764341e+11

bc.d(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.d(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.d(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.d(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.d(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.d(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