bc.d

Broadcasted Decimal Numeric Operations

Description

The bc.d() function performs broadcasted decimal numeric operations on 2 numeric or logical arrays.
bc.num() is an alias for bc.d().

Usage

bc.d(x, y, op, tol = sqrt(.Machine$double.eps))

bc.num(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>=.
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.

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,] 533.1  11.1 872.1
## [2,] 220.1 927.1 665.1
## [3,] 373.1  45.1 435.1
## [4,]    NA 814.1 626.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 145.1 336.1 718.1
## [2,] 976.1 858.1 609.1
## [3,] 730.1 235.1 953.1
## [4,] 776.1  41.1 952.1
bc.d(x, y, "-")
## , , 1
## 
##       [,1]  [,2]  [,3]
## [1,] 531.1   9.1 870.1
## [2,] 216.1 923.1 661.1
## [3,] 367.1  39.1 429.1
## [4,]    NA 806.1 618.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 143.1 334.1 716.1
## [2,] 972.1 854.1 605.1
## [3,] 724.1 229.1 947.1
## [4,] 768.1  33.1 944.1
bc.d(x, y, "*")
## , , 1
## 
##        [,1]   [,2]   [,3]
## [1,]  532.1   10.1  871.1
## [2,]  436.2 1850.2 1326.2
## [3,] 1110.3  126.3 1296.3
## [4,]     NA 3240.4 2488.4
## 
## , , 2
## 
##        [,1]   [,2]   [,3]
## [1,]  144.1  335.1  717.1
## [2,] 1948.2 1712.2 1214.2
## [3,] 2181.3  696.3 2850.3
## [4,] 3088.4  148.4 3792.4
bc.d(x, y, "/")
## , , 1
## 
##          [,1]      [,2]     [,3]
## [1,] 532.1000  10.10000 871.1000
## [2,] 109.0500 462.55000 331.5500
## [3,] 123.3667  14.03333 144.0333
## [4,]       NA 202.52500 155.5250
## 
## , , 2
## 
##          [,1]      [,2]    [,3]
## [1,] 144.1000 335.10000 717.100
## [2,] 487.0500 428.05000 303.550
## [3,] 242.3667  77.36667 316.700
## [4,] 193.0250   9.27500 237.025
bc.d(x, y, "^")
## , , 1
## 
##             [,1]         [,2]         [,3]
## [1,]      532.10 1.010000e+01 8.711000e+02
## [2,]    47567.61 8.558100e+05 4.397016e+05
## [3,] 50694081.10 7.461846e+04 8.067757e+07
## [4,]          NA 4.306798e+11 1.497755e+11
## 
## , , 2
## 
##              [,1]       [,2]         [,3]
## [1,] 1.441000e+02      335.1 7.171000e+02
## [2,] 9.488708e+05   732907.2 3.685704e+05
## [3,] 3.843992e+08 12503322.2 8.576458e+08
## [4,] 3.553810e+11  1894504.5 8.080097e+11

bc.d(x, y, "==")
## , , 1
## 
##       [,1]  [,2]  [,3]
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
## [4,]    NA 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,]   NA 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,]    NA 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,]   NA 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,]    NA 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,]   NA TRUE TRUE
## 
## , , 2
## 
##      [,1] [,2] [,3]
## [1,] TRUE TRUE TRUE
## [2,] TRUE TRUE TRUE
## [3,] TRUE TRUE TRUE
## [4,] TRUE TRUE TRUE