bc.d

Broadcasted Decimal Numeric Operations

Description

The bc.d() function 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,] 497.1 989.1 310.1
## [2,] 277.1 268.1 106.1
## [3,] 714.1 877.1  29.1
## [4,]  38.1 992.1 552.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 354.1 616.1 243.1
## [2,] 880.1 149.1 165.1
## [3,] 221.1 946.1 582.1
## [4,] 306.1 599.1 307.1
bc.d(x, y, "-")
## , , 1
## 
##       [,1]  [,2]  [,3]
## [1,] 495.1 987.1 308.1
## [2,] 273.1 264.1 102.1
## [3,] 708.1 871.1  23.1
## [4,]  30.1 984.1 544.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 352.1 614.1 241.1
## [2,] 876.1 145.1 161.1
## [3,] 215.1 940.1 576.1
## [4,] 298.1 591.1 299.1
bc.d(x, y, "*")
## , , 1
## 
##        [,1]   [,2]   [,3]
## [1,]  496.1  988.1  309.1
## [2,]  550.2  532.2  208.2
## [3,] 2133.3 2622.3   78.3
## [4,]  136.4 3952.4 2192.4
## 
## , , 2
## 
##        [,1]   [,2]   [,3]
## [1,]  353.1  615.1  242.1
## [2,] 1756.2  294.2  326.2
## [3,]  654.3 2829.3 1737.3
## [4,] 1208.4 2380.4 1212.4
bc.d(x, y, "/")
## , , 1
## 
##          [,1]     [,2]    [,3]
## [1,] 496.1000 988.1000 309.100
## [2,] 137.5500 133.0500  52.050
## [3,] 237.0333 291.3667   8.700
## [4,]   8.5250 247.0250 137.025
## 
## , , 2
## 
##         [,1]     [,2]     [,3]
## [1,] 353.100 615.1000 242.1000
## [2,] 439.050  73.5500  81.5500
## [3,]  72.700 314.3667 193.0333
## [4,]  75.525 148.7750  75.7750
bc.d(x, y, "^")
## , , 1
## 
##              [,1]         [,2]         [,3]
## [1,]       496.10 9.881000e+02 3.091000e+02
## [2,]     75680.01 7.080921e+04 1.083681e+04
## [3,] 359577108.63 6.678568e+08 1.777958e+04
## [4,]   1352127.10 9.532429e+11 9.024834e+10
## 
## , , 2
## 
##              [,1]         [,2]         [,3]
## [1,]        353.1 6.151000e+02 2.421000e+02
## [2,]     771059.6 2.163841e+04 2.660161e+04
## [3,]   10374495.7 8.388286e+08 1.942051e+08
## [4,] 8329192532.6 1.254180e+11 8.440025e+09

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