1 | 'use strict'
|
2 |
|
3 | const deepMap = require('../../utils/collection/deepMap')
|
4 |
|
5 | function factory (type, config, load, typed) {
|
6 | const gamma = load(require('./gamma'))
|
7 | const latex = require('../../utils/latex')
|
8 |
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | const factorial = typed('factorial', {
|
32 | 'number': function (n) {
|
33 | if (n < 0) {
|
34 | throw new Error('Value must be non-negative')
|
35 | }
|
36 |
|
37 | return gamma(n + 1)
|
38 | },
|
39 |
|
40 | 'BigNumber': function (n) {
|
41 | if (n.isNegative()) {
|
42 | throw new Error('Value must be non-negative')
|
43 | }
|
44 |
|
45 | return gamma(n.plus(1))
|
46 | },
|
47 |
|
48 | 'Array | Matrix': function (n) {
|
49 | return deepMap(n, factorial)
|
50 | }
|
51 | })
|
52 |
|
53 | factorial.toTex = {
|
54 | 1: `\\left(\${args[0]}\\right)${latex.operators['factorial']}`
|
55 | }
|
56 |
|
57 | return factorial
|
58 | }
|
59 |
|
60 | exports.name = 'factorial'
|
61 | exports.factory = factory
|