@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.
Files changed (75) hide show
  1. package/dist/{chunk-DNM6YMFU.js → chunk-CZOIPBED.js} +331 -205
  2. package/dist/chunk-CZOIPBED.js.map +6 -0
  3. package/dist/{chunk-GBWG7BQZ.js → chunk-UI6VQ263.js} +116 -42
  4. package/dist/chunk-UI6VQ263.js.map +6 -0
  5. package/dist/compiler/diagnostic.d.ts +4 -0
  6. package/dist/compiler/diagnostic.d.ts.map +1 -1
  7. package/dist/compiler/emit/constants.d.ts +3 -0
  8. package/dist/compiler/emit/constants.d.ts.map +1 -1
  9. package/dist/compiler/emit/index.d.ts +6 -1
  10. package/dist/compiler/emit/index.d.ts.map +1 -1
  11. package/dist/compiler/emit/sourcemap.d.ts +2 -1
  12. package/dist/compiler/emit/sourcemap.d.ts.map +1 -1
  13. package/dist/compiler/worker.js +1 -1
  14. package/dist/index.js +2 -2
  15. package/dist/subtle.js +6 -2
  16. package/dist/subtle.js.map +1 -1
  17. package/dist/vm/lib/global/debug.d.ts +11 -35
  18. package/dist/vm/lib/global/debug.d.ts.map +1 -1
  19. package/dist/vm/lib/global/index.d.ts +1 -1
  20. package/dist/vm/lib/global/index.d.ts.map +1 -1
  21. package/dist/vm/lib/global/math/arr.d.ts +7 -0
  22. package/dist/vm/lib/global/math/arr.d.ts.map +1 -0
  23. package/dist/vm/lib/global/math/const.d.ts +31 -0
  24. package/dist/vm/lib/global/math/const.d.ts.map +1 -0
  25. package/dist/vm/lib/global/math/gamma.d.ts +3 -0
  26. package/dist/vm/lib/global/math/gamma.d.ts.map +1 -0
  27. package/dist/vm/lib/global/math/index.d.ts +8 -0
  28. package/dist/vm/lib/global/math/index.d.ts.map +1 -0
  29. package/dist/vm/lib/global/math/unary.d.ts +28 -0
  30. package/dist/vm/lib/global/math/unary.d.ts.map +1 -0
  31. package/dist/vm/lib/helpers.d.ts.map +1 -1
  32. package/dist/vm/lib/loader.d.ts.map +1 -1
  33. package/dist/vm/operations/common.d.ts +2 -2
  34. package/dist/vm/operations/common.d.ts.map +1 -1
  35. package/dist/vm/operations/helpers.d.ts +7 -2
  36. package/dist/vm/operations/helpers.d.ts.map +1 -1
  37. package/dist/vm/operations/type-check.d.ts +1 -1
  38. package/dist/vm/operations/type-check.d.ts.map +1 -1
  39. package/dist/vm/types/function.d.ts +2 -2
  40. package/dist/vm/types/function.d.ts.map +1 -1
  41. package/dist/vm/types/wrapper.d.ts +0 -2
  42. package/dist/vm/types/wrapper.d.ts.map +1 -1
  43. package/package.json +5 -5
  44. package/src/compiler/diagnostic.ts +56 -31
  45. package/src/compiler/emit/constants.ts +3 -0
  46. package/src/compiler/emit/index.ts +62 -5
  47. package/src/compiler/emit/sourcemap.ts +4 -3
  48. package/src/vm/lib/global/debug.ts +75 -61
  49. package/src/vm/lib/global/index.ts +1 -1
  50. package/src/vm/lib/global/{math-arr.ts → math/arr.ts} +2 -2
  51. package/src/vm/lib/global/{math-const.ts → math/const.ts} +1 -1
  52. package/src/vm/lib/global/math/gamma.ts +245 -0
  53. package/src/vm/lib/global/{math.ts → math/index.ts} +5 -5
  54. package/src/vm/lib/global/{math-unary.ts → math/unary.ts} +2 -2
  55. package/src/vm/lib/global/string.ts +1 -1
  56. package/src/vm/lib/helpers.ts +12 -10
  57. package/src/vm/lib/loader.ts +3 -13
  58. package/src/vm/operations/common.ts +2 -2
  59. package/src/vm/operations/helpers.ts +16 -3
  60. package/src/vm/operations/type-check.ts +1 -1
  61. package/src/vm/types/function.ts +19 -6
  62. package/src/vm/types/wrapper.ts +0 -4
  63. package/dist/chunk-DNM6YMFU.js.map +0 -6
  64. package/dist/chunk-GBWG7BQZ.js.map +0 -6
  65. package/dist/vm/lib/global/math-additional.d.ts +0 -2
  66. package/dist/vm/lib/global/math-additional.d.ts.map +0 -1
  67. package/dist/vm/lib/global/math-arr.d.ts +0 -7
  68. package/dist/vm/lib/global/math-arr.d.ts.map +0 -1
  69. package/dist/vm/lib/global/math-const.d.ts +0 -31
  70. package/dist/vm/lib/global/math-const.d.ts.map +0 -1
  71. package/dist/vm/lib/global/math-unary.d.ts +0 -28
  72. package/dist/vm/lib/global/math-unary.d.ts.map +0 -1
  73. package/dist/vm/lib/global/math.d.ts +0 -8
  74. package/dist/vm/lib/global/math.d.ts.map +0 -1
  75. 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
- );