@mirascript/mirascript 0.1.43 → 0.1.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-DNM6YMFU.js → chunk-CZOIPBED.js} +331 -205
- package/dist/chunk-CZOIPBED.js.map +6 -0
- package/dist/{chunk-GBWG7BQZ.js → chunk-UI6VQ263.js} +116 -42
- package/dist/chunk-UI6VQ263.js.map +6 -0
- package/dist/compiler/diagnostic.d.ts +4 -0
- package/dist/compiler/diagnostic.d.ts.map +1 -1
- package/dist/compiler/emit/constants.d.ts +3 -0
- package/dist/compiler/emit/constants.d.ts.map +1 -1
- package/dist/compiler/emit/index.d.ts +6 -1
- package/dist/compiler/emit/index.d.ts.map +1 -1
- package/dist/compiler/emit/sourcemap.d.ts +2 -1
- package/dist/compiler/emit/sourcemap.d.ts.map +1 -1
- package/dist/compiler/worker.js +1 -1
- package/dist/index.js +2 -2
- package/dist/subtle.js +6 -2
- package/dist/subtle.js.map +1 -1
- package/dist/vm/lib/global/debug.d.ts +11 -35
- package/dist/vm/lib/global/debug.d.ts.map +1 -1
- package/dist/vm/lib/global/index.d.ts +1 -1
- package/dist/vm/lib/global/index.d.ts.map +1 -1
- package/dist/vm/lib/global/math/arr.d.ts +7 -0
- package/dist/vm/lib/global/math/arr.d.ts.map +1 -0
- package/dist/vm/lib/global/math/const.d.ts +31 -0
- package/dist/vm/lib/global/math/const.d.ts.map +1 -0
- package/dist/vm/lib/global/math/gamma.d.ts +3 -0
- package/dist/vm/lib/global/math/gamma.d.ts.map +1 -0
- package/dist/vm/lib/global/math/index.d.ts +8 -0
- package/dist/vm/lib/global/math/index.d.ts.map +1 -0
- package/dist/vm/lib/global/math/unary.d.ts +28 -0
- package/dist/vm/lib/global/math/unary.d.ts.map +1 -0
- package/dist/vm/lib/helpers.d.ts.map +1 -1
- package/dist/vm/lib/loader.d.ts.map +1 -1
- package/dist/vm/operations/common.d.ts +2 -2
- package/dist/vm/operations/common.d.ts.map +1 -1
- package/dist/vm/operations/helpers.d.ts +7 -2
- package/dist/vm/operations/helpers.d.ts.map +1 -1
- package/dist/vm/operations/type-check.d.ts +1 -1
- package/dist/vm/operations/type-check.d.ts.map +1 -1
- package/dist/vm/types/function.d.ts +2 -2
- package/dist/vm/types/function.d.ts.map +1 -1
- package/dist/vm/types/wrapper.d.ts +0 -2
- package/dist/vm/types/wrapper.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/compiler/diagnostic.ts +56 -31
- package/src/compiler/emit/constants.ts +3 -0
- package/src/compiler/emit/index.ts +62 -5
- package/src/compiler/emit/sourcemap.ts +4 -3
- package/src/vm/lib/global/debug.ts +75 -61
- package/src/vm/lib/global/index.ts +1 -1
- package/src/vm/lib/global/{math-arr.ts → math/arr.ts} +2 -2
- package/src/vm/lib/global/{math-const.ts → math/const.ts} +1 -1
- package/src/vm/lib/global/math/gamma.ts +245 -0
- package/src/vm/lib/global/{math.ts → math/index.ts} +5 -5
- package/src/vm/lib/global/{math-unary.ts → math/unary.ts} +2 -2
- package/src/vm/lib/global/string.ts +1 -1
- package/src/vm/lib/helpers.ts +12 -10
- package/src/vm/lib/loader.ts +3 -13
- package/src/vm/operations/common.ts +2 -2
- package/src/vm/operations/helpers.ts +16 -3
- package/src/vm/operations/type-check.ts +1 -1
- package/src/vm/types/function.ts +19 -6
- package/src/vm/types/wrapper.ts +0 -4
- package/dist/chunk-DNM6YMFU.js.map +0 -6
- package/dist/chunk-GBWG7BQZ.js.map +0 -6
- package/dist/vm/lib/global/math-additional.d.ts +0 -2
- package/dist/vm/lib/global/math-additional.d.ts.map +0 -1
- package/dist/vm/lib/global/math-arr.d.ts +0 -7
- package/dist/vm/lib/global/math-arr.d.ts.map +0 -1
- package/dist/vm/lib/global/math-const.d.ts +0 -31
- package/dist/vm/lib/global/math-const.d.ts.map +0 -1
- package/dist/vm/lib/global/math-unary.d.ts +0 -28
- package/dist/vm/lib/global/math-unary.d.ts.map +0 -1
- package/dist/vm/lib/global/math.d.ts +0 -8
- package/dist/vm/lib/global/math.d.ts.map +0 -1
- package/src/vm/lib/global/math-additional.ts +0 -69
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-loss-of-precision */
|
|
2
|
-
import { isInteger, isNaN, NotNumber, PositiveInfinity } from '../../../helpers/utils.js';
|
|
3
|
-
import { expectNumber, VmLib } from '../helpers.js';
|
|
4
|
-
const { sqrt, pow, exp } = Math;
|
|
5
|
-
|
|
6
|
-
const GAMMA_G = 4.742_187_5;
|
|
7
|
-
|
|
8
|
-
const GAMMA_P = [
|
|
9
|
-
0.999_999_999_999_997_091_82, 57.156_235_665_862_923_517, -59.597_960_355_475_491_248, 14.136_097_974_741_747_174,
|
|
10
|
-
-0.491_913_816_097_620_199_78, 0.339_946_499_848_118_886_99e-4, 0.465_236_289_270_485_756_65e-4,
|
|
11
|
-
-0.983_744_753_048_795_646_77e-4, 0.158_088_703_224_912_488_84e-3, -0.210_264_441_724_104_883_19e-3,
|
|
12
|
-
0.217_439_618_115_212_643_2e-3, -0.164_318_106_536_763_890_22e-3, 0.844_182_239_838_527_432_93e-4,
|
|
13
|
-
-0.261_908_384_015_814_086_7e-4, 0.368_991_826_595_316_227_04e-5,
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
const SQRT_2_PI = sqrt(2 * Math.PI);
|
|
17
|
-
|
|
18
|
-
export const factorial = VmLib(
|
|
19
|
-
(x): number => {
|
|
20
|
-
let n = expectNumber('x', x);
|
|
21
|
-
if (isNaN(n) || n < 0) return NotNumber;
|
|
22
|
-
if (n >= 171) return PositiveInfinity; // will overflow
|
|
23
|
-
|
|
24
|
-
if (isInteger(n)) {
|
|
25
|
-
if (n === 0 || n === 1) return 1;
|
|
26
|
-
|
|
27
|
-
let r = 1;
|
|
28
|
-
for (let i = 2; i <= n; i++) {
|
|
29
|
-
r *= i;
|
|
30
|
-
}
|
|
31
|
-
return r;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (n > 85) {
|
|
35
|
-
// Extended Stirling Approx
|
|
36
|
-
n = n + 1;
|
|
37
|
-
const twoN = n * n;
|
|
38
|
-
const threeN = twoN * n;
|
|
39
|
-
const fourN = threeN * n;
|
|
40
|
-
const fiveN = fourN * n;
|
|
41
|
-
return (
|
|
42
|
-
sqrt((2 * Math.PI) / n) *
|
|
43
|
-
pow(n / Math.E, n) *
|
|
44
|
-
(1 +
|
|
45
|
-
1 / (12 * n) +
|
|
46
|
-
1 / (288 * twoN) -
|
|
47
|
-
139 / (51840 * threeN) -
|
|
48
|
-
571 / (2_488_320 * fourN) +
|
|
49
|
-
163_879 / (209_018_880 * fiveN) +
|
|
50
|
-
5_246_819 / (75_246_796_800 * fiveN * n))
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
let p = GAMMA_P[0]!;
|
|
55
|
-
for (let i = 1; i < GAMMA_P.length; ++i) {
|
|
56
|
-
p += GAMMA_P[i]! / (n + i);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const t = n + GAMMA_G + 0.5;
|
|
60
|
-
return SQRT_2_PI * pow(t, n + 0.5) * exp(-t) * p;
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
summary: '返回一个数的阶乘',
|
|
64
|
-
params: { x: '要计算阶乘的数值' },
|
|
65
|
-
paramsType: { x: 'number' },
|
|
66
|
-
returnsType: 'number',
|
|
67
|
-
examples: ['factorial(5) // 120'],
|
|
68
|
-
},
|
|
69
|
-
);
|