mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
var deepMap = require('../../utils/collection/deepMap');
|
|
|
|
function factory (type, config, load, typed) {
|
|
var latex = require('../../utils/latex');
|
|
|
|
/**
|
|
* Logical `not`. Flips boolean value of a given parameter.
|
|
* For matrices, the function is evaluated element wise.
|
|
*
|
|
* Syntax:
|
|
*
|
|
* math.not(x)
|
|
*
|
|
* Examples:
|
|
*
|
|
* math.not(2); // returns false
|
|
* math.not(0); // returns true
|
|
* math.not(true); // returns false
|
|
*
|
|
* a = [2, -7, 0];
|
|
* math.not(a); // returns [false, false, true]
|
|
*
|
|
* See also:
|
|
*
|
|
* and, or, xor
|
|
*
|
|
* @param {number | BigNumber | Complex | Unit | Array | Matrix} x First value to check
|
|
* @return {boolean | Array | Matrix}
|
|
* Returns true when input is a zero or empty value.
|
|
*/
|
|
var not = typed('not', {
|
|
'number': function (x) {
|
|
return !x;
|
|
},
|
|
|
|
'Complex': function (x) {
|
|
return x.re === 0 && x.im === 0;
|
|
},
|
|
|
|
'BigNumber': function (x) {
|
|
return x.isZero() || x.isNaN();
|
|
},
|
|
|
|
'Unit': function (x) {
|
|
return not(x.value);
|
|
},
|
|
|
|
'Array | Matrix': function (x) {
|
|
return deepMap(x, not);
|
|
}
|
|
});
|
|
|
|
not.toTex = latex.operators['not'] + '\\left(${args[0]}\\right)';
|
|
|
|
return not;
|
|
}
|
|
|
|
exports.name = 'not';
|
|
exports.factory = factory;
|