UNPKG

3.28 kBJavaScriptView Raw
1import { bitOrBigNumber } from '../../utils/bignumber/bitwise'
2import { factory } from '../../utils/factory'
3import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14'
4import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13'
5import { createAlgorithm10 } from '../../type/matrix/utils/algorithm10'
6import { createAlgorithm04 } from '../../type/matrix/utils/algorithm04'
7import { createAlgorithm01 } from '../../type/matrix/utils/algorithm01'
8import { bitOrNumber } from '../../plain/number'
9
10const name = 'bitOr'
11const dependencies = [
12 'typed',
13 'matrix',
14 'equalScalar',
15 'DenseMatrix'
16]
17
18export const createBitOr = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, DenseMatrix }) => {
19 const algorithm01 = createAlgorithm01({ typed })
20 const algorithm04 = createAlgorithm04({ typed, equalScalar })
21 const algorithm10 = createAlgorithm10({ typed, DenseMatrix })
22 const algorithm13 = createAlgorithm13({ typed })
23 const algorithm14 = createAlgorithm14({ typed })
24
25 /**
26 * Bitwise OR two values, `x | y`.
27 * For matrices, the function is evaluated element wise.
28 * For units, the function is evaluated on the lowest print base.
29 *
30 * Syntax:
31 *
32 * math.bitOr(x, y)
33 *
34 * Examples:
35 *
36 * math.bitOr(1, 2) // returns number 3
37 *
38 * math.bitOr([1, 2, 3], 4) // returns Array [5, 6, 7]
39 *
40 * See also:
41 *
42 * bitAnd, bitNot, bitXor, leftShift, rightArithShift, rightLogShift
43 *
44 * @param {number | BigNumber | Array | Matrix} x First value to or
45 * @param {number | BigNumber | Array | Matrix} y Second value to or
46 * @return {number | BigNumber | Array | Matrix} OR of `x` and `y`
47 */
48 const bitOr = typed(name, {
49
50 'number, number': bitOrNumber,
51
52 'BigNumber, BigNumber': bitOrBigNumber,
53
54 'SparseMatrix, SparseMatrix': function (x, y) {
55 return algorithm04(x, y, bitOr)
56 },
57
58 'SparseMatrix, DenseMatrix': function (x, y) {
59 return algorithm01(y, x, bitOr, true)
60 },
61
62 'DenseMatrix, SparseMatrix': function (x, y) {
63 return algorithm01(x, y, bitOr, false)
64 },
65
66 'DenseMatrix, DenseMatrix': function (x, y) {
67 return algorithm13(x, y, bitOr)
68 },
69
70 'Array, Array': function (x, y) {
71 // use matrix implementation
72 return bitOr(matrix(x), matrix(y)).valueOf()
73 },
74
75 'Array, Matrix': function (x, y) {
76 // use matrix implementation
77 return bitOr(matrix(x), y)
78 },
79
80 'Matrix, Array': function (x, y) {
81 // use matrix implementation
82 return bitOr(x, matrix(y))
83 },
84
85 'SparseMatrix, any': function (x, y) {
86 return algorithm10(x, y, bitOr, false)
87 },
88
89 'DenseMatrix, any': function (x, y) {
90 return algorithm14(x, y, bitOr, false)
91 },
92
93 'any, SparseMatrix': function (x, y) {
94 return algorithm10(y, x, bitOr, true)
95 },
96
97 'any, DenseMatrix': function (x, y) {
98 return algorithm14(y, x, bitOr, true)
99 },
100
101 'Array, any': function (x, y) {
102 // use matrix implementation
103 return algorithm14(matrix(x), y, bitOr, false).valueOf()
104 },
105
106 'any, Array': function (x, y) {
107 // use matrix implementation
108 return algorithm14(matrix(y), x, bitOr, true).valueOf()
109 }
110 })
111
112 return bitOr
113})