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 the "+", "-" operators:
An array of type double or integer (depending on the input types) as a result of the broadcasted operation.
Integer overflow results in an error (base ‘R’, in contrast, gives an warning and returns NA at integer overflow).

For the "*", "/", "^" operators:
An array of type double as a result of the broadcasted operation.

For relational operators:
A logical array as a result of the broadcasted decimal relational comparison.

For pmin/pmax:
An array of type double or integer (depending on the input types) as a result of the broadcasted operation.

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,] 806.1 595.1  964.1
#> [2,] 367.1 578.1 1001.1
#> [3,] 785.1 611.1  982.1
#> [4,] 139.1 443.1  939.1
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 662.1 352.1 387.1
#> [2,] 281.1 793.1 177.1
#> [3,] 180.1 815.1 580.1
#> [4,] 138.1 995.1 845.1
bc.d(x, y, "-")
#> , , 1
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 804.1 593.1 962.1
#> [2,] 363.1 574.1 997.1
#> [3,] 779.1 605.1 976.1
#> [4,] 131.1 435.1 931.1
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 660.1 350.1 385.1
#> [2,] 277.1 789.1 173.1
#> [3,] 174.1 809.1 574.1
#> [4,] 130.1 987.1 837.1
bc.d(x, y, "*")
#> , , 1
#> 
#>        [,1]   [,2]   [,3]
#> [1,]  805.1  594.1  963.1
#> [2,]  730.2 1152.2 1998.2
#> [3,] 2346.3 1824.3 2937.3
#> [4,]  540.4 1756.4 3740.4
#> 
#> , , 2
#> 
#>       [,1]   [,2]   [,3]
#> [1,] 661.1  351.1  386.1
#> [2,] 558.2 1582.2  350.2
#> [3,] 531.3 2436.3 1731.3
#> [4,] 536.4 3964.4 3364.4
bc.d(x, y, "/")
#> , , 1
#> 
#>         [,1]    [,2]     [,3]
#> [1,] 805.100 594.100 963.1000
#> [2,] 182.550 288.050 499.5500
#> [3,] 260.700 202.700 326.3667
#> [4,]  33.775 109.775 233.7750
#> 
#> , , 2
#> 
#>           [,1]    [,2]     [,3]
#> [1,] 661.10000 351.100 386.1000
#> [2,] 139.55000 395.550  87.5500
#> [3,]  59.03333 270.700 192.3667
#> [4,]  33.52500 247.775 210.2750
bc.d(x, y, "^")
#> , , 1
#> 
#>             [,1]         [,2]         [,3]
#> [1,]       805.1 5.941000e+02 9.631000e+02
#> [2,]    133298.0 3.318912e+05 9.982008e+05
#> [3,] 478395248.7 2.248666e+08 9.386013e+08
#> [4,] 333135869.0 3.717524e+10 7.645964e+11
#> 
#> , , 2
#> 
#>              [,1]         [,2]         [,3]
#> [1,]       661.10 3.511000e+02 3.861000e+02
#> [2,]     77896.81 6.258392e+05 3.066001e+04
#> [3,]   5554637.01 5.355852e+08 1.921999e+08
#> [4,] 323381455.50 9.648724e+11 5.004844e+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