abs.js (1643B)
1 "use strict"; 2 3 Object.defineProperty(exports, "__esModule", { 4 value: true 5 }); 6 exports.createAbs = void 0; 7 8 var _factory = require("../../utils/factory.js"); 9 10 var _collection = require("../../utils/collection.js"); 11 12 var _index = require("../../plain/number/index.js"); 13 14 var name = 'abs'; 15 var dependencies = ['typed']; 16 var createAbs = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) { 17 var typed = _ref.typed; 18 19 /** 20 * Calculate the absolute value of a number. For matrices, the function is 21 * evaluated element wise. 22 * 23 * Syntax: 24 * 25 * math.abs(x) 26 * 27 * Examples: 28 * 29 * math.abs(3.5) // returns number 3.5 30 * math.abs(-4.2) // returns number 4.2 31 * 32 * math.abs([3, -5, -1, 0, 2]) // returns Array [3, 5, 1, 0, 2] 33 * 34 * See also: 35 * 36 * sign 37 * 38 * @param {number | BigNumber | Fraction | Complex | Array | Matrix | Unit} x 39 * A number or matrix for which to get the absolute value 40 * @return {number | BigNumber | Fraction | Complex | Array | Matrix | Unit} 41 * Absolute value of `x` 42 */ 43 return typed(name, { 44 number: _index.absNumber, 45 Complex: function Complex(x) { 46 return x.abs(); 47 }, 48 BigNumber: function BigNumber(x) { 49 return x.abs(); 50 }, 51 Fraction: function Fraction(x) { 52 return x.abs(); 53 }, 54 'Array | Matrix': function ArrayMatrix(x) { 55 // deep map collection, skip zeros since abs(0) = 0 56 return (0, _collection.deepMap)(x, this, true); 57 }, 58 Unit: function Unit(x) { 59 return x.abs(); 60 } 61 }); 62 }); 63 exports.createAbs = createAbs;