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,] 347.1 336.1 651.1
#> [2,] 511.1 736.1 902.1
#> [3,] 683.1 958.1 304.1
#> [4,] 967.1 536.1 749.1
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 501.1 367.1 762.1
#> [2,] 388.1 247.1 782.1
#> [3,] 310.1  77.1 405.1
#> [4,] 400.1 961.1 854.1
bc.d(x, y, "-")
#> , , 1
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 345.1 334.1 649.1
#> [2,] 507.1 732.1 898.1
#> [3,] 677.1 952.1 298.1
#> [4,] 959.1 528.1 741.1
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 499.1 365.1 760.1
#> [2,] 384.1 243.1 778.1
#> [3,] 304.1  71.1 399.1
#> [4,] 392.1 953.1 846.1
bc.d(x, y, "*")
#> , , 1
#> 
#>        [,1]   [,2]   [,3]
#> [1,]  346.1  335.1  650.1
#> [2,] 1018.2 1468.2 1800.2
#> [3,] 2040.3 2865.3  903.3
#> [4,] 3852.4 2128.4 2980.4
#> 
#> , , 2
#> 
#>        [,1]   [,2]   [,3]
#> [1,]  500.1  366.1  761.1
#> [2,]  772.2  490.2 1560.2
#> [3,]  921.3  222.3 1206.3
#> [4,] 1584.4 3828.4 3400.4
bc.d(x, y, "/")
#> , , 1
#> 
#>         [,1]     [,2]     [,3]
#> [1,] 346.100 335.1000 650.1000
#> [2,] 254.550 367.0500 450.0500
#> [3,] 226.700 318.3667 100.3667
#> [4,] 240.775 133.0250 186.2750
#> 
#> , , 2
#> 
#>          [,1]    [,2]     [,3]
#> [1,] 500.1000 366.100 761.1000
#> [2,] 193.0500 122.550 390.0500
#> [3,] 102.3667  24.700 134.0333
#> [4,]  99.0250 239.275 212.5250
bc.d(x, y, "^")
#> , , 1
#> 
#>              [,1]         [,2]         [,3]
#> [1,] 3.461000e+02 3.351000e+02 6.501000e+02
#> [2,] 2.591828e+05 5.389028e+05 8.101800e+05
#> [3,] 3.145707e+08 8.712575e+08 2.729809e+07
#> [4,] 8.603705e+11 8.016283e+10 3.082182e+11
#> 
#> , , 2
#> 
#>              [,1]         [,2]         [,3]
#> [1,] 5.001000e+02 3.661000e+02 7.611000e+02
#> [2,] 1.490732e+05 6.007401e+04 6.085560e+05
#> [3,] 2.896273e+07 4.068690e+05 6.501330e+07
#> [4,] 2.461611e+10 8.391300e+11 5.222519e+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