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.
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,] 387.1 112.1 119.1
## [2,] 379.1 306.1 708.1
## [3,] 433.1 581.1 320.1
## [4,] 272.1 402.1  52.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 482.1 733.1 919.1
## [2,] 156.1 125.1 845.1
## [3,] 998.1 828.1 613.1
## [4,] 272.1 743.1 746.1
bc.d(x, y, "-")
## , , 1
## 
##       [,1]  [,2]  [,3]
## [1,] 385.1 110.1 117.1
## [2,] 375.1 302.1 704.1
## [3,] 427.1 575.1 314.1
## [4,] 264.1 394.1  44.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 480.1 731.1 917.1
## [2,] 152.1 121.1 841.1
## [3,] 992.1 822.1 607.1
## [4,] 264.1 735.1 738.1
bc.d(x, y, "*")
## , , 1
## 
##        [,1]   [,2]   [,3]
## [1,]  386.1  111.1  118.1
## [2,]  754.2  608.2 1412.2
## [3,] 1290.3 1734.3  951.3
## [4,] 1072.4 1592.4  192.4
## 
## , , 2
## 
##        [,1]   [,2]   [,3]
## [1,]  481.1  732.1  918.1
## [2,]  308.2  246.2 1686.2
## [3,] 2985.3 2475.3 1830.3
## [4,] 1072.4 2956.4 2968.4
bc.d(x, y, "/")
## , , 1
## 
##          [,1]    [,2]    [,3]
## [1,] 386.1000 111.100 118.100
## [2,] 188.5500 152.050 353.050
## [3,] 143.3667 192.700 105.700
## [4,]  67.0250  99.525  12.025
## 
## , , 2
## 
##         [,1]     [,2]     [,3]
## [1,] 481.100 732.1000 918.1000
## [2,]  77.050  61.5500 421.5500
## [3,] 331.700 275.0333 203.3667
## [4,]  67.025 184.7750 185.5250
bc.d(x, y, "^")
## , , 1
## 
##              [,1]         [,2]       [,3]
## [1,]        386.1 1.111000e+02      118.1
## [2,]     142204.4 9.247681e+04   498577.2
## [3,]   79562482.9 1.932008e+08 31885169.2
## [4,] 5166390819.3 2.511705e+10  5352791.2
## 
## , , 2
## 
##              [,1]         [,2]         [,3]
## [1,] 4.811000e+02 7.321000e+02 9.181000e+02
## [2,] 2.374681e+04 1.515361e+04 7.108176e+05
## [3,] 9.853719e+08 5.617198e+08 2.270926e+08
## [4,] 5.166391e+09 2.984096e+11 3.032842e+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