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,] 240.1 249.1 129.1
#> [2,] 292.1 780.1 433.1
#> [3,] 856.1 261.1 419.1
#> [4,] 812.1 698.1 112.1
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 334.1 968.1 331.1
#> [2,] 922.1 545.1 322.1
#> [3,] 968.1 927.1  23.1
#> [4,] 492.1  24.1 738.1
bc.d(x, y, "-")
#> , , 1
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 238.1 247.1 127.1
#> [2,] 288.1 776.1 429.1
#> [3,] 850.1 255.1 413.1
#> [4,] 804.1 690.1 104.1
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,] 332.1 966.1 329.1
#> [2,] 918.1 541.1 318.1
#> [3,] 962.1 921.1  17.1
#> [4,] 484.1  16.1 730.1
bc.d(x, y, "*")
#> , , 1
#> 
#>        [,1]   [,2]   [,3]
#> [1,]  239.1  248.1  128.1
#> [2,]  580.2 1556.2  862.2
#> [3,] 2559.3  774.3 1248.3
#> [4,] 3232.4 2776.4  432.4
#> 
#> , , 2
#> 
#>        [,1]   [,2]   [,3]
#> [1,]  333.1  967.1  330.1
#> [2,] 1840.2 1086.2  640.2
#> [3,] 2895.3 2772.3   60.3
#> [4,] 1952.4   80.4 2936.4
bc.d(x, y, "/")
#> , , 1
#> 
#>          [,1]      [,2]    [,3]
#> [1,] 239.1000 248.10000 128.100
#> [2,] 145.0500 389.05000 215.550
#> [3,] 284.3667  86.03333 138.700
#> [4,] 202.0250 173.52500  27.025
#> 
#> , , 2
#> 
#>         [,1]     [,2]    [,3]
#> [1,] 333.100 967.1000 330.100
#> [2,] 460.050 271.5500 160.050
#> [3,] 321.700 308.0333   6.700
#> [4,] 122.025   5.0250 183.525
bc.d(x, y, "^")
#> , , 1
#> 
#>              [,1]         [,2]        [,3]
#> [1,] 2.391000e+02 2.481000e+02       128.1
#> [2,] 8.415801e+04 6.054396e+05    185847.2
#> [3,] 6.208688e+08 1.719349e+07  72043225.3
#> [4,] 4.264424e+11 2.321070e+11 136553481.1
#> 
#> , , 2
#> 
#>              [,1]        [,2]         [,3]
#> [1,] 3.331000e+02       967.1 3.301000e+02
#> [2,] 8.465840e+05    294957.6 1.024640e+05
#> [3,] 8.989115e+08 789145184.5 8.120601e+03
#> [4,] 5.675906e+10    163224.1 2.904162e+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