bitAnd.js (3474B)
1 import { bitAndBigNumber } from '../../utils/bignumber/bitwise.js'; 2 import { createAlgorithm02 } from '../../type/matrix/utils/algorithm02.js'; 3 import { createAlgorithm11 } from '../../type/matrix/utils/algorithm11.js'; 4 import { createAlgorithm13 } from '../../type/matrix/utils/algorithm13.js'; 5 import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14.js'; 6 import { createAlgorithm06 } from '../../type/matrix/utils/algorithm06.js'; 7 import { factory } from '../../utils/factory.js'; 8 import { bitAndNumber } from '../../plain/number/index.js'; 9 var name = 'bitAnd'; 10 var dependencies = ['typed', 'matrix', 'equalScalar']; 11 export var createBitAnd = /* #__PURE__ */factory(name, dependencies, _ref => { 12 var { 13 typed, 14 matrix, 15 equalScalar 16 } = _ref; 17 var algorithm02 = createAlgorithm02({ 18 typed, 19 equalScalar 20 }); 21 var algorithm06 = createAlgorithm06({ 22 typed, 23 equalScalar 24 }); 25 var algorithm11 = createAlgorithm11({ 26 typed, 27 equalScalar 28 }); 29 var algorithm13 = createAlgorithm13({ 30 typed 31 }); 32 var algorithm14 = createAlgorithm14({ 33 typed 34 }); 35 /** 36 * Bitwise AND two values, `x & y`. 37 * For matrices, the function is evaluated element wise. 38 * 39 * Syntax: 40 * 41 * math.bitAnd(x, y) 42 * 43 * Examples: 44 * 45 * math.bitAnd(53, 131) // returns number 1 46 * 47 * math.bitAnd([1, 12, 31], 42) // returns Array [0, 8, 10] 48 * 49 * See also: 50 * 51 * bitNot, bitOr, bitXor, leftShift, rightArithShift, rightLogShift 52 * 53 * @param {number | BigNumber | Array | Matrix} x First value to and 54 * @param {number | BigNumber | Array | Matrix} y Second value to and 55 * @return {number | BigNumber | Array | Matrix} AND of `x` and `y` 56 */ 57 58 return typed(name, { 59 'number, number': bitAndNumber, 60 'BigNumber, BigNumber': bitAndBigNumber, 61 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) { 62 return algorithm06(x, y, this, false); 63 }, 64 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) { 65 return algorithm02(y, x, this, true); 66 }, 67 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) { 68 return algorithm02(x, y, this, false); 69 }, 70 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) { 71 return algorithm13(x, y, this); 72 }, 73 'Array, Array': function ArrayArray(x, y) { 74 // use matrix implementation 75 return this(matrix(x), matrix(y)).valueOf(); 76 }, 77 'Array, Matrix': function ArrayMatrix(x, y) { 78 // use matrix implementation 79 return this(matrix(x), y); 80 }, 81 'Matrix, Array': function MatrixArray(x, y) { 82 // use matrix implementation 83 return this(x, matrix(y)); 84 }, 85 'SparseMatrix, any': function SparseMatrixAny(x, y) { 86 return algorithm11(x, y, this, false); 87 }, 88 'DenseMatrix, any': function DenseMatrixAny(x, y) { 89 return algorithm14(x, y, this, false); 90 }, 91 'any, SparseMatrix': function anySparseMatrix(x, y) { 92 return algorithm11(y, x, this, true); 93 }, 94 'any, DenseMatrix': function anyDenseMatrix(x, y) { 95 return algorithm14(y, x, this, true); 96 }, 97 'Array, any': function ArrayAny(x, y) { 98 // use matrix implementation 99 return algorithm14(matrix(x), y, this, false).valueOf(); 100 }, 101 'any, Array': function anyArray(x, y) { 102 // use matrix implementation 103 return algorithm14(matrix(y), x, this, true).valueOf(); 104 } 105 }); 106 });