not.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { deepMap } from '../../utils/collection.js';
  2. import { factory } from '../../utils/factory.js';
  3. import { notNumber } from '../../plain/number/index.js';
  4. var name = 'not';
  5. var dependencies = ['typed'];
  6. export var createNot = /* #__PURE__ */factory(name, dependencies, _ref => {
  7. var {
  8. typed
  9. } = _ref;
  10. /**
  11. * Logical `not`. Flips boolean value of a given parameter.
  12. * For matrices, the function is evaluated element wise.
  13. *
  14. * Syntax:
  15. *
  16. * math.not(x)
  17. *
  18. * Examples:
  19. *
  20. * math.not(2) // returns false
  21. * math.not(0) // returns true
  22. * math.not(true) // returns false
  23. *
  24. * a = [2, -7, 0]
  25. * math.not(a) // returns [false, false, true]
  26. *
  27. * See also:
  28. *
  29. * and, or, xor
  30. *
  31. * @param {number | BigNumber | Complex | Unit | Array | Matrix} x First value to check
  32. * @return {boolean | Array | Matrix}
  33. * Returns true when input is a zero or empty value.
  34. */
  35. return typed(name, {
  36. 'null | undefined': () => true,
  37. number: notNumber,
  38. Complex: function Complex(x) {
  39. return x.re === 0 && x.im === 0;
  40. },
  41. BigNumber: function BigNumber(x) {
  42. return x.isZero() || x.isNaN();
  43. },
  44. Unit: typed.referToSelf(self => x => typed.find(self, x.valueType())(x.value)),
  45. 'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
  46. });
  47. });