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,] 911.1 821.1 551.1
#> [2,] 284.1 686.1  90.1
#> [3,] 798.1 321.1 740.1
#> [4,] 214.1 414.1 403.1
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 127.1 196.1 124.1
#> [2,] 642.1 919.1 653.1
#> [3,] 623.1 494.1 882.1
#> [4,] 515.1 525.1  57.1
bc.d(x, y, "-")
#> , , 1
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 909.1 819.1 549.1
#> [2,] 280.1 682.1  86.1
#> [3,] 792.1 315.1 734.1
#> [4,] 206.1 406.1 395.1
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 125.1 194.1 122.1
#> [2,] 638.1 915.1 649.1
#> [3,] 617.1 488.1 876.1
#> [4,] 507.1 517.1  49.1
bc.d(x, y, "*")
#> , , 1
#> 
#>        [,1]   [,2]   [,3]
#> [1,]  910.1  820.1  550.1
#> [2,]  564.2 1368.2  176.2
#> [3,] 2385.3  954.3 2211.3
#> [4,]  840.4 1640.4 1596.4
#> 
#> , , 2
#> 
#>        [,1]   [,2]   [,3]
#> [1,]  126.1  195.1  123.1
#> [2,] 1280.2 1834.2 1302.2
#> [3,] 1860.3 1473.3 2637.3
#> [4,] 2044.4 2084.4  212.4
bc.d(x, y, "/")
#> , , 1
#> 
#>          [,1]     [,2]    [,3]
#> [1,] 910.1000 820.1000 550.100
#> [2,] 141.0500 342.0500  44.050
#> [3,] 265.0333 106.0333 245.700
#> [4,]  52.5250 102.5250  99.775
#> 
#> , , 2
#> 
#>         [,1]    [,2]     [,3]
#> [1,] 126.100 195.100 123.1000
#> [2,] 320.050 458.550 325.5500
#> [3,] 206.700 163.700 293.0333
#> [4,] 127.775 130.275  13.2750
bc.d(x, y, "^")
#> , , 1
#> 
#>              [,1]         [,2]         [,3]
#> [1,] 9.101000e+02 8.201000e+02 5.501000e+02
#> [2,] 7.958041e+04 4.679928e+05 7.761610e+03
#> [3,] 5.026495e+08 3.218778e+07 4.004785e+08
#> [4,] 1.948517e+09 2.828519e+10 2.537038e+10
#> 
#> , , 2
#> 
#>              [,1]         [,2]        [,3]
#> [1,] 1.261000e+02 1.951000e+02       123.1
#> [2,] 4.097280e+05 8.410724e+05    423931.2
#> [3,] 2.384433e+08 1.184431e+08 679383257.7
#> [4,] 6.823757e+10 7.373680e+10   7950200.6

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