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,]  23.1 383.1 626.1
## [2,] 377.1 423.1 991.1
## [3,]  72.1 736.1 362.1
## [4,] 889.1 720.1 198.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 941.1 927.1  65.1
## [2,]  41.1 823.1 460.1
## [3,] 403.1 478.1 710.1
## [4,] 417.1 184.1 854.1
bc.d(x, y, "-")
## , , 1
## 
##       [,1]  [,2]  [,3]
## [1,]  21.1 381.1 624.1
## [2,] 373.1 419.1 987.1
## [3,]  66.1 730.1 356.1
## [4,] 881.1 712.1 190.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 939.1 925.1  63.1
## [2,]  37.1 819.1 456.1
## [3,] 397.1 472.1 704.1
## [4,] 409.1 176.1 846.1
bc.d(x, y, "*")
## , , 1
## 
##        [,1]   [,2]   [,3]
## [1,]   22.1  382.1  625.1
## [2,]  750.2  842.2 1978.2
## [3,]  207.3 2199.3 1077.3
## [4,] 3540.4 2864.4  776.4
## 
## , , 2
## 
##        [,1]   [,2]   [,3]
## [1,]  940.1  926.1   64.1
## [2,]   78.2 1642.2  916.2
## [3,] 1200.3 1425.3 2121.3
## [4,] 1652.4  720.4 3400.4
bc.d(x, y, "/")
## , , 1
## 
##           [,1]     [,2]    [,3]
## [1,]  22.10000 382.1000 625.100
## [2,] 187.55000 210.5500 494.550
## [3,]  23.03333 244.3667 119.700
## [4,] 221.27500 179.0250  48.525
## 
## , , 2
## 
##          [,1]     [,2]    [,3]
## [1,] 940.1000 926.1000  64.100
## [2,]  19.5500 410.5500 229.050
## [3,] 133.3667 158.3667 235.700
## [4,] 103.2750  45.0250 212.525
bc.d(x, y, "^")
## , , 1
## 
##              [,1]         [,2]         [,3]
## [1,] 2.210000e+01 3.821000e+02        625.1
## [2,] 1.407000e+05 1.773252e+05     978318.8
## [3,] 3.299394e+05 3.939940e+08   46306954.1
## [4,] 6.137187e+11 2.629630e+11 1419391308.5
## 
## , , 2
## 
##              [,1]         [,2]         [,3]
## [1,] 9.401000e+02        926.1 6.410000e+01
## [2,] 1.528810e+03     674205.2 2.098556e+05
## [3,] 6.404801e+07  107239576.8 3.535432e+08
## [4,] 2.912197e+10 1052094744.7 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