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 logical or numeric arrays.
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.
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,] 704.1 131.1 523.1
## [2,] 984.1  65.1 578.1
## [3,] 461.1 740.1 542.1
## [4,] 171.1 425.1 356.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 154.1  71.1 657.1
## [2,] 187.1 994.1 130.1
## [3,] 463.1 145.1 676.1
## [4,] 604.1 335.1 667.1
bc.d(x, y, "-")
## , , 1
## 
##       [,1]  [,2]  [,3]
## [1,] 702.1 129.1 521.1
## [2,] 980.1  61.1 574.1
## [3,] 455.1 734.1 536.1
## [4,] 163.1 417.1 348.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 152.1  69.1 655.1
## [2,] 183.1 990.1 126.1
## [3,] 457.1 139.1 670.1
## [4,] 596.1 327.1 659.1
bc.d(x, y, "*")
## , , 1
## 
##        [,1]   [,2]   [,3]
## [1,]  703.1  130.1  522.1
## [2,] 1964.2  126.2 1152.2
## [3,] 1374.3 2211.3 1617.3
## [4,]  668.4 1684.4 1408.4
## 
## , , 2
## 
##        [,1]   [,2]   [,3]
## [1,]  153.1   70.1  656.1
## [2,]  370.2 1984.2  256.2
## [3,] 1380.3  426.3 2019.3
## [4,] 2400.4 1324.4 2652.4
bc.d(x, y, "/")
## , , 1
## 
##         [,1]    [,2]    [,3]
## [1,] 703.100 130.100 522.100
## [2,] 491.050  31.550 288.050
## [3,] 152.700 245.700 179.700
## [4,]  41.775 105.275  88.025
## 
## , , 2
## 
##          [,1]      [,2]     [,3]
## [1,] 153.1000  70.10000 656.1000
## [2,]  92.5500 496.05000  64.0500
## [3,] 153.3667  47.36667 224.3667
## [4,] 150.0250  82.77500 165.7750
bc.d(x, y, "^")
## , , 1
## 
##             [,1]         [,2]         [,3]
## [1,]       703.1 1.301000e+02 5.221000e+02
## [2,]    964520.4 3.981610e+03 3.318912e+05
## [3,]  96134854.9 4.004785e+08 1.566780e+08
## [4,] 779660980.2 3.144423e+10 1.536965e+10
## 
## , , 2
## 
##              [,1]         [,2]         [,3]
## [1,] 1.531000e+02 7.010000e+01 6.561000e+02
## [2,] 3.426201e+04 9.842624e+05 1.640961e+04
## [3,] 9.739949e+07 2.869341e+06 3.049571e+08
## [4,] 1.296864e+11 1.201813e+10 1.933375e+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