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,] 250.1 242.1 440.1
## [2,] 812.1 319.1 339.1
## [3,] 553.1 431.1  20.1
## [4,] 239.1 160.1 300.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 275.1 694.1 330.1
## [2,] 206.1 842.1 742.1
## [3,] 469.1 612.1 896.1
## [4,] 717.1 546.1 148.1
bc.d(x, y, "-")
## , , 1
## 
##       [,1]  [,2]  [,3]
## [1,] 248.1 240.1 438.1
## [2,] 808.1 315.1 335.1
## [3,] 547.1 425.1  14.1
## [4,] 231.1 152.1 292.1
## 
## , , 2
## 
##       [,1]  [,2]  [,3]
## [1,] 273.1 692.1 328.1
## [2,] 202.1 838.1 738.1
## [3,] 463.1 606.1 890.1
## [4,] 709.1 538.1 140.1
bc.d(x, y, "*")
## , , 1
## 
##        [,1]   [,2]   [,3]
## [1,]  249.1  241.1  439.1
## [2,] 1620.2  634.2  674.2
## [3,] 1650.3 1284.3   51.3
## [4,]  940.4  624.4 1184.4
## 
## , , 2
## 
##        [,1]   [,2]   [,3]
## [1,]  274.1  693.1  329.1
## [2,]  408.2 1680.2 1480.2
## [3,] 1398.3 1827.3 2679.3
## [4,] 2852.4 2168.4  576.4
bc.d(x, y, "/")
## , , 1
## 
##          [,1]    [,2]    [,3]
## [1,] 249.1000 241.100 439.100
## [2,] 405.0500 158.550 168.550
## [3,] 183.3667 142.700   5.700
## [4,]  58.7750  39.025  74.025
## 
## , , 2
## 
##          [,1]     [,2]    [,3]
## [1,] 274.1000 693.1000 329.100
## [2,] 102.0500 420.0500 370.050
## [3,] 155.3667 203.0333 297.700
## [4,] 178.2750 135.5250  36.025
bc.d(x, y, "^")
## , , 1
## 
##              [,1]        [,2]         [,3]
## [1,]        249.1       241.1 4.391000e+02
## [2,]     656262.0    100552.4 1.136364e+05
## [3,]  166465766.5  78457720.0 5.000211e+03
## [4,] 3054995089.4 593760923.2 7.686942e+09
## 
## , , 2
## 
##              [,1]         [,2]        [,3]
## [1,] 2.741000e+02 6.931000e+02       329.1
## [2,] 4.165681e+04 7.057680e+05    547748.0
## [3,] 1.012599e+08 2.259778e+08 712361218.5
## [4,] 2.585841e+11 8.636099e+10 431177334.3

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