factorial.js (1505B)
1 "use strict"; 2 3 Object.defineProperty(exports, "__esModule", { 4 value: true 5 }); 6 exports.createFactorial = void 0; 7 8 var _collection = require("../../utils/collection.js"); 9 10 var _factory = require("../../utils/factory.js"); 11 12 var name = 'factorial'; 13 var dependencies = ['typed', 'gamma']; 14 var createFactorial = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) { 15 var typed = _ref.typed, 16 gamma = _ref.gamma; 17 18 /** 19 * Compute the factorial of a value 20 * 21 * Factorial only supports an integer value as argument. 22 * For matrices, the function is evaluated element wise. 23 * 24 * Syntax: 25 * 26 * math.factorial(n) 27 * 28 * Examples: 29 * 30 * math.factorial(5) // returns 120 31 * math.factorial(3) // returns 6 32 * 33 * See also: 34 * 35 * combinations, combinationsWithRep, gamma, permutations 36 * 37 * @param {number | BigNumber | Array | Matrix} n An integer number 38 * @return {number | BigNumber | Array | Matrix} The factorial of `n` 39 */ 40 return typed(name, { 41 number: function number(n) { 42 if (n < 0) { 43 throw new Error('Value must be non-negative'); 44 } 45 46 return gamma(n + 1); 47 }, 48 BigNumber: function BigNumber(n) { 49 if (n.isNegative()) { 50 throw new Error('Value must be non-negative'); 51 } 52 53 return gamma(n.plus(1)); 54 }, 55 'Array | Matrix': function ArrayMatrix(n) { 56 return (0, _collection.deepMap)(n, this); 57 } 58 }); 59 }); 60 exports.createFactorial = createFactorial;