@hot-updater/console 0.36.7 → 1.0.0-rc.1
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/.output/nitro.json +1 -1
- package/.output/public/assets/BundleIdDisplay-D4ErdU5_.js +1 -0
- package/.output/public/assets/InsightsCapabilityContext-B42VqvP6.js +1 -0
- package/.output/public/assets/api-keys-api-DGVTTvTJ.js +1 -0
- package/.output/public/assets/api-keys-z16OZIP4.js +1 -0
- package/.output/public/assets/badge-Br_KDO0J.js +1 -0
- package/.output/public/assets/card-DzuEXvyJ.js +1 -0
- package/.output/public/assets/chart-no-axes-combined-FaYMGmQS.js +1 -0
- package/.output/public/assets/createServerFn-gM2-LFBy.js +3 -0
- package/.output/public/assets/dialog-BeAENgez.js +1 -0
- package/.output/public/assets/dist-Bssh_cv0.js +1 -0
- package/.output/public/assets/field-Buq148-A.js +1 -0
- package/.output/public/assets/index-uOpQAIC4.js +10 -0
- package/.output/public/assets/input-group-B3p5UpyW.js +1 -0
- package/.output/public/assets/insights-DJTr7Ozn.js +1 -0
- package/.output/public/assets/insights-api-DVMOoRMS.js +1 -0
- package/.output/public/assets/installations-BY64iIAK.js +2 -0
- package/.output/public/assets/installations-D5v9i3AL.js +1 -0
- package/.output/public/assets/lazyRouteComponent-DKYu5cZJ.js +1 -0
- package/.output/public/assets/preload-helper-CQ36nxok.js +1 -0
- package/.output/public/assets/refresh-cw-BkbfZ62O.js +1 -0
- package/.output/public/assets/routes-BuoI5-Cr.js +2 -0
- package/.output/public/assets/routes-C8fvgETO.js +1 -0
- package/.output/public/assets/search-qsIDvS2I.js +1 -0
- package/.output/public/assets/shield-check-DE_hVuHu.js +1 -0
- package/.output/public/assets/signing-mJD88Y4C.js +1 -0
- package/.output/public/assets/styles-BZIG7t42.css +2 -0
- package/.output/public/assets/table-RamFEclP.js +1 -0
- package/.output/public/assets/useCompositeListItem-ChzDqdpc.js +42 -0
- package/.output/public/assets/useMutation-JsGVjQMY.js +1 -0
- package/.output/public/assets/useOpenInteractionType-Dwfy-SpA.js +1 -0
- package/.output/server/__23tanstack-start-server-fn-resolver-Dftxlm2E.mjs +146 -0
- package/.output/server/_libs/@base-ui/react+[...].mjs +16124 -0
- package/.output/server/_libs/@reduxjs/toolkit+[...].mjs +1554 -0
- package/.output/server/_libs/@tanstack/react-router+[...].mjs +41 -10
- package/.output/server/_libs/@tanstack/react-router-ssr-query+[...].mjs +132 -0
- package/.output/server/_libs/d3-array.mjs +231 -0
- package/.output/server/_libs/d3-color.mjs +330 -0
- package/.output/server/_libs/d3-format.mjs +252 -0
- package/.output/server/_libs/d3-interpolate.mjs +207 -0
- package/.output/server/_libs/d3-path.mjs +77 -0
- package/.output/server/_libs/d3-scale+[...].mjs +1907 -0
- package/.output/server/_libs/d3-shape.mjs +818 -0
- package/.output/server/_libs/decimal.js-light.mjs +884 -0
- package/.output/server/_libs/es-toolkit.mjs +1134 -0
- package/.output/server/_libs/eventemitter3.mjs +236 -0
- package/.output/server/_libs/immer.mjs +532 -0
- package/.output/server/_libs/lucide-react.mjs +141 -13
- package/.output/server/_libs/next-themes.mjs +2 -2
- package/.output/server/_libs/react-redux+[...].mjs +205 -0
- package/.output/server/_libs/recharts+[...].mjs +14117 -0
- package/.output/server/_libs/sonner.mjs +2 -2
- package/.output/server/_libs/tanstack__query-core.mjs +114 -1
- package/.output/server/_libs/tanstack__react-query.mjs +3 -4
- package/.output/server/_runtime.mjs +10 -1
- package/.output/server/_ssr/BundleActivityChart-CWcdPuUn.mjs +288 -0
- package/.output/server/_ssr/BundleIdDisplay-BEvB3MvA.mjs +13 -0
- package/.output/server/_ssr/InsightsCapabilityContext-Cx8fjm2s.mjs +15 -0
- package/.output/server/_ssr/api-keys-CpBqHpuC.mjs +300 -0
- package/.output/server/_ssr/api-keys-api-Czkp57UV.mjs +60 -0
- package/.output/server/_ssr/api-keys-rpc-BTtMDSoR.mjs +136 -0
- package/.output/server/_ssr/api-rpc-BEX8ISai.mjs +1468 -0
- package/.output/server/_ssr/auth-BF8mbAgF.mjs +21 -0
- package/.output/server/_ssr/auth-rpc-BFMEC-TT.mjs +24 -0
- package/.output/server/_ssr/auth.server-DW71WzsD.mjs +47 -0
- package/.output/server/_ssr/badge-CpWXQwyF.mjs +26 -0
- package/.output/server/_ssr/bundle-signing-rpc-BbCFUQSu.mjs +16 -0
- package/.output/server/_ssr/bundle-signing.server-C4NW5mWx.mjs +12 -0
- package/.output/server/_ssr/card-Bsc8mRis.mjs +86 -0
- package/.output/server/_ssr/config-Dv8qLDZ0.mjs +13 -0
- package/.output/server/_ssr/config.server-DQYEr_5X.mjs +361 -0
- package/.output/server/_ssr/{createServerFn-DzU0k62V.mjs → createServerFn-B2hcXoPM.mjs} +1 -1
- package/.output/server/_ssr/createServerRpc-DB29C_5p.mjs +12 -0
- package/.output/server/_ssr/{sidebar-Cv_H0_Jv.mjs → createSsrRpc-DhfrxEjg.mjs} +68 -50
- package/.output/server/_ssr/databaseRows-QlCYLi0H.mjs +166 -0
- package/.output/server/_ssr/deleteBundle-Cu_XOMt0.mjs +66 -0
- package/.output/server/_ssr/dialog-C0vKUp8R.mjs +170 -0
- package/.output/server/_ssr/dist-BVSLTpoP.mjs +250 -0
- package/.output/server/_ssr/downloadBundle-CNnYxYO2.mjs +24 -0
- package/.output/server/_ssr/{empty-plugin-adapters-B4HCzgmM.mjs → empty-plugin-adapters-B5QvGpEl.mjs} +1 -1
- package/.output/server/_ssr/field-DASCh-5d.mjs +74 -0
- package/.output/server/_ssr/{getBundleChildren-CVtSiH5t.mjs → getBundleChildren-BcRMFoDF.mjs} +10 -18
- package/.output/server/_ssr/input-group-etIsBUqv.mjs +288 -0
- package/.output/server/_ssr/insights-api-C1F7UreR.mjs +71 -0
- package/.output/server/_ssr/insights-input-9fEJF-ZG.mjs +96 -0
- package/.output/server/_ssr/insights-rpc-C-8R6kED.mjs +155 -0
- package/.output/server/_ssr/insights-ygT_aIfo.mjs +858 -0
- package/.output/server/_ssr/installations-DqRT1QTd.mjs +535 -0
- package/.output/server/_ssr/installations-K8TCYTYh.mjs +19 -0
- package/.output/server/_ssr/router-BxBEvtF1.mjs +513 -0
- package/.output/server/_ssr/routes-BC7rn-tf.mjs +37 -0
- package/.output/server/_ssr/routes-CM5KAwpB.mjs +2285 -0
- package/.output/server/_ssr/runtime.server-la7TRAH_.mjs +527 -0
- package/.output/server/_ssr/server-CpzW--lT.mjs +7468 -0
- package/.output/server/_ssr/signing-jk4HANnl.mjs +134 -0
- package/.output/server/_ssr/ssr.mjs +4 -5740
- package/.output/server/_ssr/start-DpViQGnt.mjs +4 -0
- package/.output/server/_ssr/table-CU58HeI7.mjs +53 -0
- package/.output/server/_ssr/uuidv7-CaKuKXrV.mjs +31 -0
- package/.output/server/_tanstack-start-manifest_v-Mz9MmSlD.mjs +103 -0
- package/.output/server/index.mjs +229 -47
- package/README.md +29 -8
- package/lib/index.d.mts +35 -0
- package/lib/index.mjs +4 -0
- package/lib/vite-internal.mjs +127 -0
- package/lib/vite.d.mts +10 -0
- package/lib/vite.mjs +5 -0
- package/package.json +51 -29
- package/public/apple-touch-icon.png +0 -0
- package/public/favicon-16x16.png +0 -0
- package/public/favicon-32x32.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/logo.svg +1 -0
- package/public/manifest.json +30 -0
- package/public/robots.txt +3 -0
- package/src/components/AppSidebar.tsx +159 -0
- package/src/components/BundleIdDisplay.tsx +18 -0
- package/src/components/ChannelBadge.tsx +31 -0
- package/src/components/ConsoleAccessPage.tsx +122 -0
- package/src/components/EnabledStatusIcon.tsx +54 -0
- package/src/components/HashValueDisplay.tsx +85 -0
- package/src/components/HotUpdaterLogo.tsx +30 -0
- package/src/components/NotFoundPage.tsx +33 -0
- package/src/components/PlatformIcon.tsx +39 -0
- package/src/components/RolloutPercentageBadge.tsx +28 -0
- package/src/components/ThemeProvider.tsx +116 -0
- package/src/components/TimestampDisplay.tsx +41 -0
- package/src/components/features/api-keys/ApiKeysPage.tsx +377 -0
- package/src/components/features/bundles/BundleActivityChart.tsx +193 -0
- package/src/components/features/bundles/BundleChildrenPanel.tsx +201 -0
- package/src/components/features/bundles/BundleInsightsSummary.tsx +123 -0
- package/src/components/features/bundles/BundleMetadata.tsx +136 -0
- package/src/components/features/bundles/RolloutCohortsDialog.tsx +201 -0
- package/src/components/features/channels/ChannelManagementDialog.tsx +228 -0
- package/src/components/features/insights/ActivityChart.tsx +150 -0
- package/src/components/features/insights/BundleDistribution.tsx +133 -0
- package/src/components/features/insights/BundleSelector.tsx +114 -0
- package/src/components/features/insights/InsightsCapabilityContext.tsx +24 -0
- package/src/components/features/insights/InsightsControls.tsx +115 -0
- package/src/components/features/insights/InsightsErrorAlert.tsx +21 -0
- package/src/components/features/insights/InsightsOverview.tsx +208 -0
- package/src/components/features/insights/InstallationHistoryCard.tsx +248 -0
- package/src/components/features/insights/InstallationMatchesCard.tsx +132 -0
- package/src/components/features/insights/InstallationPageHeader.tsx +138 -0
- package/src/components/features/insights/InstallationPagination.tsx +48 -0
- package/src/components/features/insights/InstallationSearch.tsx +230 -0
- package/src/components/features/insights/UpdateOutcomes.tsx +147 -0
- package/src/components/features/releases/ReleaseEditorSheet.tsx +879 -0
- package/src/components/features/releases/ReleaseStateBadge.tsx +20 -0
- package/src/components/features/signing/BundleSigningPage.tsx +139 -0
- package/src/components/ui/alert-dialog.tsx +185 -0
- package/src/components/ui/alert.tsx +76 -0
- package/src/components/ui/badge.tsx +49 -0
- package/src/components/ui/button.tsx +58 -0
- package/src/components/ui/card.tsx +89 -0
- package/src/components/ui/chart.tsx +371 -0
- package/src/components/ui/combobox.tsx +303 -0
- package/src/components/ui/dialog.tsx +156 -0
- package/src/components/ui/dropdown-menu.tsx +270 -0
- package/src/components/ui/field.tsx +235 -0
- package/src/components/ui/input-group.tsx +147 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/label.tsx +25 -0
- package/src/components/ui/progress.tsx +84 -0
- package/src/components/ui/select.tsx +205 -0
- package/src/components/ui/separator.tsx +23 -0
- package/src/components/ui/sheet.tsx +132 -0
- package/src/components/ui/sidebar.tsx +779 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/slider.tsx +56 -0
- package/src/components/ui/sonner.tsx +45 -0
- package/src/components/ui/switch.tsx +25 -0
- package/src/components/ui/table.tsx +114 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/ui/toggle-group.tsx +89 -0
- package/src/components/ui/toggle.tsx +43 -0
- package/src/components/ui/tooltip.tsx +66 -0
- package/src/hooks/use-mobile.ts +30 -0
- package/src/index.ts +47 -0
- package/src/lib/api-keys-api.ts +69 -0
- package/src/lib/api-keys-rpc.ts +87 -0
- package/src/lib/api-rpc.ts +478 -0
- package/src/lib/api.ts +444 -0
- package/src/lib/auth-rpc.ts +16 -0
- package/src/lib/bundle-signing-api.ts +14 -0
- package/src/lib/bundle-signing-rpc.ts +16 -0
- package/src/lib/constants.ts +1 -0
- package/src/lib/git.ts +51 -0
- package/src/lib/insights-api.ts +144 -0
- package/src/lib/insights-error.ts +19 -0
- package/src/lib/insights-input.ts +187 -0
- package/src/lib/insights-overview.ts +170 -0
- package/src/lib/insights-rpc.ts +218 -0
- package/src/lib/server/auth.server.ts +43 -0
- package/src/lib/server/bundle-signing.server.ts +23 -0
- package/src/lib/server/config.server.ts +109 -0
- package/src/lib/server/console-runtime.server.ts +61 -0
- package/src/lib/server/deleteBundle.ts +145 -0
- package/src/lib/server/downloadBundle.ts +46 -0
- package/src/lib/server/getBundleChildren.ts +130 -0
- package/src/lib/server/listReleases.ts +61 -0
- package/src/lib/server/releaseActivity.ts +27 -0
- package/src/lib/server/releaseReachability.ts +95 -0
- package/src/lib/server/runtime.server.ts +172 -0
- package/src/lib/utils.ts +9 -0
- package/src/logo.svg +1 -0
- package/src/routeTree.gen.ts +199 -0
- package/src/router.tsx +21 -0
- package/src/routes/-installations-search.ts +19 -0
- package/src/routes/-releases-search.ts +74 -0
- package/src/routes/__root.tsx +174 -0
- package/src/routes/api/auth/$.ts +19 -0
- package/src/routes/api/bundles/$bundleId/download.ts +17 -0
- package/src/routes/api-keys.tsx +37 -0
- package/src/routes/index.tsx +982 -0
- package/src/routes/insights.tsx +139 -0
- package/src/routes/installations.tsx +194 -0
- package/src/routes/signing.tsx +37 -0
- package/src/styles.css +152 -0
- package/src/virtual-modules.d.ts +21 -0
- package/src/vite-env.d.ts +1 -0
- package/src/vite-internal.ts +195 -0
- package/src/vite.ts +12 -0
- package/.output/public/assets/dist-DJX53faP.js +0 -3
- package/.output/public/assets/index-Iylis5kY.js +0 -10
- package/.output/public/assets/routes-HT21hs0C.js +0 -54
- package/.output/public/assets/styles-C0Re4quB.css +0 -2
- package/.output/server/__23tanstack-start-server-fn-resolver-CgwgZ0-i.mjs +0 -66
- package/.output/server/_libs/@floating-ui/core+[...].mjs +0 -698
- package/.output/server/_libs/@floating-ui/dom+[...].mjs +0 -644
- package/.output/server/_libs/@floating-ui/react-dom+[...].mjs +0 -839
- package/.output/server/_libs/@radix-ui/react-alert-dialog+[...].mjs +0 -2138
- package/.output/server/_libs/@radix-ui/react-popper+[...].mjs +0 -308
- package/.output/server/_libs/@radix-ui/react-select+[...].mjs +0 -1038
- package/.output/server/_libs/@tanstack/devtools-event-client+[...].mjs +0 -196
- package/.output/server/_libs/@tanstack/form-core+[...].mjs +0 -3228
- package/.output/server/_libs/@tanstack/react-form+[...].mjs +0 -430
- package/.output/server/_libs/@tanstack/react-table+[...].mjs +0 -2382
- package/.output/server/_libs/radix-ui__number.mjs +0 -6
- package/.output/server/_libs/radix-ui__primitive.mjs +0 -9
- package/.output/server/_libs/radix-ui__react-arrow.mjs +0 -23
- package/.output/server/_libs/radix-ui__react-collection.mjs +0 -78
- package/.output/server/_libs/radix-ui__react-direction.mjs +0 -13
- package/.output/server/_libs/radix-ui__react-label.mjs +0 -22
- package/.output/server/_libs/radix-ui__react-separator.mjs +0 -30
- package/.output/server/_libs/radix-ui__react-slider.mjs +0 -510
- package/.output/server/_libs/radix-ui__react-switch.mjs +0 -157
- package/.output/server/_libs/radix-ui__react-tooltip.mjs +0 -493
- package/.output/server/_ssr/api-rpc-BIbDUKSz.mjs +0 -292
- package/.output/server/_ssr/config.server-BSS366KT.mjs +0 -41
- package/.output/server/_ssr/deleteBundle-BgbZTtpW.mjs +0 -141
- package/.output/server/_ssr/dist-KboydRVk.mjs +0 -120
- package/.output/server/_ssr/router-C3hqEy3k.mjs +0 -307
- package/.output/server/_ssr/routes-B0lQvvlC.mjs +0 -3048
- package/.output/server/_ssr/start-02sLteYG.mjs +0 -4
- package/.output/server/_ssr/storageProfile-FVkjPoGb.mjs +0 -9
- package/.output/server/_tanstack-start-manifest_v-Bpx52WOU.mjs +0 -20
- package/.output/server/node_modules/tslib/modules/index.js +0 -70
- package/.output/server/node_modules/tslib/modules/package.json +0 -3
- package/.output/server/node_modules/tslib/package.json +0 -47
- package/.output/server/node_modules/tslib/tslib.js +0 -484
- package/.output/server/package.json +0 -9
|
@@ -0,0 +1,884 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/decimal.js-light@2.5.1/node_modules/decimal.js-light/decimal.mjs
|
|
2
|
+
var MAX_DIGITS = 1e9, defaults = {
|
|
3
|
+
precision: 20,
|
|
4
|
+
rounding: 4,
|
|
5
|
+
toExpNeg: -7,
|
|
6
|
+
toExpPos: 21,
|
|
7
|
+
LN10: "2.302585092994045684017991454684364207601101488628772976033327900967572609677352480235997205089598298341967784042286"
|
|
8
|
+
}, Decimal, external = true, decimalError = "[DecimalError] ", invalidArgument = decimalError + "Invalid argument: ", exponentOutOfRange = decimalError + "Exponent out of range: ", mathfloor = Math.floor, mathpow = Math.pow, isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i, ONE, BASE = 1e7, LOG_BASE = 7, MAX_SAFE_INTEGER = 9007199254740991, MAX_E = mathfloor(MAX_SAFE_INTEGER / LOG_BASE), P = {};
|
|
9
|
+
P.absoluteValue = P.abs = function() {
|
|
10
|
+
var x = new this.constructor(this);
|
|
11
|
+
if (x.s) x.s = 1;
|
|
12
|
+
return x;
|
|
13
|
+
};
|
|
14
|
+
P.comparedTo = P.cmp = function(y) {
|
|
15
|
+
var i, j, xdL, ydL, x = this;
|
|
16
|
+
y = new x.constructor(y);
|
|
17
|
+
if (x.s !== y.s) return x.s || -y.s;
|
|
18
|
+
if (x.e !== y.e) return x.e > y.e ^ x.s < 0 ? 1 : -1;
|
|
19
|
+
xdL = x.d.length;
|
|
20
|
+
ydL = y.d.length;
|
|
21
|
+
for (i = 0, j = xdL < ydL ? xdL : ydL; i < j; ++i) if (x.d[i] !== y.d[i]) return x.d[i] > y.d[i] ^ x.s < 0 ? 1 : -1;
|
|
22
|
+
return xdL === ydL ? 0 : xdL > ydL ^ x.s < 0 ? 1 : -1;
|
|
23
|
+
};
|
|
24
|
+
P.decimalPlaces = P.dp = function() {
|
|
25
|
+
var x = this, w = x.d.length - 1, dp = (w - x.e) * LOG_BASE;
|
|
26
|
+
w = x.d[w];
|
|
27
|
+
if (w) for (; w % 10 == 0; w /= 10) dp--;
|
|
28
|
+
return dp < 0 ? 0 : dp;
|
|
29
|
+
};
|
|
30
|
+
P.dividedBy = P.div = function(y) {
|
|
31
|
+
return divide(this, new this.constructor(y));
|
|
32
|
+
};
|
|
33
|
+
P.dividedToIntegerBy = P.idiv = function(y) {
|
|
34
|
+
var x = this, Ctor = x.constructor;
|
|
35
|
+
return round(divide(x, new Ctor(y), 0, 1), Ctor.precision);
|
|
36
|
+
};
|
|
37
|
+
P.equals = P.eq = function(y) {
|
|
38
|
+
return !this.cmp(y);
|
|
39
|
+
};
|
|
40
|
+
P.exponent = function() {
|
|
41
|
+
return getBase10Exponent(this);
|
|
42
|
+
};
|
|
43
|
+
P.greaterThan = P.gt = function(y) {
|
|
44
|
+
return this.cmp(y) > 0;
|
|
45
|
+
};
|
|
46
|
+
P.greaterThanOrEqualTo = P.gte = function(y) {
|
|
47
|
+
return this.cmp(y) >= 0;
|
|
48
|
+
};
|
|
49
|
+
P.isInteger = P.isint = function() {
|
|
50
|
+
return this.e > this.d.length - 2;
|
|
51
|
+
};
|
|
52
|
+
P.isNegative = P.isneg = function() {
|
|
53
|
+
return this.s < 0;
|
|
54
|
+
};
|
|
55
|
+
P.isPositive = P.ispos = function() {
|
|
56
|
+
return this.s > 0;
|
|
57
|
+
};
|
|
58
|
+
P.isZero = function() {
|
|
59
|
+
return this.s === 0;
|
|
60
|
+
};
|
|
61
|
+
P.lessThan = P.lt = function(y) {
|
|
62
|
+
return this.cmp(y) < 0;
|
|
63
|
+
};
|
|
64
|
+
P.lessThanOrEqualTo = P.lte = function(y) {
|
|
65
|
+
return this.cmp(y) < 1;
|
|
66
|
+
};
|
|
67
|
+
P.logarithm = P.log = function(base) {
|
|
68
|
+
var r, x = this, Ctor = x.constructor, pr = Ctor.precision, wpr = pr + 5;
|
|
69
|
+
if (base === void 0) base = new Ctor(10);
|
|
70
|
+
else {
|
|
71
|
+
base = new Ctor(base);
|
|
72
|
+
if (base.s < 1 || base.eq(ONE)) throw Error(decimalError + "NaN");
|
|
73
|
+
}
|
|
74
|
+
if (x.s < 1) throw Error(decimalError + (x.s ? "NaN" : "-Infinity"));
|
|
75
|
+
if (x.eq(ONE)) return new Ctor(0);
|
|
76
|
+
external = false;
|
|
77
|
+
r = divide(ln(x, wpr), ln(base, wpr), wpr);
|
|
78
|
+
external = true;
|
|
79
|
+
return round(r, pr);
|
|
80
|
+
};
|
|
81
|
+
P.minus = P.sub = function(y) {
|
|
82
|
+
var x = this;
|
|
83
|
+
y = new x.constructor(y);
|
|
84
|
+
return x.s == y.s ? subtract(x, y) : add(x, (y.s = -y.s, y));
|
|
85
|
+
};
|
|
86
|
+
P.modulo = P.mod = function(y) {
|
|
87
|
+
var q, x = this, Ctor = x.constructor, pr = Ctor.precision;
|
|
88
|
+
y = new Ctor(y);
|
|
89
|
+
if (!y.s) throw Error(decimalError + "NaN");
|
|
90
|
+
if (!x.s) return round(new Ctor(x), pr);
|
|
91
|
+
external = false;
|
|
92
|
+
q = divide(x, y, 0, 1).times(y);
|
|
93
|
+
external = true;
|
|
94
|
+
return x.minus(q);
|
|
95
|
+
};
|
|
96
|
+
P.naturalExponential = P.exp = function() {
|
|
97
|
+
return exp(this);
|
|
98
|
+
};
|
|
99
|
+
P.naturalLogarithm = P.ln = function() {
|
|
100
|
+
return ln(this);
|
|
101
|
+
};
|
|
102
|
+
P.negated = P.neg = function() {
|
|
103
|
+
var x = new this.constructor(this);
|
|
104
|
+
x.s = -x.s || 0;
|
|
105
|
+
return x;
|
|
106
|
+
};
|
|
107
|
+
P.plus = P.add = function(y) {
|
|
108
|
+
var x = this;
|
|
109
|
+
y = new x.constructor(y);
|
|
110
|
+
return x.s == y.s ? add(x, y) : subtract(x, (y.s = -y.s, y));
|
|
111
|
+
};
|
|
112
|
+
P.precision = P.sd = function(z) {
|
|
113
|
+
var e, sd, w, x = this;
|
|
114
|
+
if (z !== void 0 && z !== !!z && z !== 1 && z !== 0) throw Error(invalidArgument + z);
|
|
115
|
+
e = getBase10Exponent(x) + 1;
|
|
116
|
+
w = x.d.length - 1;
|
|
117
|
+
sd = w * LOG_BASE + 1;
|
|
118
|
+
w = x.d[w];
|
|
119
|
+
if (w) {
|
|
120
|
+
for (; w % 10 == 0; w /= 10) sd--;
|
|
121
|
+
for (w = x.d[0]; w >= 10; w /= 10) sd++;
|
|
122
|
+
}
|
|
123
|
+
return z && e > sd ? e : sd;
|
|
124
|
+
};
|
|
125
|
+
P.squareRoot = P.sqrt = function() {
|
|
126
|
+
var e, n, pr, r, s, t, wpr, x = this, Ctor = x.constructor;
|
|
127
|
+
if (x.s < 1) {
|
|
128
|
+
if (!x.s) return new Ctor(0);
|
|
129
|
+
throw Error(decimalError + "NaN");
|
|
130
|
+
}
|
|
131
|
+
e = getBase10Exponent(x);
|
|
132
|
+
external = false;
|
|
133
|
+
s = Math.sqrt(+x);
|
|
134
|
+
if (s == 0 || s == Infinity) {
|
|
135
|
+
n = digitsToString(x.d);
|
|
136
|
+
if ((n.length + e) % 2 == 0) n += "0";
|
|
137
|
+
s = Math.sqrt(n);
|
|
138
|
+
e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
139
|
+
if (s == Infinity) n = "5e" + e;
|
|
140
|
+
else {
|
|
141
|
+
n = s.toExponential();
|
|
142
|
+
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
143
|
+
}
|
|
144
|
+
r = new Ctor(n);
|
|
145
|
+
} else r = new Ctor(s.toString());
|
|
146
|
+
pr = Ctor.precision;
|
|
147
|
+
s = wpr = pr + 3;
|
|
148
|
+
for (;;) {
|
|
149
|
+
t = r;
|
|
150
|
+
r = t.plus(divide(x, t, wpr + 2)).times(.5);
|
|
151
|
+
if (digitsToString(t.d).slice(0, wpr) === (n = digitsToString(r.d)).slice(0, wpr)) {
|
|
152
|
+
n = n.slice(wpr - 3, wpr + 1);
|
|
153
|
+
if (s == wpr && n == "4999") {
|
|
154
|
+
round(t, pr + 1, 0);
|
|
155
|
+
if (t.times(t).eq(x)) {
|
|
156
|
+
r = t;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
} else if (n != "9999") break;
|
|
160
|
+
wpr += 4;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
external = true;
|
|
164
|
+
return round(r, pr);
|
|
165
|
+
};
|
|
166
|
+
P.times = P.mul = function(y) {
|
|
167
|
+
var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
|
|
168
|
+
if (!x.s || !y.s) return new Ctor(0);
|
|
169
|
+
y.s *= x.s;
|
|
170
|
+
e = x.e + y.e;
|
|
171
|
+
xdL = xd.length;
|
|
172
|
+
ydL = yd.length;
|
|
173
|
+
if (xdL < ydL) {
|
|
174
|
+
r = xd;
|
|
175
|
+
xd = yd;
|
|
176
|
+
yd = r;
|
|
177
|
+
rL = xdL;
|
|
178
|
+
xdL = ydL;
|
|
179
|
+
ydL = rL;
|
|
180
|
+
}
|
|
181
|
+
r = [];
|
|
182
|
+
rL = xdL + ydL;
|
|
183
|
+
for (i = rL; i--;) r.push(0);
|
|
184
|
+
for (i = ydL; --i >= 0;) {
|
|
185
|
+
carry = 0;
|
|
186
|
+
for (k = xdL + i; k > i;) {
|
|
187
|
+
t = r[k] + yd[i] * xd[k - i - 1] + carry;
|
|
188
|
+
r[k--] = t % BASE | 0;
|
|
189
|
+
carry = t / BASE | 0;
|
|
190
|
+
}
|
|
191
|
+
r[k] = (r[k] + carry) % BASE | 0;
|
|
192
|
+
}
|
|
193
|
+
for (; !r[--rL];) r.pop();
|
|
194
|
+
if (carry) ++e;
|
|
195
|
+
else r.shift();
|
|
196
|
+
y.d = r;
|
|
197
|
+
y.e = e;
|
|
198
|
+
return external ? round(y, Ctor.precision) : y;
|
|
199
|
+
};
|
|
200
|
+
P.toDecimalPlaces = P.todp = function(dp, rm) {
|
|
201
|
+
var x = this, Ctor = x.constructor;
|
|
202
|
+
x = new Ctor(x);
|
|
203
|
+
if (dp === void 0) return x;
|
|
204
|
+
checkInt32(dp, 0, MAX_DIGITS);
|
|
205
|
+
if (rm === void 0) rm = Ctor.rounding;
|
|
206
|
+
else checkInt32(rm, 0, 8);
|
|
207
|
+
return round(x, dp + getBase10Exponent(x) + 1, rm);
|
|
208
|
+
};
|
|
209
|
+
P.toExponential = function(dp, rm) {
|
|
210
|
+
var str, x = this, Ctor = x.constructor;
|
|
211
|
+
if (dp === void 0) str = toString(x, true);
|
|
212
|
+
else {
|
|
213
|
+
checkInt32(dp, 0, MAX_DIGITS);
|
|
214
|
+
if (rm === void 0) rm = Ctor.rounding;
|
|
215
|
+
else checkInt32(rm, 0, 8);
|
|
216
|
+
x = round(new Ctor(x), dp + 1, rm);
|
|
217
|
+
str = toString(x, true, dp + 1);
|
|
218
|
+
}
|
|
219
|
+
return str;
|
|
220
|
+
};
|
|
221
|
+
P.toFixed = function(dp, rm) {
|
|
222
|
+
var str, y, x = this, Ctor = x.constructor;
|
|
223
|
+
if (dp === void 0) return toString(x);
|
|
224
|
+
checkInt32(dp, 0, MAX_DIGITS);
|
|
225
|
+
if (rm === void 0) rm = Ctor.rounding;
|
|
226
|
+
else checkInt32(rm, 0, 8);
|
|
227
|
+
y = round(new Ctor(x), dp + getBase10Exponent(x) + 1, rm);
|
|
228
|
+
str = toString(y.abs(), false, dp + getBase10Exponent(y) + 1);
|
|
229
|
+
return x.isneg() && !x.isZero() ? "-" + str : str;
|
|
230
|
+
};
|
|
231
|
+
P.toInteger = P.toint = function() {
|
|
232
|
+
var x = this, Ctor = x.constructor;
|
|
233
|
+
return round(new Ctor(x), getBase10Exponent(x) + 1, Ctor.rounding);
|
|
234
|
+
};
|
|
235
|
+
P.toNumber = function() {
|
|
236
|
+
return +this;
|
|
237
|
+
};
|
|
238
|
+
P.toPower = P.pow = function(y) {
|
|
239
|
+
var e, k, pr, r, sign, yIsInt, x = this, Ctor = x.constructor, guard = 12, yn = +(y = new Ctor(y));
|
|
240
|
+
if (!y.s) return new Ctor(ONE);
|
|
241
|
+
x = new Ctor(x);
|
|
242
|
+
if (!x.s) {
|
|
243
|
+
if (y.s < 1) throw Error(decimalError + "Infinity");
|
|
244
|
+
return x;
|
|
245
|
+
}
|
|
246
|
+
if (x.eq(ONE)) return x;
|
|
247
|
+
pr = Ctor.precision;
|
|
248
|
+
if (y.eq(ONE)) return round(x, pr);
|
|
249
|
+
e = y.e;
|
|
250
|
+
k = y.d.length - 1;
|
|
251
|
+
yIsInt = e >= k;
|
|
252
|
+
sign = x.s;
|
|
253
|
+
if (!yIsInt) {
|
|
254
|
+
if (sign < 0) throw Error(decimalError + "NaN");
|
|
255
|
+
} else if ((k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
|
|
256
|
+
r = new Ctor(ONE);
|
|
257
|
+
e = Math.ceil(pr / LOG_BASE + 4);
|
|
258
|
+
external = false;
|
|
259
|
+
for (;;) {
|
|
260
|
+
if (k % 2) {
|
|
261
|
+
r = r.times(x);
|
|
262
|
+
truncate(r.d, e);
|
|
263
|
+
}
|
|
264
|
+
k = mathfloor(k / 2);
|
|
265
|
+
if (k === 0) break;
|
|
266
|
+
x = x.times(x);
|
|
267
|
+
truncate(x.d, e);
|
|
268
|
+
}
|
|
269
|
+
external = true;
|
|
270
|
+
return y.s < 0 ? new Ctor(ONE).div(r) : round(r, pr);
|
|
271
|
+
}
|
|
272
|
+
sign = sign < 0 && y.d[Math.max(e, k)] & 1 ? -1 : 1;
|
|
273
|
+
x.s = 1;
|
|
274
|
+
external = false;
|
|
275
|
+
r = y.times(ln(x, pr + guard));
|
|
276
|
+
external = true;
|
|
277
|
+
r = exp(r);
|
|
278
|
+
r.s = sign;
|
|
279
|
+
return r;
|
|
280
|
+
};
|
|
281
|
+
P.toPrecision = function(sd, rm) {
|
|
282
|
+
var e, str, x = this, Ctor = x.constructor;
|
|
283
|
+
if (sd === void 0) {
|
|
284
|
+
e = getBase10Exponent(x);
|
|
285
|
+
str = toString(x, e <= Ctor.toExpNeg || e >= Ctor.toExpPos);
|
|
286
|
+
} else {
|
|
287
|
+
checkInt32(sd, 1, MAX_DIGITS);
|
|
288
|
+
if (rm === void 0) rm = Ctor.rounding;
|
|
289
|
+
else checkInt32(rm, 0, 8);
|
|
290
|
+
x = round(new Ctor(x), sd, rm);
|
|
291
|
+
e = getBase10Exponent(x);
|
|
292
|
+
str = toString(x, sd <= e || e <= Ctor.toExpNeg, sd);
|
|
293
|
+
}
|
|
294
|
+
return str;
|
|
295
|
+
};
|
|
296
|
+
P.toSignificantDigits = P.tosd = function(sd, rm) {
|
|
297
|
+
var x = this, Ctor = x.constructor;
|
|
298
|
+
if (sd === void 0) {
|
|
299
|
+
sd = Ctor.precision;
|
|
300
|
+
rm = Ctor.rounding;
|
|
301
|
+
} else {
|
|
302
|
+
checkInt32(sd, 1, MAX_DIGITS);
|
|
303
|
+
if (rm === void 0) rm = Ctor.rounding;
|
|
304
|
+
else checkInt32(rm, 0, 8);
|
|
305
|
+
}
|
|
306
|
+
return round(new Ctor(x), sd, rm);
|
|
307
|
+
};
|
|
308
|
+
P.toString = P.valueOf = P.val = P.toJSON = P[Symbol.for("nodejs.util.inspect.custom")] = function() {
|
|
309
|
+
var x = this, e = getBase10Exponent(x), Ctor = x.constructor;
|
|
310
|
+
return toString(x, e <= Ctor.toExpNeg || e >= Ctor.toExpPos);
|
|
311
|
+
};
|
|
312
|
+
function add(x, y) {
|
|
313
|
+
var carry, d, e, i, k, len, xd, yd, Ctor = x.constructor, pr = Ctor.precision;
|
|
314
|
+
if (!x.s || !y.s) {
|
|
315
|
+
if (!y.s) y = new Ctor(x);
|
|
316
|
+
return external ? round(y, pr) : y;
|
|
317
|
+
}
|
|
318
|
+
xd = x.d;
|
|
319
|
+
yd = y.d;
|
|
320
|
+
k = x.e;
|
|
321
|
+
e = y.e;
|
|
322
|
+
xd = xd.slice();
|
|
323
|
+
i = k - e;
|
|
324
|
+
if (i) {
|
|
325
|
+
if (i < 0) {
|
|
326
|
+
d = xd;
|
|
327
|
+
i = -i;
|
|
328
|
+
len = yd.length;
|
|
329
|
+
} else {
|
|
330
|
+
d = yd;
|
|
331
|
+
e = k;
|
|
332
|
+
len = xd.length;
|
|
333
|
+
}
|
|
334
|
+
k = Math.ceil(pr / LOG_BASE);
|
|
335
|
+
len = k > len ? k + 1 : len + 1;
|
|
336
|
+
if (i > len) {
|
|
337
|
+
i = len;
|
|
338
|
+
d.length = 1;
|
|
339
|
+
}
|
|
340
|
+
d.reverse();
|
|
341
|
+
for (; i--;) d.push(0);
|
|
342
|
+
d.reverse();
|
|
343
|
+
}
|
|
344
|
+
len = xd.length;
|
|
345
|
+
i = yd.length;
|
|
346
|
+
if (len - i < 0) {
|
|
347
|
+
i = len;
|
|
348
|
+
d = yd;
|
|
349
|
+
yd = xd;
|
|
350
|
+
xd = d;
|
|
351
|
+
}
|
|
352
|
+
for (carry = 0; i;) {
|
|
353
|
+
carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
|
|
354
|
+
xd[i] %= BASE;
|
|
355
|
+
}
|
|
356
|
+
if (carry) {
|
|
357
|
+
xd.unshift(carry);
|
|
358
|
+
++e;
|
|
359
|
+
}
|
|
360
|
+
for (len = xd.length; xd[--len] == 0;) xd.pop();
|
|
361
|
+
y.d = xd;
|
|
362
|
+
y.e = e;
|
|
363
|
+
return external ? round(y, pr) : y;
|
|
364
|
+
}
|
|
365
|
+
function checkInt32(i, min, max) {
|
|
366
|
+
if (i !== ~~i || i < min || i > max) throw Error(invalidArgument + i);
|
|
367
|
+
}
|
|
368
|
+
function digitsToString(d) {
|
|
369
|
+
var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
|
|
370
|
+
if (indexOfLastWord > 0) {
|
|
371
|
+
str += w;
|
|
372
|
+
for (i = 1; i < indexOfLastWord; i++) {
|
|
373
|
+
ws = d[i] + "";
|
|
374
|
+
k = LOG_BASE - ws.length;
|
|
375
|
+
if (k) str += getZeroString(k);
|
|
376
|
+
str += ws;
|
|
377
|
+
}
|
|
378
|
+
w = d[i];
|
|
379
|
+
ws = w + "";
|
|
380
|
+
k = LOG_BASE - ws.length;
|
|
381
|
+
if (k) str += getZeroString(k);
|
|
382
|
+
} else if (w === 0) return "0";
|
|
383
|
+
for (; w % 10 === 0;) w /= 10;
|
|
384
|
+
return str + w;
|
|
385
|
+
}
|
|
386
|
+
var divide = (function() {
|
|
387
|
+
function multiplyInteger(x, k) {
|
|
388
|
+
var temp, carry = 0, i = x.length;
|
|
389
|
+
for (x = x.slice(); i--;) {
|
|
390
|
+
temp = x[i] * k + carry;
|
|
391
|
+
x[i] = temp % BASE | 0;
|
|
392
|
+
carry = temp / BASE | 0;
|
|
393
|
+
}
|
|
394
|
+
if (carry) x.unshift(carry);
|
|
395
|
+
return x;
|
|
396
|
+
}
|
|
397
|
+
function compare(a, b, aL, bL) {
|
|
398
|
+
var i, r;
|
|
399
|
+
if (aL != bL) r = aL > bL ? 1 : -1;
|
|
400
|
+
else for (i = r = 0; i < aL; i++) if (a[i] != b[i]) {
|
|
401
|
+
r = a[i] > b[i] ? 1 : -1;
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
return r;
|
|
405
|
+
}
|
|
406
|
+
function subtract(a, b, aL) {
|
|
407
|
+
var i = 0;
|
|
408
|
+
for (; aL--;) {
|
|
409
|
+
a[aL] -= i;
|
|
410
|
+
i = a[aL] < b[aL] ? 1 : 0;
|
|
411
|
+
a[aL] = i * BASE + a[aL] - b[aL];
|
|
412
|
+
}
|
|
413
|
+
for (; !a[0] && a.length > 1;) a.shift();
|
|
414
|
+
}
|
|
415
|
+
return function(x, y, pr, dp) {
|
|
416
|
+
var cmp, e, i, k, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
|
|
417
|
+
if (!x.s) return new Ctor(x);
|
|
418
|
+
if (!y.s) throw Error(decimalError + "Division by zero");
|
|
419
|
+
e = x.e - y.e;
|
|
420
|
+
yL = yd.length;
|
|
421
|
+
xL = xd.length;
|
|
422
|
+
q = new Ctor(sign);
|
|
423
|
+
qd = q.d = [];
|
|
424
|
+
for (i = 0; yd[i] == (xd[i] || 0);) ++i;
|
|
425
|
+
if (yd[i] > (xd[i] || 0)) --e;
|
|
426
|
+
if (pr == null) sd = pr = Ctor.precision;
|
|
427
|
+
else if (dp) sd = pr + (getBase10Exponent(x) - getBase10Exponent(y)) + 1;
|
|
428
|
+
else sd = pr;
|
|
429
|
+
if (sd < 0) return new Ctor(0);
|
|
430
|
+
sd = sd / LOG_BASE + 2 | 0;
|
|
431
|
+
i = 0;
|
|
432
|
+
if (yL == 1) {
|
|
433
|
+
k = 0;
|
|
434
|
+
yd = yd[0];
|
|
435
|
+
sd++;
|
|
436
|
+
for (; (i < xL || k) && sd--; i++) {
|
|
437
|
+
t = k * BASE + (xd[i] || 0);
|
|
438
|
+
qd[i] = t / yd | 0;
|
|
439
|
+
k = t % yd | 0;
|
|
440
|
+
}
|
|
441
|
+
} else {
|
|
442
|
+
k = BASE / (yd[0] + 1) | 0;
|
|
443
|
+
if (k > 1) {
|
|
444
|
+
yd = multiplyInteger(yd, k);
|
|
445
|
+
xd = multiplyInteger(xd, k);
|
|
446
|
+
yL = yd.length;
|
|
447
|
+
xL = xd.length;
|
|
448
|
+
}
|
|
449
|
+
xi = yL;
|
|
450
|
+
rem = xd.slice(0, yL);
|
|
451
|
+
remL = rem.length;
|
|
452
|
+
for (; remL < yL;) rem[remL++] = 0;
|
|
453
|
+
yz = yd.slice();
|
|
454
|
+
yz.unshift(0);
|
|
455
|
+
yd0 = yd[0];
|
|
456
|
+
if (yd[1] >= BASE / 2) ++yd0;
|
|
457
|
+
do {
|
|
458
|
+
k = 0;
|
|
459
|
+
cmp = compare(yd, rem, yL, remL);
|
|
460
|
+
if (cmp < 0) {
|
|
461
|
+
rem0 = rem[0];
|
|
462
|
+
if (yL != remL) rem0 = rem0 * BASE + (rem[1] || 0);
|
|
463
|
+
k = rem0 / yd0 | 0;
|
|
464
|
+
if (k > 1) {
|
|
465
|
+
if (k >= BASE) k = BASE - 1;
|
|
466
|
+
prod = multiplyInteger(yd, k);
|
|
467
|
+
prodL = prod.length;
|
|
468
|
+
remL = rem.length;
|
|
469
|
+
cmp = compare(prod, rem, prodL, remL);
|
|
470
|
+
if (cmp == 1) {
|
|
471
|
+
k--;
|
|
472
|
+
subtract(prod, yL < prodL ? yz : yd, prodL);
|
|
473
|
+
}
|
|
474
|
+
} else {
|
|
475
|
+
if (k == 0) cmp = k = 1;
|
|
476
|
+
prod = yd.slice();
|
|
477
|
+
}
|
|
478
|
+
prodL = prod.length;
|
|
479
|
+
if (prodL < remL) prod.unshift(0);
|
|
480
|
+
subtract(rem, prod, remL);
|
|
481
|
+
if (cmp == -1) {
|
|
482
|
+
remL = rem.length;
|
|
483
|
+
cmp = compare(yd, rem, yL, remL);
|
|
484
|
+
if (cmp < 1) {
|
|
485
|
+
k++;
|
|
486
|
+
subtract(rem, yL < remL ? yz : yd, remL);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
remL = rem.length;
|
|
490
|
+
} else if (cmp === 0) {
|
|
491
|
+
k++;
|
|
492
|
+
rem = [0];
|
|
493
|
+
}
|
|
494
|
+
qd[i++] = k;
|
|
495
|
+
if (cmp && rem[0]) rem[remL++] = xd[xi] || 0;
|
|
496
|
+
else {
|
|
497
|
+
rem = [xd[xi]];
|
|
498
|
+
remL = 1;
|
|
499
|
+
}
|
|
500
|
+
} while ((xi++ < xL || rem[0] !== void 0) && sd--);
|
|
501
|
+
}
|
|
502
|
+
if (!qd[0]) qd.shift();
|
|
503
|
+
q.e = e;
|
|
504
|
+
return round(q, dp ? pr + getBase10Exponent(q) + 1 : pr);
|
|
505
|
+
};
|
|
506
|
+
})();
|
|
507
|
+
function exp(x, sd) {
|
|
508
|
+
var denominator, guard, pow, sum, t, wpr, i = 0, k = 0, Ctor = x.constructor, pr = Ctor.precision;
|
|
509
|
+
if (getBase10Exponent(x) > 16) throw Error(exponentOutOfRange + getBase10Exponent(x));
|
|
510
|
+
if (!x.s) return new Ctor(ONE);
|
|
511
|
+
if (sd == null) {
|
|
512
|
+
external = false;
|
|
513
|
+
wpr = pr;
|
|
514
|
+
} else wpr = sd;
|
|
515
|
+
t = new Ctor(.03125);
|
|
516
|
+
while (x.abs().gte(.1)) {
|
|
517
|
+
x = x.times(t);
|
|
518
|
+
k += 5;
|
|
519
|
+
}
|
|
520
|
+
guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
|
|
521
|
+
wpr += guard;
|
|
522
|
+
denominator = pow = sum = new Ctor(ONE);
|
|
523
|
+
Ctor.precision = wpr;
|
|
524
|
+
for (;;) {
|
|
525
|
+
pow = round(pow.times(x), wpr);
|
|
526
|
+
denominator = denominator.times(++i);
|
|
527
|
+
t = sum.plus(divide(pow, denominator, wpr));
|
|
528
|
+
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
|
|
529
|
+
while (k--) sum = round(sum.times(sum), wpr);
|
|
530
|
+
Ctor.precision = pr;
|
|
531
|
+
return sd == null ? (external = true, round(sum, pr)) : sum;
|
|
532
|
+
}
|
|
533
|
+
sum = t;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function getBase10Exponent(x) {
|
|
537
|
+
var e = x.e * LOG_BASE, w = x.d[0];
|
|
538
|
+
for (; w >= 10; w /= 10) e++;
|
|
539
|
+
return e;
|
|
540
|
+
}
|
|
541
|
+
function getLn10(Ctor, sd, pr) {
|
|
542
|
+
if (sd > Ctor.LN10.sd()) {
|
|
543
|
+
external = true;
|
|
544
|
+
if (pr) Ctor.precision = pr;
|
|
545
|
+
throw Error(decimalError + "LN10 precision limit exceeded");
|
|
546
|
+
}
|
|
547
|
+
return round(new Ctor(Ctor.LN10), sd);
|
|
548
|
+
}
|
|
549
|
+
function getZeroString(k) {
|
|
550
|
+
var zs = "";
|
|
551
|
+
for (; k--;) zs += "0";
|
|
552
|
+
return zs;
|
|
553
|
+
}
|
|
554
|
+
function ln(y, sd) {
|
|
555
|
+
var c, c0, denominator, e, numerator, sum, t, wpr, x2, n = 1, guard = 10, x = y, xd = x.d, Ctor = x.constructor, pr = Ctor.precision;
|
|
556
|
+
if (x.s < 1) throw Error(decimalError + (x.s ? "NaN" : "-Infinity"));
|
|
557
|
+
if (x.eq(ONE)) return new Ctor(0);
|
|
558
|
+
if (sd == null) {
|
|
559
|
+
external = false;
|
|
560
|
+
wpr = pr;
|
|
561
|
+
} else wpr = sd;
|
|
562
|
+
if (x.eq(10)) {
|
|
563
|
+
if (sd == null) external = true;
|
|
564
|
+
return getLn10(Ctor, wpr);
|
|
565
|
+
}
|
|
566
|
+
wpr += guard;
|
|
567
|
+
Ctor.precision = wpr;
|
|
568
|
+
c = digitsToString(xd);
|
|
569
|
+
c0 = c.charAt(0);
|
|
570
|
+
e = getBase10Exponent(x);
|
|
571
|
+
if (Math.abs(e) < 0x5543df729c000) {
|
|
572
|
+
while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
|
|
573
|
+
x = x.times(y);
|
|
574
|
+
c = digitsToString(x.d);
|
|
575
|
+
c0 = c.charAt(0);
|
|
576
|
+
n++;
|
|
577
|
+
}
|
|
578
|
+
e = getBase10Exponent(x);
|
|
579
|
+
if (c0 > 1) {
|
|
580
|
+
x = new Ctor("0." + c);
|
|
581
|
+
e++;
|
|
582
|
+
} else x = new Ctor(c0 + "." + c.slice(1));
|
|
583
|
+
} else {
|
|
584
|
+
t = getLn10(Ctor, wpr + 2, pr).times(e + "");
|
|
585
|
+
x = ln(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
|
|
586
|
+
Ctor.precision = pr;
|
|
587
|
+
return sd == null ? (external = true, round(x, pr)) : x;
|
|
588
|
+
}
|
|
589
|
+
sum = numerator = x = divide(x.minus(ONE), x.plus(ONE), wpr);
|
|
590
|
+
x2 = round(x.times(x), wpr);
|
|
591
|
+
denominator = 3;
|
|
592
|
+
for (;;) {
|
|
593
|
+
numerator = round(numerator.times(x2), wpr);
|
|
594
|
+
t = sum.plus(divide(numerator, new Ctor(denominator), wpr));
|
|
595
|
+
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
|
|
596
|
+
sum = sum.times(2);
|
|
597
|
+
if (e !== 0) sum = sum.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
|
|
598
|
+
sum = divide(sum, new Ctor(n), wpr);
|
|
599
|
+
Ctor.precision = pr;
|
|
600
|
+
return sd == null ? (external = true, round(sum, pr)) : sum;
|
|
601
|
+
}
|
|
602
|
+
sum = t;
|
|
603
|
+
denominator += 2;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
function parseDecimal(x, str) {
|
|
607
|
+
var e, i, len;
|
|
608
|
+
if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
|
|
609
|
+
if ((i = str.search(/e/i)) > 0) {
|
|
610
|
+
if (e < 0) e = i;
|
|
611
|
+
e += +str.slice(i + 1);
|
|
612
|
+
str = str.substring(0, i);
|
|
613
|
+
} else if (e < 0) e = str.length;
|
|
614
|
+
for (i = 0; str.charCodeAt(i) === 48;) ++i;
|
|
615
|
+
for (len = str.length; str.charCodeAt(len - 1) === 48;) --len;
|
|
616
|
+
str = str.slice(i, len);
|
|
617
|
+
if (str) {
|
|
618
|
+
len -= i;
|
|
619
|
+
e = e - i - 1;
|
|
620
|
+
x.e = mathfloor(e / LOG_BASE);
|
|
621
|
+
x.d = [];
|
|
622
|
+
i = (e + 1) % LOG_BASE;
|
|
623
|
+
if (e < 0) i += LOG_BASE;
|
|
624
|
+
if (i < len) {
|
|
625
|
+
if (i) x.d.push(+str.slice(0, i));
|
|
626
|
+
for (len -= LOG_BASE; i < len;) x.d.push(+str.slice(i, i += LOG_BASE));
|
|
627
|
+
str = str.slice(i);
|
|
628
|
+
i = LOG_BASE - str.length;
|
|
629
|
+
} else i -= len;
|
|
630
|
+
for (; i--;) str += "0";
|
|
631
|
+
x.d.push(+str);
|
|
632
|
+
if (external && (x.e > MAX_E || x.e < -MAX_E)) throw Error(exponentOutOfRange + e);
|
|
633
|
+
} else {
|
|
634
|
+
x.s = 0;
|
|
635
|
+
x.e = 0;
|
|
636
|
+
x.d = [0];
|
|
637
|
+
}
|
|
638
|
+
return x;
|
|
639
|
+
}
|
|
640
|
+
function round(x, sd, rm) {
|
|
641
|
+
var i, j, k, n, rd, doRound, w, xdi, xd = x.d;
|
|
642
|
+
for (n = 1, k = xd[0]; k >= 10; k /= 10) n++;
|
|
643
|
+
i = sd - n;
|
|
644
|
+
if (i < 0) {
|
|
645
|
+
i += LOG_BASE;
|
|
646
|
+
j = sd;
|
|
647
|
+
w = xd[xdi = 0];
|
|
648
|
+
} else {
|
|
649
|
+
xdi = Math.ceil((i + 1) / LOG_BASE);
|
|
650
|
+
k = xd.length;
|
|
651
|
+
if (xdi >= k) return x;
|
|
652
|
+
w = k = xd[xdi];
|
|
653
|
+
for (n = 1; k >= 10; k /= 10) n++;
|
|
654
|
+
i %= LOG_BASE;
|
|
655
|
+
j = i - LOG_BASE + n;
|
|
656
|
+
}
|
|
657
|
+
if (rm !== void 0) {
|
|
658
|
+
k = mathpow(10, n - j - 1);
|
|
659
|
+
rd = w / k % 10 | 0;
|
|
660
|
+
doRound = sd < 0 || xd[xdi + 1] !== void 0 || w % k;
|
|
661
|
+
doRound = rm < 4 ? (rd || doRound) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || doRound || rm == 6 && (i > 0 ? j > 0 ? w / mathpow(10, n - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
662
|
+
}
|
|
663
|
+
if (sd < 1 || !xd[0]) {
|
|
664
|
+
if (doRound) {
|
|
665
|
+
k = getBase10Exponent(x);
|
|
666
|
+
xd.length = 1;
|
|
667
|
+
sd = sd - k - 1;
|
|
668
|
+
xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
|
|
669
|
+
x.e = mathfloor(-sd / LOG_BASE) || 0;
|
|
670
|
+
} else {
|
|
671
|
+
xd.length = 1;
|
|
672
|
+
xd[0] = x.e = x.s = 0;
|
|
673
|
+
}
|
|
674
|
+
return x;
|
|
675
|
+
}
|
|
676
|
+
if (i == 0) {
|
|
677
|
+
xd.length = xdi;
|
|
678
|
+
k = 1;
|
|
679
|
+
xdi--;
|
|
680
|
+
} else {
|
|
681
|
+
xd.length = xdi + 1;
|
|
682
|
+
k = mathpow(10, LOG_BASE - i);
|
|
683
|
+
xd[xdi] = j > 0 ? (w / mathpow(10, n - j) % mathpow(10, j) | 0) * k : 0;
|
|
684
|
+
}
|
|
685
|
+
if (doRound) for (;;) if (xdi == 0) {
|
|
686
|
+
if ((xd[0] += k) == BASE) {
|
|
687
|
+
xd[0] = 1;
|
|
688
|
+
++x.e;
|
|
689
|
+
}
|
|
690
|
+
break;
|
|
691
|
+
} else {
|
|
692
|
+
xd[xdi] += k;
|
|
693
|
+
if (xd[xdi] != BASE) break;
|
|
694
|
+
xd[xdi--] = 0;
|
|
695
|
+
k = 1;
|
|
696
|
+
}
|
|
697
|
+
for (i = xd.length; xd[--i] === 0;) xd.pop();
|
|
698
|
+
if (external && (x.e > MAX_E || x.e < -MAX_E)) throw Error(exponentOutOfRange + getBase10Exponent(x));
|
|
699
|
+
return x;
|
|
700
|
+
}
|
|
701
|
+
function subtract(x, y) {
|
|
702
|
+
var d, e, i, j, k, len, xd, xe, xLTy, yd, Ctor = x.constructor, pr = Ctor.precision;
|
|
703
|
+
if (!x.s || !y.s) {
|
|
704
|
+
if (y.s) y.s = -y.s;
|
|
705
|
+
else y = new Ctor(x);
|
|
706
|
+
return external ? round(y, pr) : y;
|
|
707
|
+
}
|
|
708
|
+
xd = x.d;
|
|
709
|
+
yd = y.d;
|
|
710
|
+
e = y.e;
|
|
711
|
+
xe = x.e;
|
|
712
|
+
xd = xd.slice();
|
|
713
|
+
k = xe - e;
|
|
714
|
+
if (k) {
|
|
715
|
+
xLTy = k < 0;
|
|
716
|
+
if (xLTy) {
|
|
717
|
+
d = xd;
|
|
718
|
+
k = -k;
|
|
719
|
+
len = yd.length;
|
|
720
|
+
} else {
|
|
721
|
+
d = yd;
|
|
722
|
+
e = xe;
|
|
723
|
+
len = xd.length;
|
|
724
|
+
}
|
|
725
|
+
i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
|
|
726
|
+
if (k > i) {
|
|
727
|
+
k = i;
|
|
728
|
+
d.length = 1;
|
|
729
|
+
}
|
|
730
|
+
d.reverse();
|
|
731
|
+
for (i = k; i--;) d.push(0);
|
|
732
|
+
d.reverse();
|
|
733
|
+
} else {
|
|
734
|
+
i = xd.length;
|
|
735
|
+
len = yd.length;
|
|
736
|
+
xLTy = i < len;
|
|
737
|
+
if (xLTy) len = i;
|
|
738
|
+
for (i = 0; i < len; i++) if (xd[i] != yd[i]) {
|
|
739
|
+
xLTy = xd[i] < yd[i];
|
|
740
|
+
break;
|
|
741
|
+
}
|
|
742
|
+
k = 0;
|
|
743
|
+
}
|
|
744
|
+
if (xLTy) {
|
|
745
|
+
d = xd;
|
|
746
|
+
xd = yd;
|
|
747
|
+
yd = d;
|
|
748
|
+
y.s = -y.s;
|
|
749
|
+
}
|
|
750
|
+
len = xd.length;
|
|
751
|
+
for (i = yd.length - len; i > 0; --i) xd[len++] = 0;
|
|
752
|
+
for (i = yd.length; i > k;) {
|
|
753
|
+
if (xd[--i] < yd[i]) {
|
|
754
|
+
for (j = i; j && xd[--j] === 0;) xd[j] = BASE - 1;
|
|
755
|
+
--xd[j];
|
|
756
|
+
xd[i] += BASE;
|
|
757
|
+
}
|
|
758
|
+
xd[i] -= yd[i];
|
|
759
|
+
}
|
|
760
|
+
for (; xd[--len] === 0;) xd.pop();
|
|
761
|
+
for (; xd[0] === 0; xd.shift()) --e;
|
|
762
|
+
if (!xd[0]) return new Ctor(0);
|
|
763
|
+
y.d = xd;
|
|
764
|
+
y.e = e;
|
|
765
|
+
return external ? round(y, pr) : y;
|
|
766
|
+
}
|
|
767
|
+
function toString(x, isExp, sd) {
|
|
768
|
+
var k, e = getBase10Exponent(x), str = digitsToString(x.d), len = str.length;
|
|
769
|
+
if (isExp) {
|
|
770
|
+
if (sd && (k = sd - len) > 0) str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
|
|
771
|
+
else if (len > 1) str = str.charAt(0) + "." + str.slice(1);
|
|
772
|
+
str = str + (e < 0 ? "e" : "e+") + e;
|
|
773
|
+
} else if (e < 0) {
|
|
774
|
+
str = "0." + getZeroString(-e - 1) + str;
|
|
775
|
+
if (sd && (k = sd - len) > 0) str += getZeroString(k);
|
|
776
|
+
} else if (e >= len) {
|
|
777
|
+
str += getZeroString(e + 1 - len);
|
|
778
|
+
if (sd && (k = sd - e - 1) > 0) str = str + "." + getZeroString(k);
|
|
779
|
+
} else {
|
|
780
|
+
if ((k = e + 1) < len) str = str.slice(0, k) + "." + str.slice(k);
|
|
781
|
+
if (sd && (k = sd - len) > 0) {
|
|
782
|
+
if (e + 1 === len) str += ".";
|
|
783
|
+
str += getZeroString(k);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
return x.s < 0 ? "-" + str : str;
|
|
787
|
+
}
|
|
788
|
+
function truncate(arr, len) {
|
|
789
|
+
if (arr.length > len) {
|
|
790
|
+
arr.length = len;
|
|
791
|
+
return true;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
function clone(obj) {
|
|
795
|
+
var i, p, ps;
|
|
796
|
+
function Decimal(value) {
|
|
797
|
+
var x = this;
|
|
798
|
+
if (!(x instanceof Decimal)) return new Decimal(value);
|
|
799
|
+
x.constructor = Decimal;
|
|
800
|
+
if (value instanceof Decimal) {
|
|
801
|
+
x.s = value.s;
|
|
802
|
+
x.e = value.e;
|
|
803
|
+
x.d = (value = value.d) ? value.slice() : value;
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
if (typeof value === "number") {
|
|
807
|
+
if (value * 0 !== 0) throw Error(invalidArgument + value);
|
|
808
|
+
if (value > 0) x.s = 1;
|
|
809
|
+
else if (value < 0) {
|
|
810
|
+
value = -value;
|
|
811
|
+
x.s = -1;
|
|
812
|
+
} else {
|
|
813
|
+
x.s = 0;
|
|
814
|
+
x.e = 0;
|
|
815
|
+
x.d = [0];
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
if (value === ~~value && value < 1e7) {
|
|
819
|
+
x.e = 0;
|
|
820
|
+
x.d = [value];
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
return parseDecimal(x, value.toString());
|
|
824
|
+
} else if (typeof value !== "string") throw Error(invalidArgument + value);
|
|
825
|
+
if (value.charCodeAt(0) === 45) {
|
|
826
|
+
value = value.slice(1);
|
|
827
|
+
x.s = -1;
|
|
828
|
+
} else x.s = 1;
|
|
829
|
+
if (isDecimal.test(value)) parseDecimal(x, value);
|
|
830
|
+
else throw Error(invalidArgument + value);
|
|
831
|
+
}
|
|
832
|
+
Decimal.prototype = P;
|
|
833
|
+
Decimal.ROUND_UP = 0;
|
|
834
|
+
Decimal.ROUND_DOWN = 1;
|
|
835
|
+
Decimal.ROUND_CEIL = 2;
|
|
836
|
+
Decimal.ROUND_FLOOR = 3;
|
|
837
|
+
Decimal.ROUND_HALF_UP = 4;
|
|
838
|
+
Decimal.ROUND_HALF_DOWN = 5;
|
|
839
|
+
Decimal.ROUND_HALF_EVEN = 6;
|
|
840
|
+
Decimal.ROUND_HALF_CEIL = 7;
|
|
841
|
+
Decimal.ROUND_HALF_FLOOR = 8;
|
|
842
|
+
Decimal.clone = clone;
|
|
843
|
+
Decimal.config = Decimal.set = config;
|
|
844
|
+
if (obj === void 0) obj = {};
|
|
845
|
+
if (obj) {
|
|
846
|
+
ps = [
|
|
847
|
+
"precision",
|
|
848
|
+
"rounding",
|
|
849
|
+
"toExpNeg",
|
|
850
|
+
"toExpPos",
|
|
851
|
+
"LN10"
|
|
852
|
+
];
|
|
853
|
+
for (i = 0; i < ps.length;) if (!obj.hasOwnProperty(p = ps[i++])) obj[p] = this[p];
|
|
854
|
+
}
|
|
855
|
+
Decimal.config(obj);
|
|
856
|
+
return Decimal;
|
|
857
|
+
}
|
|
858
|
+
function config(obj) {
|
|
859
|
+
if (!obj || typeof obj !== "object") throw Error(decimalError + "Object expected");
|
|
860
|
+
var i, p, v, ps = [
|
|
861
|
+
"precision",
|
|
862
|
+
1,
|
|
863
|
+
MAX_DIGITS,
|
|
864
|
+
"rounding",
|
|
865
|
+
0,
|
|
866
|
+
8,
|
|
867
|
+
"toExpNeg",
|
|
868
|
+
-Infinity,
|
|
869
|
+
0,
|
|
870
|
+
"toExpPos",
|
|
871
|
+
0,
|
|
872
|
+
Infinity
|
|
873
|
+
];
|
|
874
|
+
for (i = 0; i < ps.length; i += 3) if ((v = obj[p = ps[i]]) !== void 0) if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2]) this[p] = v;
|
|
875
|
+
else throw Error(invalidArgument + p + ": " + v);
|
|
876
|
+
if ((v = obj[p = "LN10"]) !== void 0) if (v == Math.LN10) this[p] = new this(v);
|
|
877
|
+
else throw Error(invalidArgument + p + ": " + v);
|
|
878
|
+
return this;
|
|
879
|
+
}
|
|
880
|
+
var Decimal = clone(defaults);
|
|
881
|
+
ONE = new Decimal(1);
|
|
882
|
+
var decimal_default = Decimal;
|
|
883
|
+
//#endregion
|
|
884
|
+
export { decimal_default as t };
|