isNaN.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { deepMap } from '../../utils/collection.js';
  2. import { factory } from '../../utils/factory.js';
  3. import { isNaNNumber } from '../../plain/number/index.js';
  4. var name = 'isNaN';
  5. var dependencies = ['typed'];
  6. export var createIsNaN = /* #__PURE__ */factory(name, dependencies, _ref => {
  7. var {
  8. typed
  9. } = _ref;
  10. /**
  11. * Test whether a value is NaN (not a number).
  12. * The function supports types `number`, `BigNumber`, `Fraction`, `Unit` and `Complex`.
  13. *
  14. * The function is evaluated element-wise in case of Array or Matrix input.
  15. *
  16. * Syntax:
  17. *
  18. * math.isNaN(x)
  19. *
  20. * Examples:
  21. *
  22. * math.isNaN(3) // returns false
  23. * math.isNaN(NaN) // returns true
  24. * math.isNaN(0) // returns false
  25. * math.isNaN(math.bignumber(NaN)) // returns true
  26. * math.isNaN(math.bignumber(0)) // returns false
  27. * math.isNaN(math.fraction(-2, 5)) // returns false
  28. * math.isNaN('-2') // returns false
  29. * math.isNaN([2, 0, -3, NaN]) // returns [false, false, false, true]
  30. *
  31. * See also:
  32. *
  33. * isNumeric, isNegative, isPositive, isZero, isInteger
  34. *
  35. * @param {number | BigNumber | Fraction | Unit | Array | Matrix} x Value to be tested
  36. * @return {boolean} Returns true when `x` is NaN.
  37. * Throws an error in case of an unknown data type.
  38. */
  39. return typed(name, {
  40. number: isNaNNumber,
  41. BigNumber: function BigNumber(x) {
  42. return x.isNaN();
  43. },
  44. Fraction: function Fraction(x) {
  45. return false;
  46. },
  47. Complex: function Complex(x) {
  48. return x.isNaN();
  49. },
  50. Unit: function Unit(x) {
  51. return Number.isNaN(x.value);
  52. },
  53. 'Array | Matrix': function ArrayMatrix(x) {
  54. return deepMap(x, Number.isNaN);
  55. }
  56. });
  57. });