@hot-updater/console 1.0.0-rc.0 → 1.0.0-rc.2
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/HashValueDisplay-CB0Eskit.js +1 -0
- package/.output/public/assets/InsightsPageHeader-Car5LNiZ.js +1 -0
- package/.output/public/assets/api-keys-BzKocqRy.js +1 -0
- package/.output/public/assets/api-keys-api-BHcODB7q.js +1 -0
- package/.output/public/assets/card-Dhr_eFYj.js +1 -0
- package/.output/public/assets/{chart-no-axes-combined-FaYMGmQS.js → chart-no-axes-combined-Dy4WJv2U.js} +1 -1
- package/.output/public/assets/composite-Bp98A0Ld.js +1 -0
- package/.output/public/assets/createServerFn-CA8fs7QD.js +3 -0
- package/.output/public/assets/dialog-CUTrcPlB.js +1 -0
- package/.output/public/assets/{dist-DspNKfMj.js → dist-C_NydL0e.js} +1 -1
- package/.output/public/assets/index-DdAz-CXv.js +10 -0
- package/.output/public/assets/input-group-cSOG4wh_.js +1 -0
- package/.output/public/assets/insights-C0PBSZ-n.js +1 -0
- package/.output/public/assets/installations-CE33wgbY.js +2 -0
- package/.output/public/assets/installations-CStZja8x.js +1 -0
- package/.output/public/assets/lazyRouteComponent-Ccp3bwBY.js +1 -0
- package/.output/public/assets/link-CI8idAUi.js +1 -0
- package/.output/public/assets/loader-circle-BoxLrsOu.js +1 -0
- package/.output/public/assets/refresh-cw-Bqc72UZG.js +1 -0
- package/.output/public/assets/{routes-DcQnVajO.js → routes-DGVXdzpw.js} +2 -2
- package/.output/public/assets/routes-DTlwOr8I.js +1 -0
- package/.output/public/assets/{shield-check-DE_hVuHu.js → shield-check-uK3MHWJZ.js} +1 -1
- package/.output/public/assets/signing-CMf4aqDO.js +1 -0
- package/.output/public/assets/styles-BCvbtKsm.css +2 -0
- package/.output/public/assets/table-2vcV89QB.js +1 -0
- package/.output/public/assets/useCompositeListItem-CHLITE_4.js +1 -0
- package/.output/public/assets/x-DCd0j8c6.js +1 -0
- package/.output/server/{__23tanstack-start-server-fn-resolver-DBP9TQ7K.mjs → __23tanstack-start-server-fn-resolver-B7ioJhtE.mjs} +44 -52
- package/.output/server/_libs/@base-ui/react+[...].mjs +1906 -4040
- package/.output/server/_libs/@tanstack/react-router+[...].mjs +52 -4
- package/.output/server/_libs/@tanstack/react-router-ssr-query+[...].mjs +2 -2
- package/.output/server/_libs/lucide-react.mjs +36 -3
- package/.output/server/_libs/next-themes.mjs +2 -2
- package/.output/server/_libs/sonner.mjs +2 -2
- package/.output/server/_libs/tanstack__react-query.mjs +2 -2
- package/.output/server/_libs/verkit.mjs +20 -15
- package/.output/server/_runtime.mjs +1 -10
- package/.output/server/_ssr/HashValueDisplay-DwpGLfrl.mjs +55 -0
- package/.output/server/_ssr/InsightsPageHeader-Df4Brj8u.mjs +484 -0
- package/.output/server/_ssr/{api-keys-BnM_o2nS.mjs → api-keys-CZeTPQys.mjs} +11 -13
- package/.output/server/_ssr/{api-keys-api-CIywsSF5.mjs → api-keys-api-BUPQVSpk.mjs} +2 -2
- package/.output/server/_ssr/{api-keys-rpc-BSp1wkIV.mjs → api-keys-rpc-Cs7tS5_j.mjs} +5 -5
- package/.output/server/_ssr/{api-rpc-cG5wd_tO.mjs → api-rpc-tAupfGQm.mjs} +73 -142
- package/.output/server/_ssr/{auth-rpc-BrJ6obHJ.mjs → auth-rpc-DUaeOWKK.mjs} +4 -4
- package/.output/server/_ssr/{auth.server-DwKoZoQM.mjs → auth.server-DW71WzsD.mjs} +2 -5
- package/.output/server/_ssr/{bundle-signing-rpc-COoQhW8E.mjs → bundle-signing-rpc-BhnBw0-d.mjs} +2 -2
- package/.output/server/_ssr/bundle-signing.server-C4NW5mWx.mjs +12 -0
- package/.output/server/_ssr/{alert-Dim3MGY5.mjs → card-BRiPmi0C.mjs} +61 -39
- package/.output/server/_ssr/{config.server-DEiLhKmy.mjs → config.server-afDuAwaG.mjs} +15 -8
- package/.output/server/_ssr/{createSsrRpc-9P0S0lJ3.mjs → createSsrRpc-DjWNJ0uc.mjs} +6 -6
- package/.output/server/_ssr/databaseJsonValue-d6I3nAS4.mjs +45 -0
- package/.output/server/_ssr/{databaseRows-CwbNwYSl.mjs → databaseRows-5bCRTxm-.mjs} +4 -44
- package/.output/server/_ssr/{deleteBundle-Cu_XOMt0.mjs → deleteBundle-BTGwBgzx.mjs} +2 -2
- package/.output/server/_ssr/{dialog-CQuRMNZ4.mjs → dialog-DS-nw-pA.mjs} +2 -2
- package/.output/server/_ssr/{dist-BVSLTpoP.mjs → dist-CyzPaI5v.mjs} +2 -2
- package/.output/server/_ssr/{getBundleChildren-BcRMFoDF.mjs → getBundleChildren-C0vh4ZvE.mjs} +2 -2
- package/.output/server/_ssr/input-group-BpsnmvZw.mjs +70 -0
- package/.output/server/_ssr/insights-BdS364Xu.mjs +460 -0
- package/.output/server/_ssr/insights-rpc-38DujK0G.mjs +57 -0
- package/.output/server/_ssr/insightsContract-fjJDBeEE.mjs +303 -0
- package/.output/server/_ssr/installations-CtA59MQG.mjs +29 -0
- package/.output/server/_ssr/installations-DiVKEF5T.mjs +627 -0
- package/.output/server/_ssr/{router-C-KUBfOi.mjs → router-B9wG_9f8.mjs} +37 -46
- package/.output/server/_ssr/{routes-Z7TwC6nC.mjs → routes-CKrrS2q2.mjs} +3 -3
- package/.output/server/_ssr/{routes-BM4ht9jb.mjs → routes-D7Yh_jfj.mjs} +402 -390
- package/.output/server/_ssr/runtime.server-DacU1TBV.mjs +438 -0
- package/.output/server/_ssr/{server-BjzmvXnO.mjs → server-D_C2rMzf.mjs} +5 -5
- package/.output/server/_ssr/{signing-k8GxyBDF.mjs → signing-Dz1WkZOf.mjs} +16 -85
- package/.output/server/_ssr/ssr.mjs +1 -1
- package/.output/server/_ssr/{field-DRIXKjZG.mjs → table-CnZmon_Z.mjs} +51 -5
- package/.output/server/_ssr/{uuidv7-BbJ-9D_I.mjs → uuidv7-D0QFkPL_.mjs} +3 -3
- package/.output/server/_tanstack-start-manifest_v-2MjTyxil.mjs +97 -0
- package/.output/server/index.mjs +168 -203
- package/lib/index.d.mts +4 -4
- package/lib/vite-internal.mjs +1 -1
- package/lib/vite.d.mts +0 -1
- package/package.json +8 -8
- package/src/components/AppSidebar.tsx +12 -16
- package/src/components/ConsoleAccessPage.tsx +1 -1
- package/src/components/HashValueDisplay.tsx +11 -2
- package/src/components/features/api-keys/ApiKeysPage.tsx +1 -1
- package/src/components/features/bundles/BundleChildrenPanel.tsx +7 -6
- package/src/components/features/bundles/BundleMetadata.tsx +1 -20
- package/src/components/features/channels/ChannelManagementDialog.tsx +1 -1
- package/src/components/features/insights/EventDetails.tsx +151 -0
- package/src/components/features/insights/EventHistoryCard.tsx +245 -0
- package/src/components/features/insights/EventHistoryList.tsx +63 -0
- package/src/components/features/insights/InsightsBundleReports.tsx +51 -0
- package/src/components/features/insights/InsightsControls.tsx +121 -0
- package/src/components/features/{analytics/AnalyticsErrorAlert.tsx → insights/InsightsErrorAlert.tsx} +6 -6
- package/src/components/features/insights/InsightsOverview.tsx +203 -0
- package/src/components/features/insights/InsightsPageHeader.tsx +48 -0
- package/src/components/features/insights/InsightsPagination.tsx +52 -0
- package/src/components/features/insights/InstallationHistoryCard.tsx +250 -0
- package/src/components/features/insights/InstallationMatchesCard.tsx +178 -0
- package/src/components/features/insights/InstallationPageHeader.tsx +90 -0
- package/src/components/features/releases/ReleaseEditorSheet.tsx +24 -24
- package/src/components/features/signing/BundleSigningPage.tsx +18 -126
- package/src/components/ui/badge.tsx +2 -0
- package/src/components/ui/combobox.tsx +1 -0
- package/src/components/ui/skeleton.tsx +4 -1
- package/src/components/ui/tooltip.tsx +1 -1
- package/src/index.ts +7 -3
- package/src/lib/api-rpc.ts +19 -90
- package/src/lib/api.ts +0 -99
- package/src/lib/insights-api.ts +100 -0
- package/src/lib/insights-rpc.ts +88 -0
- package/src/lib/insights-view.ts +15 -0
- package/src/lib/public-bundle-error.ts +19 -0
- package/src/lib/server/bundle-signing.server.ts +5 -82
- package/src/lib/server/console-runtime.server.ts +0 -9
- package/src/lib/server/releaseReachability.ts +1 -4
- package/src/lib/server/runtime.server.ts +6 -142
- package/src/routeTree.gen.ts +21 -21
- package/src/router.tsx +3 -0
- package/src/routes/-installations-search.ts +25 -12
- package/src/routes/__root.tsx +6 -16
- package/src/routes/api-keys.tsx +1 -1
- package/src/routes/index.tsx +21 -81
- package/src/routes/insights.tsx +84 -0
- package/src/routes/installations.tsx +294 -142
- package/src/styles.css +6 -0
- package/.output/public/assets/AnalyticsCapabilityContext-BCke57-7.js +0 -1
- package/.output/public/assets/BundleActivityChart-CnsBe_1J.js +0 -42
- package/.output/public/assets/BundleIdDisplay-Dky75zLU.js +0 -1
- package/.output/public/assets/alert-C-1KvDW8.js +0 -1
- package/.output/public/assets/analytics-Bqz0c-BT.js +0 -1
- package/.output/public/assets/analytics-api-CJdrTLLO.js +0 -1
- package/.output/public/assets/api-B_Rh-uzC.js +0 -1
- package/.output/public/assets/api-keys-BurCFhzH.js +0 -1
- package/.output/public/assets/api-keys-api-BEDJdQg3.js +0 -1
- package/.output/public/assets/badge-Bf0fZ-Gx.js +0 -1
- package/.output/public/assets/createServerFn-gM2-LFBy.js +0 -3
- package/.output/public/assets/dialog-BS60BRr2.js +0 -1
- package/.output/public/assets/download-O-yNBc9H.js +0 -1
- package/.output/public/assets/field-Buq148-A.js +0 -1
- package/.output/public/assets/index-kFhd2S78.js +0 -10
- package/.output/public/assets/installations-BrQ-od41.js +0 -2
- package/.output/public/assets/installations-CGlZ3ROz.js +0 -1
- package/.output/public/assets/lazyRouteComponent-rPzgA7S-.js +0 -1
- package/.output/public/assets/loader-circle-DCYF-wJl.js +0 -1
- package/.output/public/assets/refresh-cw-n8XYbPPj.js +0 -1
- package/.output/public/assets/routes-CrdokJ80.js +0 -1
- package/.output/public/assets/search-DLhbWw3W.js +0 -1
- package/.output/public/assets/signing-HRexfjsH.js +0 -1
- package/.output/public/assets/styles-eB4EtvFS.css +0 -2
- package/.output/public/assets/table-D8CLieHX.js +0 -1
- package/.output/public/assets/textarea-YJLTVAoq.js +0 -1
- package/.output/public/assets/useMutation-JsGVjQMY.js +0 -1
- package/.output/public/assets/useOpenInteractionType-4cRD5xO0.js +0 -1
- package/.output/server/_libs/@reduxjs/toolkit+[...].mjs +0 -1554
- package/.output/server/_libs/d3-array.mjs +0 -231
- package/.output/server/_libs/d3-color.mjs +0 -330
- package/.output/server/_libs/d3-format.mjs +0 -252
- package/.output/server/_libs/d3-interpolate.mjs +0 -207
- package/.output/server/_libs/d3-path.mjs +0 -77
- package/.output/server/_libs/d3-scale+[...].mjs +0 -1907
- package/.output/server/_libs/d3-shape.mjs +0 -818
- package/.output/server/_libs/decimal.js-light.mjs +0 -884
- package/.output/server/_libs/es-toolkit.mjs +0 -1134
- package/.output/server/_libs/eventemitter3.mjs +0 -236
- package/.output/server/_libs/immer.mjs +0 -532
- package/.output/server/_libs/react-redux+[...].mjs +0 -205
- package/.output/server/_libs/recharts+[...].mjs +0 -14117
- package/.output/server/_ssr/AnalyticsCapabilityContext-ui4DX8GO.mjs +0 -15
- package/.output/server/_ssr/BundleActivityChart-BiB9ZORH.mjs +0 -288
- package/.output/server/_ssr/BundleIdDisplay-Czk6iR6p.mjs +0 -13
- package/.output/server/_ssr/analytics-DtMTn8fn.mjs +0 -858
- package/.output/server/_ssr/analytics-api-Cg1M5v_H.mjs +0 -71
- package/.output/server/_ssr/analytics-input-fRRRn0uA.mjs +0 -96
- package/.output/server/_ssr/analytics-rpc-DY5uXvHT.mjs +0 -155
- package/.output/server/_ssr/api-BTSv1tZb.mjs +0 -282
- package/.output/server/_ssr/badge-DCxbEeof.mjs +0 -26
- package/.output/server/_ssr/bundle-signing.server-D5u8KkMp.mjs +0 -51
- package/.output/server/_ssr/installations-B-azgAvX.mjs +0 -19
- package/.output/server/_ssr/installations-Ctvzp2JH.mjs +0 -535
- package/.output/server/_ssr/runtime.server-awTLiiXW.mjs +0 -527
- package/.output/server/_ssr/table-v1yCvYo7.mjs +0 -53
- package/.output/server/_ssr/textarea-DYHnskhb.mjs +0 -14
- package/.output/server/_tanstack-start-manifest_v-CH4StzJu.mjs +0 -108
- package/src/components/features/analytics/ActivityChart.tsx +0 -150
- package/src/components/features/analytics/AnalyticsCapabilityContext.tsx +0 -24
- package/src/components/features/analytics/AnalyticsControls.tsx +0 -115
- package/src/components/features/analytics/AnalyticsOverview.tsx +0 -208
- package/src/components/features/analytics/BundleDistribution.tsx +0 -133
- package/src/components/features/analytics/BundleSelector.tsx +0 -114
- package/src/components/features/analytics/InstallationHistoryCard.tsx +0 -248
- package/src/components/features/analytics/InstallationMatchesCard.tsx +0 -132
- package/src/components/features/analytics/InstallationPageHeader.tsx +0 -138
- package/src/components/features/analytics/InstallationPagination.tsx +0 -48
- package/src/components/features/analytics/InstallationSearch.tsx +0 -230
- package/src/components/features/analytics/UpdateOutcomes.tsx +0 -147
- package/src/components/features/bundles/BundleActivityChart.tsx +0 -193
- package/src/components/features/bundles/BundleAnalyticsSummary.tsx +0 -123
- package/src/lib/analytics-api.ts +0 -145
- package/src/lib/analytics-error.ts +0 -19
- package/src/lib/analytics-input.ts +0 -187
- package/src/lib/analytics-overview.ts +0 -170
- package/src/lib/analytics-rpc.ts +0 -218
- package/src/lib/server/releaseActivity.ts +0 -27
- package/src/routes/analytics.tsx +0 -139
- /package/.output/public/assets/{preload-helper-TKOBYGYD.js → preload-helper-CQ36nxok.js} +0 -0
|
@@ -1,884 +0,0 @@
|
|
|
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 };
|