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,]  56.1 505.1 762.1
## [2,] 667.1 592.1 906.1
## [3,] 326.1 570.1  91.1
## [4,] 442.1 113.1 351.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 246.1  39.1 402.1
## [2,] 207.1 324.1 918.1
## [3,] 399.1 151.1 216.1
## [4,] 512.1 785.1  44.1
bc.d(x, y, "-")
## , , 1
## 
##       [,1]  [,2]  [,3]
## [1,]  54.1 503.1 760.1
## [2,] 663.1 588.1 902.1
## [3,] 320.1 564.1  85.1
## [4,] 434.1 105.1 343.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 244.1  37.1 400.1
## [2,] 203.1 320.1 914.1
## [3,] 393.1 145.1 210.1
## [4,] 504.1 777.1  36.1
bc.d(x, y, "*")
## , , 1
## 
##        [,1]   [,2]   [,3]
## [1,]   55.1  504.1  761.1
## [2,] 1330.2 1180.2 1808.2
## [3,]  969.3 1701.3  264.3
## [4,] 1752.4  436.4 1388.4
## 
## , , 2
## 
##        [,1]   [,2]   [,3]
## [1,]  245.1   38.1  401.1
## [2,]  410.2  644.2 1832.2
## [3,] 1188.3  444.3  639.3
## [4,] 2032.4 3124.4  160.4
bc.d(x, y, "/")
## , , 1
## 
##         [,1]     [,2]      [,3]
## [1,]  55.100 504.1000 761.10000
## [2,] 332.550 295.0500 452.05000
## [3,] 107.700 189.0333  29.36667
## [4,] 109.525  27.2750  86.77500
## 
## , , 2
## 
##          [,1]      [,2]      [,3]
## [1,] 245.1000  38.10000 401.10000
## [2,] 102.5500 161.05000 458.05000
## [3,] 132.0333  49.36667  71.03333
## [4,] 127.0250 195.27500  10.02500
bc.d(x, y, "^")
## , , 1
## 
##              [,1]        [,2]         [,3]
## [1,] 5.510000e+01       504.1 7.611000e+02
## [2,] 4.423580e+05    348218.0 8.173968e+05
## [3,] 3.372958e+07 182380726.7 6.837978e+05
## [4,] 3.683774e+10 141676885.9 1.451505e+10
## 
## , , 2
## 
##              [,1]         [,2]      [,3]
## [1,] 2.451000e+02 3.810000e+01     401.1
## [2,] 4.206601e+04 1.037484e+05  839239.2
## [3,] 6.214619e+07 3.248368e+06 9677214.1
## [4,] 6.664948e+10 3.722430e+11 2585696.2

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