forked from josdejong/mathjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxor.js
More file actions
75 lines (68 loc) · 2.34 KB
/
xor.js
File metadata and controls
75 lines (68 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { createMatAlgo03xDSf } from '../../type/matrix/utils/matAlgo03xDSf.js'
import { createMatAlgo07xSSf } from '../../type/matrix/utils/matAlgo07xSSf.js'
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js'
import { factory } from '../../utils/factory.js'
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js'
import { xorNumber } from '../../plain/number/index.js'
const name = 'xor'
const dependencies = [
'typed',
'matrix',
'DenseMatrix',
'concat',
'SparseMatrix'
]
export const createXor = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, DenseMatrix, concat, SparseMatrix }) => {
const matAlgo03xDSf = createMatAlgo03xDSf({ typed })
const matAlgo07xSSf = createMatAlgo07xSSf({ typed, SparseMatrix })
const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix })
const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat })
/**
* Logical `xor`. Test whether one and only one value is defined with a nonzero/nonempty value.
* For matrices, the function is evaluated element wise.
*
* Syntax:
*
* math.xor(x, y)
*
* Examples:
*
* math.xor(2, 4) // returns false
*
* a = [2, 0, 0]
* b = [2, 7, 0]
* c = 0
*
* math.xor(a, b) // returns [false, true, false]
* math.xor(a, c) // returns [true, false, false]
*
* See also:
*
* and, not, or
*
* @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} x First value to check
* @param {number | BigNumber | bigint | Complex | Unit | Array | Matrix} y Second value to check
* @return {boolean | Array | Matrix}
* Returns true when one and only one input is defined with a nonzero/nonempty value.
*/
return typed(
name,
{
'number, number': xorNumber,
'Complex, Complex': function (x, y) {
return ((x.re !== 0 || x.im !== 0) !== (y.re !== 0 || y.im !== 0))
},
'bigint, bigint': xorNumber,
'BigNumber, BigNumber': function (x, y) {
return ((!x.isZero() && !x.isNaN()) !== (!y.isZero() && !y.isNaN()))
},
'Unit, Unit': typed.referToSelf(self =>
(x, y) => self(x.value || 0, y.value || 0))
},
matrixAlgorithmSuite({
SS: matAlgo07xSSf,
DS: matAlgo03xDSf,
Ss: matAlgo12xSfs
})
)
})