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,] 514.1 402.1 325.1
## [2,] 108.1 663.1 563.1
## [3,] 266.1 366.1 426.1
## [4,] 562.1 839.1 271.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 807.1 895.1 236.1
## [2,] 300.1 712.1 781.1
## [3,] 451.1 292.1 926.1
## [4,] 277.1 127.1 462.1
bc.d(x, y, "-")
## , , 1
## 
##       [,1]  [,2]  [,3]
## [1,] 512.1 400.1 323.1
## [2,] 104.1 659.1 559.1
## [3,] 260.1 360.1 420.1
## [4,] 554.1 831.1 263.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 805.1 893.1 234.1
## [2,] 296.1 708.1 777.1
## [3,] 445.1 286.1 920.1
## [4,] 269.1 119.1 454.1
bc.d(x, y, "*")
## , , 1
## 
##        [,1]   [,2]   [,3]
## [1,]  513.1  401.1  324.1
## [2,]  212.2 1322.2 1122.2
## [3,]  789.3 1089.3 1269.3
## [4,] 2232.4 3340.4 1068.4
## 
## , , 2
## 
##        [,1]   [,2]   [,3]
## [1,]  806.1  894.1  235.1
## [2,]  596.2 1420.2 1558.2
## [3,] 1344.3  867.3 2769.3
## [4,] 1092.4  492.4 1832.4
bc.d(x, y, "/")
## , , 1
## 
##         [,1]     [,2]     [,3]
## [1,] 513.100 401.1000 324.1000
## [2,]  53.050 330.5500 280.5500
## [3,]  87.700 121.0333 141.0333
## [4,] 139.525 208.7750  66.7750
## 
## , , 2
## 
##          [,1]      [,2]    [,3]
## [1,] 806.1000 894.10000 235.100
## [2,] 149.0500 355.05000 389.550
## [3,] 149.3667  96.36667 307.700
## [4,]  68.2750  30.77500 114.525
bc.d(x, y, "^")
## , , 1
## 
##              [,1]         [,2]         [,3]
## [1,] 5.131000e+02 4.011000e+02        324.1
## [2,] 1.125721e+04 4.370532e+05     314833.2
## [3,] 1.821221e+07 4.787169e+07   75740658.4
## [4,] 9.701706e+10 4.863556e+11 5089739464.6
## 
## , , 2
## 
##              [,1]        [,2]         [,3]
## [1,] 8.061000e+02       894.1 2.351000e+02
## [2,] 8.886361e+04    504242.0 6.069968e+05
## [3,] 8.997562e+07  24162634.0 7.865861e+08
## [4,] 5.562715e+09 229631896.0 4.403938e+10

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