forked from josdejong/mathjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitNot.js
More file actions
56 lines (47 loc) · 1.3 KB
/
bitNot.js
File metadata and controls
56 lines (47 loc) · 1.3 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
'use strict'
const deepMap = require('../../utils/collection/deepMap')
const bigBitNot = require('../../utils/bignumber/bitNot')
const isInteger = require('../../utils/number').isInteger
function factory (type, config, load, typed) {
const latex = require('../../utils/latex')
/**
* Bitwise NOT value, `~x`.
* For matrices, the function is evaluated element wise.
* For units, the function is evaluated on the best prefix base.
*
* Syntax:
*
* math.bitNot(x)
*
* Examples:
*
* math.bitNot(1) // returns number -2
*
* math.bitNot([2, -3, 4]) // returns Array [-3, 2, 5]
*
* See also:
*
* bitAnd, bitOr, bitXor, leftShift, rightArithShift, rightLogShift
*
* @param {number | BigNumber | Array | Matrix} x Value to not
* @return {number | BigNumber | Array | Matrix} NOT of `x`
*/
const bitNot = typed('bitNot', {
'number': function (x) {
if (!isInteger(x)) {
throw new Error('Integer expected in function bitNot')
}
return ~x
},
'BigNumber': bigBitNot,
'Array | Matrix': function (x) {
return deepMap(x, bitNot)
}
})
bitNot.toTex = {
1: latex.operators['bitNot'] + `\\left(\${args[0]}\\right)`
}
return bitNot
}
exports.name = 'bitNot'
exports.factory = factory