1 | 'use strict'
|
2 |
|
3 | const isInteger = require('../../utils/number').isInteger
|
4 | const bigBitXor = require('../../utils/bignumber/bitXor')
|
5 |
|
6 | function factory (type, config, load, typed) {
|
7 | const latex = require('../../utils/latex')
|
8 |
|
9 | const matrix = load(require('../../type/matrix/function/matrix'))
|
10 |
|
11 | const algorithm03 = load(require('../../type/matrix/utils/algorithm03'))
|
12 | const algorithm07 = load(require('../../type/matrix/utils/algorithm07'))
|
13 | const algorithm12 = load(require('../../type/matrix/utils/algorithm12'))
|
14 | const algorithm13 = load(require('../../type/matrix/utils/algorithm13'))
|
15 | const algorithm14 = load(require('../../type/matrix/utils/algorithm14'))
|
16 |
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | const bitXor = typed('bitXor', {
|
40 |
|
41 | 'number, number': function (x, y) {
|
42 | if (!isInteger(x) || !isInteger(y)) {
|
43 | throw new Error('Integers expected in function bitXor')
|
44 | }
|
45 |
|
46 | return x ^ y
|
47 | },
|
48 |
|
49 | 'BigNumber, BigNumber': bigBitXor,
|
50 |
|
51 | 'SparseMatrix, SparseMatrix': function (x, y) {
|
52 | return algorithm07(x, y, bitXor)
|
53 | },
|
54 |
|
55 | 'SparseMatrix, DenseMatrix': function (x, y) {
|
56 | return algorithm03(y, x, bitXor, true)
|
57 | },
|
58 |
|
59 | 'DenseMatrix, SparseMatrix': function (x, y) {
|
60 | return algorithm03(x, y, bitXor, false)
|
61 | },
|
62 |
|
63 | 'DenseMatrix, DenseMatrix': function (x, y) {
|
64 | return algorithm13(x, y, bitXor)
|
65 | },
|
66 |
|
67 | 'Array, Array': function (x, y) {
|
68 |
|
69 | return bitXor(matrix(x), matrix(y)).valueOf()
|
70 | },
|
71 |
|
72 | 'Array, Matrix': function (x, y) {
|
73 |
|
74 | return bitXor(matrix(x), y)
|
75 | },
|
76 |
|
77 | 'Matrix, Array': function (x, y) {
|
78 |
|
79 | return bitXor(x, matrix(y))
|
80 | },
|
81 |
|
82 | 'SparseMatrix, any': function (x, y) {
|
83 | return algorithm12(x, y, bitXor, false)
|
84 | },
|
85 |
|
86 | 'DenseMatrix, any': function (x, y) {
|
87 | return algorithm14(x, y, bitXor, false)
|
88 | },
|
89 |
|
90 | 'any, SparseMatrix': function (x, y) {
|
91 | return algorithm12(y, x, bitXor, true)
|
92 | },
|
93 |
|
94 | 'any, DenseMatrix': function (x, y) {
|
95 | return algorithm14(y, x, bitXor, true)
|
96 | },
|
97 |
|
98 | 'Array, any': function (x, y) {
|
99 |
|
100 | return algorithm14(matrix(x), y, bitXor, false).valueOf()
|
101 | },
|
102 |
|
103 | 'any, Array': function (x, y) {
|
104 |
|
105 | return algorithm14(matrix(y), x, bitXor, true).valueOf()
|
106 | }
|
107 | })
|
108 |
|
109 | bitXor.toTex = {
|
110 | 2: `\\left(\${args[0]}${latex.operators['bitXor']}\${args[1]}\\right)`
|
111 | }
|
112 |
|
113 | return bitXor
|
114 | }
|
115 |
|
116 | exports.name = 'bitXor'
|
117 | exports.factory = factory
|