bc.d

Broadcasted Decimal Numeric Operations

Description

The bc.d() method 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 numeric or logical.
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,] 293.1 309.1 406.1
#> [2,] 145.1 915.1  88.1
#> [3,] 555.1  67.1 899.1
#> [4,] 377.1 762.1 163.1
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 490.1 632.1  68.1
#> [2,] 110.1 413.1 491.1
#> [3,]  93.1 661.1 372.1
#> [4,] 133.1 740.1 645.1
bc.d(x, y, "-")
#> , , 1
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 291.1 307.1 404.1
#> [2,] 141.1 911.1  84.1
#> [3,] 549.1  61.1 893.1
#> [4,] 369.1 754.1 155.1
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 488.1 630.1  66.1
#> [2,] 106.1 409.1 487.1
#> [3,]  87.1 655.1 366.1
#> [4,] 125.1 732.1 637.1
bc.d(x, y, "*")
#> , , 1
#> 
#>        [,1]   [,2]   [,3]
#> [1,]  292.1  308.1  405.1
#> [2,]  286.2 1826.2  172.2
#> [3,] 1656.3  192.3 2688.3
#> [4,] 1492.4 3032.4  636.4
#> 
#> , , 2
#> 
#>       [,1]   [,2]   [,3]
#> [1,] 489.1  631.1   67.1
#> [2,] 216.2  822.2  978.2
#> [3,] 270.3 1974.3 1107.3
#> [4,] 516.4 2944.4 2564.4
bc.d(x, y, "/")
#> , , 1
#> 
#>          [,1]      [,2]    [,3]
#> [1,] 292.1000 308.10000 405.100
#> [2,]  71.5500 456.55000  43.050
#> [3,] 184.0333  21.36667 298.700
#> [4,]  93.2750 189.52500  39.775
#> 
#> , , 2
#> 
#>           [,1]     [,2]     [,3]
#> [1,] 489.10000 631.1000  67.1000
#> [2,]  54.05000 205.5500 244.5500
#> [3,]  30.03333 219.3667 123.0333
#> [4,]  32.27500 184.0250 160.2750
bc.d(x, y, "^")
#> , , 1
#> 
#>              [,1]         [,2]         [,3]
#> [1,] 2.921000e+02 3.081000e+02       405.10
#> [2,] 2.047761e+04 8.337516e+05      7413.21
#> [3,] 1.682880e+08 2.633747e+05 719564007.68
#> [4,] 1.937765e+10 3.302980e+11 640738350.10
#> 
#> , , 2
#> 
#>              [,1]         [,2]         [,3]
#> [1,]       489.10 6.311000e+02 6.710000e+01
#> [2,]     11685.61 1.690032e+05 2.392188e+05
#> [3,]    731432.70 2.850202e+08 5.028427e+07
#> [4,] 277782555.58 2.935941e+11 1.689286e+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