@hairy/utils 0.6.9 → 0.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1687 -104
- package/dist/index.d.ts +121 -18
- package/dist/index.mjs +1660 -115
- package/package.json +2 -7
- package/src/index.ts +0 -6
package/dist/index.mjs
CHANGED
|
@@ -1,76 +1,3 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
|
|
27
|
-
// ../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isObjectLike.js
|
|
28
|
-
var require_isObjectLike = __commonJS({
|
|
29
|
-
"../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isObjectLike.js"(exports, module) {
|
|
30
|
-
function isObjectLike(value) {
|
|
31
|
-
return !!value && typeof value == "object";
|
|
32
|
-
}
|
|
33
|
-
module.exports = isObjectLike;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// ../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isNumber.js
|
|
38
|
-
var require_isNumber = __commonJS({
|
|
39
|
-
"../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isNumber.js"(exports, module) {
|
|
40
|
-
var isObjectLike = require_isObjectLike();
|
|
41
|
-
var numberTag = "[object Number]";
|
|
42
|
-
var objectProto = global.Object.prototype;
|
|
43
|
-
var objectToString = objectProto.toString;
|
|
44
|
-
function isNumber2(value) {
|
|
45
|
-
return typeof value == "number" || isObjectLike(value) && objectToString.call(value) == numberTag;
|
|
46
|
-
}
|
|
47
|
-
module.exports = isNumber2;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// ../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isArray.js
|
|
52
|
-
var require_isArray = __commonJS({
|
|
53
|
-
"../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isArray.js"(exports, module) {
|
|
54
|
-
var isArray = Array.isArray;
|
|
55
|
-
module.exports = isArray;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// ../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isString.js
|
|
60
|
-
var require_isString = __commonJS({
|
|
61
|
-
"../../node_modules/.pnpm/lodash@4.0.0/node_modules/lodash/isString.js"(exports, module) {
|
|
62
|
-
var isArray = require_isArray();
|
|
63
|
-
var isObjectLike = require_isObjectLike();
|
|
64
|
-
var stringTag = "[object String]";
|
|
65
|
-
var objectProto = global.Object.prototype;
|
|
66
|
-
var objectToString = objectProto.toString;
|
|
67
|
-
function isString2(value) {
|
|
68
|
-
return typeof value == "string" || !isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag;
|
|
69
|
-
}
|
|
70
|
-
module.exports = isString2;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
1
|
// src/is/index.ts
|
|
75
2
|
var isBrowser = () => typeof window !== "undefined";
|
|
76
3
|
var isWeex = () => typeof WXEnvironment !== "undefined" && !!WXEnvironment.platform;
|
|
@@ -86,6 +13,14 @@ var isChrome = () => UA() && /chrome\/\d+/.test(UA()) && !isEdge();
|
|
|
86
13
|
var isPhantomJS = () => UA() && /phantomjs/.test(UA());
|
|
87
14
|
var isFF = () => typeof UA() === "string" && UA().match(/firefox\/(\d+)/);
|
|
88
15
|
var isMobile = () => isBrowser() && navigator.userAgent.toLowerCase().includes("mobile");
|
|
16
|
+
var isObject = (value) => typeof value === "object" && !Array.isArray(value);
|
|
17
|
+
var isNumber = (value) => typeof value === "number";
|
|
18
|
+
var isString = (value) => typeof value === "string";
|
|
19
|
+
var isArray = (value) => Array.isArray(value);
|
|
20
|
+
var isNull = (value) => value === null;
|
|
21
|
+
var isPlainObject = (value) => typeof value === "object" && value !== null && value.constructor === Object;
|
|
22
|
+
var isFormData = (value) => isObject(value) && isBrowser() && value instanceof FormData;
|
|
23
|
+
var isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
89
24
|
|
|
90
25
|
// src/lang/index.ts
|
|
91
26
|
function formDataToObject(formData) {
|
|
@@ -97,23 +32,13 @@ function objectToFormData(object) {
|
|
|
97
32
|
formData.append(key, value);
|
|
98
33
|
return formData;
|
|
99
34
|
}
|
|
100
|
-
function isFormData(value) {
|
|
101
|
-
return isObject(value) && isBrowser() && value instanceof FormData;
|
|
102
|
-
}
|
|
103
|
-
function isWindow(value) {
|
|
104
|
-
return typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
105
|
-
}
|
|
106
|
-
function isObject(value) {
|
|
107
|
-
return typeof value === "object" && !Array.isArray(value);
|
|
108
|
-
}
|
|
109
35
|
|
|
110
36
|
// src/size/index.ts
|
|
111
|
-
var import_isNumber = __toESM(require_isNumber());
|
|
112
|
-
var import_isString = __toESM(require_isString());
|
|
113
37
|
function formatUnit(value, unit = "px") {
|
|
114
|
-
if (!((
|
|
38
|
+
if (!(isString(value) || isNumber(value)))
|
|
115
39
|
return "";
|
|
116
|
-
|
|
40
|
+
value = String(value);
|
|
41
|
+
return /\D/g.test(value) ? value : value + unit;
|
|
117
42
|
}
|
|
118
43
|
function formatSize(dimension, unit) {
|
|
119
44
|
const _formatUnit = (value) => formatUnit(value, unit);
|
|
@@ -136,38 +61,44 @@ function isTypeof(target, type) {
|
|
|
136
61
|
}
|
|
137
62
|
|
|
138
63
|
// src/util/deferred.ts
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
resolve(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
64
|
+
var Deferred = class extends Promise {
|
|
65
|
+
constructor() {
|
|
66
|
+
let _resolve, _reject;
|
|
67
|
+
super((resolve_, reject_) => {
|
|
68
|
+
_resolve = resolve_;
|
|
69
|
+
_reject = reject_;
|
|
70
|
+
});
|
|
71
|
+
this.resolve = (value) => {
|
|
72
|
+
_resolve(value);
|
|
73
|
+
return this;
|
|
74
|
+
};
|
|
75
|
+
this.reject = (reason) => {
|
|
76
|
+
_reject(reason);
|
|
77
|
+
return this;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
};
|
|
152
81
|
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
if (functions.length === 0)
|
|
82
|
+
// src/util/pipe.ts
|
|
83
|
+
var pPipe = (...functions) => {
|
|
84
|
+
if (functions.length === 0)
|
|
156
85
|
throw new Error("Expected at least one argument");
|
|
157
|
-
}
|
|
158
86
|
return async (input) => {
|
|
159
87
|
let currentValue = input;
|
|
160
|
-
for (const function_ of functions)
|
|
88
|
+
for (const function_ of functions)
|
|
161
89
|
currentValue = await function_(currentValue);
|
|
162
|
-
}
|
|
163
90
|
return currentValue;
|
|
164
91
|
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
import { default as default2 } from "delay";
|
|
92
|
+
};
|
|
93
|
+
var pipe = (...fns) => fns.reduce((v, f) => f(v));
|
|
94
|
+
var compose = (...fns) => fns.reduceRight((v, f) => f(v));
|
|
169
95
|
|
|
170
|
-
// src/util/
|
|
96
|
+
// src/util/util.ts
|
|
97
|
+
function noop() {
|
|
98
|
+
}
|
|
99
|
+
function delay(ms) {
|
|
100
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
101
|
+
}
|
|
171
102
|
function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
172
103
|
if (!x2)
|
|
173
104
|
x1 -= x2 = x1;
|
|
@@ -175,22 +106,1621 @@ function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
|
175
106
|
z[z0++] = x1;
|
|
176
107
|
return z;
|
|
177
108
|
}
|
|
178
|
-
var pipe = (...fns) => fns.reduce((v, f) => f(v));
|
|
179
|
-
var compose = (...fns) => fns.reduceRight((v, f) => f(v));
|
|
180
109
|
function whenever(value, callback) {
|
|
181
110
|
return value ? callback(value) : void 0;
|
|
182
111
|
}
|
|
112
|
+
function loop(fn) {
|
|
113
|
+
async function next(ms) {
|
|
114
|
+
await delay(ms);
|
|
115
|
+
return fn(next);
|
|
116
|
+
}
|
|
117
|
+
return fn(next);
|
|
118
|
+
}
|
|
119
|
+
function riposte(...args) {
|
|
120
|
+
for (const [cond, value] of args) {
|
|
121
|
+
if (cond)
|
|
122
|
+
return value;
|
|
123
|
+
}
|
|
124
|
+
return void 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.mjs
|
|
128
|
+
var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
129
|
+
var mathceil = Math.ceil;
|
|
130
|
+
var mathfloor = Math.floor;
|
|
131
|
+
var bignumberError = "[BigNumber Error] ";
|
|
132
|
+
var tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ";
|
|
133
|
+
var BASE = 1e14;
|
|
134
|
+
var LOG_BASE = 14;
|
|
135
|
+
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
136
|
+
var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
|
|
137
|
+
var SQRT_BASE = 1e7;
|
|
138
|
+
var MAX = 1e9;
|
|
139
|
+
function clone(configObject) {
|
|
140
|
+
var div, convertBase, parseNumeric2, P = BigNumber2.prototype = { constructor: BigNumber2, toString: null, valueOf: null }, ONE = new BigNumber2(1), DECIMAL_PLACES = 20, ROUNDING_MODE = 4, TO_EXP_NEG = -7, TO_EXP_POS = 21, MIN_EXP = -1e7, MAX_EXP = 1e7, CRYPTO = false, MODULO_MODE = 1, POW_PRECISION = 0, FORMAT = {
|
|
141
|
+
prefix: "",
|
|
142
|
+
groupSize: 3,
|
|
143
|
+
secondaryGroupSize: 0,
|
|
144
|
+
groupSeparator: ",",
|
|
145
|
+
decimalSeparator: ".",
|
|
146
|
+
fractionGroupSize: 0,
|
|
147
|
+
fractionGroupSeparator: "\xA0",
|
|
148
|
+
// non-breaking space
|
|
149
|
+
suffix: ""
|
|
150
|
+
}, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
|
|
151
|
+
function BigNumber2(v, b) {
|
|
152
|
+
var alphabet, c, caseChanged, e, i, isNum, len, str, x = this;
|
|
153
|
+
if (!(x instanceof BigNumber2))
|
|
154
|
+
return new BigNumber2(v, b);
|
|
155
|
+
if (b == null) {
|
|
156
|
+
if (v && v._isBigNumber === true) {
|
|
157
|
+
x.s = v.s;
|
|
158
|
+
if (!v.c || v.e > MAX_EXP) {
|
|
159
|
+
x.c = x.e = null;
|
|
160
|
+
} else if (v.e < MIN_EXP) {
|
|
161
|
+
x.c = [x.e = 0];
|
|
162
|
+
} else {
|
|
163
|
+
x.e = v.e;
|
|
164
|
+
x.c = v.c.slice();
|
|
165
|
+
}
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if ((isNum = typeof v == "number") && v * 0 == 0) {
|
|
169
|
+
x.s = 1 / v < 0 ? (v = -v, -1) : 1;
|
|
170
|
+
if (v === ~~v) {
|
|
171
|
+
for (e = 0, i = v; i >= 10; i /= 10, e++)
|
|
172
|
+
;
|
|
173
|
+
if (e > MAX_EXP) {
|
|
174
|
+
x.c = x.e = null;
|
|
175
|
+
} else {
|
|
176
|
+
x.e = e;
|
|
177
|
+
x.c = [v];
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
str = String(v);
|
|
182
|
+
} else {
|
|
183
|
+
if (!isNumeric.test(str = String(v)))
|
|
184
|
+
return parseNumeric2(x, str, isNum);
|
|
185
|
+
x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
|
|
186
|
+
}
|
|
187
|
+
if ((e = str.indexOf(".")) > -1)
|
|
188
|
+
str = str.replace(".", "");
|
|
189
|
+
if ((i = str.search(/e/i)) > 0) {
|
|
190
|
+
if (e < 0)
|
|
191
|
+
e = i;
|
|
192
|
+
e += +str.slice(i + 1);
|
|
193
|
+
str = str.substring(0, i);
|
|
194
|
+
} else if (e < 0) {
|
|
195
|
+
e = str.length;
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
199
|
+
if (b == 10 && alphabetHasNormalDecimalDigits) {
|
|
200
|
+
x = new BigNumber2(v);
|
|
201
|
+
return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
|
|
202
|
+
}
|
|
203
|
+
str = String(v);
|
|
204
|
+
if (isNum = typeof v == "number") {
|
|
205
|
+
if (v * 0 != 0)
|
|
206
|
+
return parseNumeric2(x, str, isNum, b);
|
|
207
|
+
x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
|
|
208
|
+
if (BigNumber2.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) {
|
|
209
|
+
throw Error(tooManyDigits + v);
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
|
|
213
|
+
}
|
|
214
|
+
alphabet = ALPHABET.slice(0, b);
|
|
215
|
+
e = i = 0;
|
|
216
|
+
for (len = str.length; i < len; i++) {
|
|
217
|
+
if (alphabet.indexOf(c = str.charAt(i)) < 0) {
|
|
218
|
+
if (c == ".") {
|
|
219
|
+
if (i > e) {
|
|
220
|
+
e = len;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
} else if (!caseChanged) {
|
|
224
|
+
if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
|
|
225
|
+
caseChanged = true;
|
|
226
|
+
i = -1;
|
|
227
|
+
e = 0;
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return parseNumeric2(x, String(v), isNum, b);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
isNum = false;
|
|
235
|
+
str = convertBase(str, b, 10, x.s);
|
|
236
|
+
if ((e = str.indexOf(".")) > -1)
|
|
237
|
+
str = str.replace(".", "");
|
|
238
|
+
else
|
|
239
|
+
e = str.length;
|
|
240
|
+
}
|
|
241
|
+
for (i = 0; str.charCodeAt(i) === 48; i++)
|
|
242
|
+
;
|
|
243
|
+
for (len = str.length; str.charCodeAt(--len) === 48; )
|
|
244
|
+
;
|
|
245
|
+
if (str = str.slice(i, ++len)) {
|
|
246
|
+
len -= i;
|
|
247
|
+
if (isNum && BigNumber2.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
|
|
248
|
+
throw Error(tooManyDigits + x.s * v);
|
|
249
|
+
}
|
|
250
|
+
if ((e = e - i - 1) > MAX_EXP) {
|
|
251
|
+
x.c = x.e = null;
|
|
252
|
+
} else if (e < MIN_EXP) {
|
|
253
|
+
x.c = [x.e = 0];
|
|
254
|
+
} else {
|
|
255
|
+
x.e = e;
|
|
256
|
+
x.c = [];
|
|
257
|
+
i = (e + 1) % LOG_BASE;
|
|
258
|
+
if (e < 0)
|
|
259
|
+
i += LOG_BASE;
|
|
260
|
+
if (i < len) {
|
|
261
|
+
if (i)
|
|
262
|
+
x.c.push(+str.slice(0, i));
|
|
263
|
+
for (len -= LOG_BASE; i < len; ) {
|
|
264
|
+
x.c.push(+str.slice(i, i += LOG_BASE));
|
|
265
|
+
}
|
|
266
|
+
i = LOG_BASE - (str = str.slice(i)).length;
|
|
267
|
+
} else {
|
|
268
|
+
i -= len;
|
|
269
|
+
}
|
|
270
|
+
for (; i--; str += "0")
|
|
271
|
+
;
|
|
272
|
+
x.c.push(+str);
|
|
273
|
+
}
|
|
274
|
+
} else {
|
|
275
|
+
x.c = [x.e = 0];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
BigNumber2.clone = clone;
|
|
279
|
+
BigNumber2.ROUND_UP = 0;
|
|
280
|
+
BigNumber2.ROUND_DOWN = 1;
|
|
281
|
+
BigNumber2.ROUND_CEIL = 2;
|
|
282
|
+
BigNumber2.ROUND_FLOOR = 3;
|
|
283
|
+
BigNumber2.ROUND_HALF_UP = 4;
|
|
284
|
+
BigNumber2.ROUND_HALF_DOWN = 5;
|
|
285
|
+
BigNumber2.ROUND_HALF_EVEN = 6;
|
|
286
|
+
BigNumber2.ROUND_HALF_CEIL = 7;
|
|
287
|
+
BigNumber2.ROUND_HALF_FLOOR = 8;
|
|
288
|
+
BigNumber2.EUCLID = 9;
|
|
289
|
+
BigNumber2.config = BigNumber2.set = function(obj) {
|
|
290
|
+
var p, v;
|
|
291
|
+
if (obj != null) {
|
|
292
|
+
if (typeof obj == "object") {
|
|
293
|
+
if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
|
|
294
|
+
v = obj[p];
|
|
295
|
+
intCheck(v, 0, MAX, p);
|
|
296
|
+
DECIMAL_PLACES = v;
|
|
297
|
+
}
|
|
298
|
+
if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
|
|
299
|
+
v = obj[p];
|
|
300
|
+
intCheck(v, 0, 8, p);
|
|
301
|
+
ROUNDING_MODE = v;
|
|
302
|
+
}
|
|
303
|
+
if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
|
|
304
|
+
v = obj[p];
|
|
305
|
+
if (v && v.pop) {
|
|
306
|
+
intCheck(v[0], -MAX, 0, p);
|
|
307
|
+
intCheck(v[1], 0, MAX, p);
|
|
308
|
+
TO_EXP_NEG = v[0];
|
|
309
|
+
TO_EXP_POS = v[1];
|
|
310
|
+
} else {
|
|
311
|
+
intCheck(v, -MAX, MAX, p);
|
|
312
|
+
TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (obj.hasOwnProperty(p = "RANGE")) {
|
|
316
|
+
v = obj[p];
|
|
317
|
+
if (v && v.pop) {
|
|
318
|
+
intCheck(v[0], -MAX, -1, p);
|
|
319
|
+
intCheck(v[1], 1, MAX, p);
|
|
320
|
+
MIN_EXP = v[0];
|
|
321
|
+
MAX_EXP = v[1];
|
|
322
|
+
} else {
|
|
323
|
+
intCheck(v, -MAX, MAX, p);
|
|
324
|
+
if (v) {
|
|
325
|
+
MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
|
|
326
|
+
} else {
|
|
327
|
+
throw Error(bignumberError + p + " cannot be zero: " + v);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (obj.hasOwnProperty(p = "CRYPTO")) {
|
|
332
|
+
v = obj[p];
|
|
333
|
+
if (v === !!v) {
|
|
334
|
+
if (v) {
|
|
335
|
+
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
|
336
|
+
CRYPTO = v;
|
|
337
|
+
} else {
|
|
338
|
+
CRYPTO = !v;
|
|
339
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
340
|
+
}
|
|
341
|
+
} else {
|
|
342
|
+
CRYPTO = v;
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
throw Error(bignumberError + p + " not true or false: " + v);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (obj.hasOwnProperty(p = "MODULO_MODE")) {
|
|
349
|
+
v = obj[p];
|
|
350
|
+
intCheck(v, 0, 9, p);
|
|
351
|
+
MODULO_MODE = v;
|
|
352
|
+
}
|
|
353
|
+
if (obj.hasOwnProperty(p = "POW_PRECISION")) {
|
|
354
|
+
v = obj[p];
|
|
355
|
+
intCheck(v, 0, MAX, p);
|
|
356
|
+
POW_PRECISION = v;
|
|
357
|
+
}
|
|
358
|
+
if (obj.hasOwnProperty(p = "FORMAT")) {
|
|
359
|
+
v = obj[p];
|
|
360
|
+
if (typeof v == "object")
|
|
361
|
+
FORMAT = v;
|
|
362
|
+
else
|
|
363
|
+
throw Error(bignumberError + p + " not an object: " + v);
|
|
364
|
+
}
|
|
365
|
+
if (obj.hasOwnProperty(p = "ALPHABET")) {
|
|
366
|
+
v = obj[p];
|
|
367
|
+
if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
|
|
368
|
+
alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
|
|
369
|
+
ALPHABET = v;
|
|
370
|
+
} else {
|
|
371
|
+
throw Error(bignumberError + p + " invalid: " + v);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
} else {
|
|
375
|
+
throw Error(bignumberError + "Object expected: " + obj);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
DECIMAL_PLACES,
|
|
380
|
+
ROUNDING_MODE,
|
|
381
|
+
EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
|
|
382
|
+
RANGE: [MIN_EXP, MAX_EXP],
|
|
383
|
+
CRYPTO,
|
|
384
|
+
MODULO_MODE,
|
|
385
|
+
POW_PRECISION,
|
|
386
|
+
FORMAT,
|
|
387
|
+
ALPHABET
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
BigNumber2.isBigNumber = function(v) {
|
|
391
|
+
if (!v || v._isBigNumber !== true)
|
|
392
|
+
return false;
|
|
393
|
+
if (!BigNumber2.DEBUG)
|
|
394
|
+
return true;
|
|
395
|
+
var i, n, c = v.c, e = v.e, s = v.s;
|
|
396
|
+
out:
|
|
397
|
+
if ({}.toString.call(c) == "[object Array]") {
|
|
398
|
+
if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
|
|
399
|
+
if (c[0] === 0) {
|
|
400
|
+
if (e === 0 && c.length === 1)
|
|
401
|
+
return true;
|
|
402
|
+
break out;
|
|
403
|
+
}
|
|
404
|
+
i = (e + 1) % LOG_BASE;
|
|
405
|
+
if (i < 1)
|
|
406
|
+
i += LOG_BASE;
|
|
407
|
+
if (String(c[0]).length == i) {
|
|
408
|
+
for (i = 0; i < c.length; i++) {
|
|
409
|
+
n = c[i];
|
|
410
|
+
if (n < 0 || n >= BASE || n !== mathfloor(n))
|
|
411
|
+
break out;
|
|
412
|
+
}
|
|
413
|
+
if (n !== 0)
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
} else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
|
|
418
|
+
return true;
|
|
419
|
+
}
|
|
420
|
+
throw Error(bignumberError + "Invalid BigNumber: " + v);
|
|
421
|
+
};
|
|
422
|
+
BigNumber2.maximum = BigNumber2.max = function() {
|
|
423
|
+
return maxOrMin(arguments, -1);
|
|
424
|
+
};
|
|
425
|
+
BigNumber2.minimum = BigNumber2.min = function() {
|
|
426
|
+
return maxOrMin(arguments, 1);
|
|
427
|
+
};
|
|
428
|
+
BigNumber2.random = function() {
|
|
429
|
+
var pow2_53 = 9007199254740992;
|
|
430
|
+
var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
|
|
431
|
+
return mathfloor(Math.random() * pow2_53);
|
|
432
|
+
} : function() {
|
|
433
|
+
return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
|
|
434
|
+
};
|
|
435
|
+
return function(dp) {
|
|
436
|
+
var a, b, e, k, v, i = 0, c = [], rand = new BigNumber2(ONE);
|
|
437
|
+
if (dp == null)
|
|
438
|
+
dp = DECIMAL_PLACES;
|
|
439
|
+
else
|
|
440
|
+
intCheck(dp, 0, MAX);
|
|
441
|
+
k = mathceil(dp / LOG_BASE);
|
|
442
|
+
if (CRYPTO) {
|
|
443
|
+
if (crypto.getRandomValues) {
|
|
444
|
+
a = crypto.getRandomValues(new Uint32Array(k *= 2));
|
|
445
|
+
for (; i < k; ) {
|
|
446
|
+
v = a[i] * 131072 + (a[i + 1] >>> 11);
|
|
447
|
+
if (v >= 9e15) {
|
|
448
|
+
b = crypto.getRandomValues(new Uint32Array(2));
|
|
449
|
+
a[i] = b[0];
|
|
450
|
+
a[i + 1] = b[1];
|
|
451
|
+
} else {
|
|
452
|
+
c.push(v % 1e14);
|
|
453
|
+
i += 2;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
i = k / 2;
|
|
457
|
+
} else if (crypto.randomBytes) {
|
|
458
|
+
a = crypto.randomBytes(k *= 7);
|
|
459
|
+
for (; i < k; ) {
|
|
460
|
+
v = (a[i] & 31) * 281474976710656 + a[i + 1] * 1099511627776 + a[i + 2] * 4294967296 + a[i + 3] * 16777216 + (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
|
|
461
|
+
if (v >= 9e15) {
|
|
462
|
+
crypto.randomBytes(7).copy(a, i);
|
|
463
|
+
} else {
|
|
464
|
+
c.push(v % 1e14);
|
|
465
|
+
i += 7;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
i = k / 7;
|
|
469
|
+
} else {
|
|
470
|
+
CRYPTO = false;
|
|
471
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (!CRYPTO) {
|
|
475
|
+
for (; i < k; ) {
|
|
476
|
+
v = random53bitInt();
|
|
477
|
+
if (v < 9e15)
|
|
478
|
+
c[i++] = v % 1e14;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
k = c[--i];
|
|
482
|
+
dp %= LOG_BASE;
|
|
483
|
+
if (k && dp) {
|
|
484
|
+
v = POWS_TEN[LOG_BASE - dp];
|
|
485
|
+
c[i] = mathfloor(k / v) * v;
|
|
486
|
+
}
|
|
487
|
+
for (; c[i] === 0; c.pop(), i--)
|
|
488
|
+
;
|
|
489
|
+
if (i < 0) {
|
|
490
|
+
c = [e = 0];
|
|
491
|
+
} else {
|
|
492
|
+
for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE)
|
|
493
|
+
;
|
|
494
|
+
for (i = 1, v = c[0]; v >= 10; v /= 10, i++)
|
|
495
|
+
;
|
|
496
|
+
if (i < LOG_BASE)
|
|
497
|
+
e -= LOG_BASE - i;
|
|
498
|
+
}
|
|
499
|
+
rand.e = e;
|
|
500
|
+
rand.c = c;
|
|
501
|
+
return rand;
|
|
502
|
+
};
|
|
503
|
+
}();
|
|
504
|
+
BigNumber2.sum = function() {
|
|
505
|
+
var i = 1, args = arguments, sum = new BigNumber2(args[0]);
|
|
506
|
+
for (; i < args.length; )
|
|
507
|
+
sum = sum.plus(args[i++]);
|
|
508
|
+
return sum;
|
|
509
|
+
};
|
|
510
|
+
convertBase = function() {
|
|
511
|
+
var decimal2 = "0123456789";
|
|
512
|
+
function toBaseOut(str, baseIn, baseOut, alphabet) {
|
|
513
|
+
var j, arr = [0], arrL, i = 0, len = str.length;
|
|
514
|
+
for (; i < len; ) {
|
|
515
|
+
for (arrL = arr.length; arrL--; arr[arrL] *= baseIn)
|
|
516
|
+
;
|
|
517
|
+
arr[0] += alphabet.indexOf(str.charAt(i++));
|
|
518
|
+
for (j = 0; j < arr.length; j++) {
|
|
519
|
+
if (arr[j] > baseOut - 1) {
|
|
520
|
+
if (arr[j + 1] == null)
|
|
521
|
+
arr[j + 1] = 0;
|
|
522
|
+
arr[j + 1] += arr[j] / baseOut | 0;
|
|
523
|
+
arr[j] %= baseOut;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return arr.reverse();
|
|
528
|
+
}
|
|
529
|
+
return function(str, baseIn, baseOut, sign, callerIsToString) {
|
|
530
|
+
var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
|
|
531
|
+
if (i >= 0) {
|
|
532
|
+
k = POW_PRECISION;
|
|
533
|
+
POW_PRECISION = 0;
|
|
534
|
+
str = str.replace(".", "");
|
|
535
|
+
y = new BigNumber2(baseIn);
|
|
536
|
+
x = y.pow(str.length - i);
|
|
537
|
+
POW_PRECISION = k;
|
|
538
|
+
y.c = toBaseOut(
|
|
539
|
+
toFixedPoint(coeffToString(x.c), x.e, "0"),
|
|
540
|
+
10,
|
|
541
|
+
baseOut,
|
|
542
|
+
decimal2
|
|
543
|
+
);
|
|
544
|
+
y.e = y.c.length;
|
|
545
|
+
}
|
|
546
|
+
xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal2) : (alphabet = decimal2, ALPHABET));
|
|
547
|
+
e = k = xc.length;
|
|
548
|
+
for (; xc[--k] == 0; xc.pop())
|
|
549
|
+
;
|
|
550
|
+
if (!xc[0])
|
|
551
|
+
return alphabet.charAt(0);
|
|
552
|
+
if (i < 0) {
|
|
553
|
+
--e;
|
|
554
|
+
} else {
|
|
555
|
+
x.c = xc;
|
|
556
|
+
x.e = e;
|
|
557
|
+
x.s = sign;
|
|
558
|
+
x = div(x, y, dp, rm, baseOut);
|
|
559
|
+
xc = x.c;
|
|
560
|
+
r = x.r;
|
|
561
|
+
e = x.e;
|
|
562
|
+
}
|
|
563
|
+
d = e + dp + 1;
|
|
564
|
+
i = xc[d];
|
|
565
|
+
k = baseOut / 2;
|
|
566
|
+
r = r || d < 0 || xc[d + 1] != null;
|
|
567
|
+
r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : i > k || i == k && (rm == 4 || r || rm == 6 && xc[d - 1] & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
568
|
+
if (d < 1 || !xc[0]) {
|
|
569
|
+
str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
|
|
570
|
+
} else {
|
|
571
|
+
xc.length = d;
|
|
572
|
+
if (r) {
|
|
573
|
+
for (--baseOut; ++xc[--d] > baseOut; ) {
|
|
574
|
+
xc[d] = 0;
|
|
575
|
+
if (!d) {
|
|
576
|
+
++e;
|
|
577
|
+
xc = [1].concat(xc);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
for (k = xc.length; !xc[--k]; )
|
|
582
|
+
;
|
|
583
|
+
for (i = 0, str = ""; i <= k; str += alphabet.charAt(xc[i++]))
|
|
584
|
+
;
|
|
585
|
+
str = toFixedPoint(str, e, alphabet.charAt(0));
|
|
586
|
+
}
|
|
587
|
+
return str;
|
|
588
|
+
};
|
|
589
|
+
}();
|
|
590
|
+
div = function() {
|
|
591
|
+
function multiply(x, k, base) {
|
|
592
|
+
var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
|
|
593
|
+
for (x = x.slice(); i--; ) {
|
|
594
|
+
xlo = x[i] % SQRT_BASE;
|
|
595
|
+
xhi = x[i] / SQRT_BASE | 0;
|
|
596
|
+
m = khi * xlo + xhi * klo;
|
|
597
|
+
temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
|
|
598
|
+
carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
|
|
599
|
+
x[i] = temp % base;
|
|
600
|
+
}
|
|
601
|
+
if (carry)
|
|
602
|
+
x = [carry].concat(x);
|
|
603
|
+
return x;
|
|
604
|
+
}
|
|
605
|
+
function compare2(a, b, aL, bL) {
|
|
606
|
+
var i, cmp;
|
|
607
|
+
if (aL != bL) {
|
|
608
|
+
cmp = aL > bL ? 1 : -1;
|
|
609
|
+
} else {
|
|
610
|
+
for (i = cmp = 0; i < aL; i++) {
|
|
611
|
+
if (a[i] != b[i]) {
|
|
612
|
+
cmp = a[i] > b[i] ? 1 : -1;
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return cmp;
|
|
618
|
+
}
|
|
619
|
+
function subtract(a, b, aL, base) {
|
|
620
|
+
var i = 0;
|
|
621
|
+
for (; aL--; ) {
|
|
622
|
+
a[aL] -= i;
|
|
623
|
+
i = a[aL] < b[aL] ? 1 : 0;
|
|
624
|
+
a[aL] = i * base + a[aL] - b[aL];
|
|
625
|
+
}
|
|
626
|
+
for (; !a[0] && a.length > 1; a.splice(0, 1))
|
|
627
|
+
;
|
|
628
|
+
}
|
|
629
|
+
return function(x, y, dp, rm, base) {
|
|
630
|
+
var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0, yL, yz, s = x.s == y.s ? 1 : -1, xc = x.c, yc = y.c;
|
|
631
|
+
if (!xc || !xc[0] || !yc || !yc[0]) {
|
|
632
|
+
return new BigNumber2(
|
|
633
|
+
// Return NaN if either NaN, or both Infinity or 0.
|
|
634
|
+
!x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : (
|
|
635
|
+
// Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
|
|
636
|
+
xc && xc[0] == 0 || !yc ? s * 0 : s / 0
|
|
637
|
+
)
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
q = new BigNumber2(s);
|
|
641
|
+
qc = q.c = [];
|
|
642
|
+
e = x.e - y.e;
|
|
643
|
+
s = dp + e + 1;
|
|
644
|
+
if (!base) {
|
|
645
|
+
base = BASE;
|
|
646
|
+
e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
|
|
647
|
+
s = s / LOG_BASE | 0;
|
|
648
|
+
}
|
|
649
|
+
for (i = 0; yc[i] == (xc[i] || 0); i++)
|
|
650
|
+
;
|
|
651
|
+
if (yc[i] > (xc[i] || 0))
|
|
652
|
+
e--;
|
|
653
|
+
if (s < 0) {
|
|
654
|
+
qc.push(1);
|
|
655
|
+
more = true;
|
|
656
|
+
} else {
|
|
657
|
+
xL = xc.length;
|
|
658
|
+
yL = yc.length;
|
|
659
|
+
i = 0;
|
|
660
|
+
s += 2;
|
|
661
|
+
n = mathfloor(base / (yc[0] + 1));
|
|
662
|
+
if (n > 1) {
|
|
663
|
+
yc = multiply(yc, n, base);
|
|
664
|
+
xc = multiply(xc, n, base);
|
|
665
|
+
yL = yc.length;
|
|
666
|
+
xL = xc.length;
|
|
667
|
+
}
|
|
668
|
+
xi = yL;
|
|
669
|
+
rem = xc.slice(0, yL);
|
|
670
|
+
remL = rem.length;
|
|
671
|
+
for (; remL < yL; rem[remL++] = 0)
|
|
672
|
+
;
|
|
673
|
+
yz = yc.slice();
|
|
674
|
+
yz = [0].concat(yz);
|
|
675
|
+
yc0 = yc[0];
|
|
676
|
+
if (yc[1] >= base / 2)
|
|
677
|
+
yc0++;
|
|
678
|
+
do {
|
|
679
|
+
n = 0;
|
|
680
|
+
cmp = compare2(yc, rem, yL, remL);
|
|
681
|
+
if (cmp < 0) {
|
|
682
|
+
rem0 = rem[0];
|
|
683
|
+
if (yL != remL)
|
|
684
|
+
rem0 = rem0 * base + (rem[1] || 0);
|
|
685
|
+
n = mathfloor(rem0 / yc0);
|
|
686
|
+
if (n > 1) {
|
|
687
|
+
if (n >= base)
|
|
688
|
+
n = base - 1;
|
|
689
|
+
prod = multiply(yc, n, base);
|
|
690
|
+
prodL = prod.length;
|
|
691
|
+
remL = rem.length;
|
|
692
|
+
while (compare2(prod, rem, prodL, remL) == 1) {
|
|
693
|
+
n--;
|
|
694
|
+
subtract(prod, yL < prodL ? yz : yc, prodL, base);
|
|
695
|
+
prodL = prod.length;
|
|
696
|
+
cmp = 1;
|
|
697
|
+
}
|
|
698
|
+
} else {
|
|
699
|
+
if (n == 0) {
|
|
700
|
+
cmp = n = 1;
|
|
701
|
+
}
|
|
702
|
+
prod = yc.slice();
|
|
703
|
+
prodL = prod.length;
|
|
704
|
+
}
|
|
705
|
+
if (prodL < remL)
|
|
706
|
+
prod = [0].concat(prod);
|
|
707
|
+
subtract(rem, prod, remL, base);
|
|
708
|
+
remL = rem.length;
|
|
709
|
+
if (cmp == -1) {
|
|
710
|
+
while (compare2(yc, rem, yL, remL) < 1) {
|
|
711
|
+
n++;
|
|
712
|
+
subtract(rem, yL < remL ? yz : yc, remL, base);
|
|
713
|
+
remL = rem.length;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
} else if (cmp === 0) {
|
|
717
|
+
n++;
|
|
718
|
+
rem = [0];
|
|
719
|
+
}
|
|
720
|
+
qc[i++] = n;
|
|
721
|
+
if (rem[0]) {
|
|
722
|
+
rem[remL++] = xc[xi] || 0;
|
|
723
|
+
} else {
|
|
724
|
+
rem = [xc[xi]];
|
|
725
|
+
remL = 1;
|
|
726
|
+
}
|
|
727
|
+
} while ((xi++ < xL || rem[0] != null) && s--);
|
|
728
|
+
more = rem[0] != null;
|
|
729
|
+
if (!qc[0])
|
|
730
|
+
qc.splice(0, 1);
|
|
731
|
+
}
|
|
732
|
+
if (base == BASE) {
|
|
733
|
+
for (i = 1, s = qc[0]; s >= 10; s /= 10, i++)
|
|
734
|
+
;
|
|
735
|
+
round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
|
|
736
|
+
} else {
|
|
737
|
+
q.e = e;
|
|
738
|
+
q.r = +more;
|
|
739
|
+
}
|
|
740
|
+
return q;
|
|
741
|
+
};
|
|
742
|
+
}();
|
|
743
|
+
function format(n, i, rm, id) {
|
|
744
|
+
var c0, e, ne, len, str;
|
|
745
|
+
if (rm == null)
|
|
746
|
+
rm = ROUNDING_MODE;
|
|
747
|
+
else
|
|
748
|
+
intCheck(rm, 0, 8);
|
|
749
|
+
if (!n.c)
|
|
750
|
+
return n.toString();
|
|
751
|
+
c0 = n.c[0];
|
|
752
|
+
ne = n.e;
|
|
753
|
+
if (i == null) {
|
|
754
|
+
str = coeffToString(n.c);
|
|
755
|
+
str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
|
|
756
|
+
} else {
|
|
757
|
+
n = round(new BigNumber2(n), i, rm);
|
|
758
|
+
e = n.e;
|
|
759
|
+
str = coeffToString(n.c);
|
|
760
|
+
len = str.length;
|
|
761
|
+
if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
|
|
762
|
+
for (; len < i; str += "0", len++)
|
|
763
|
+
;
|
|
764
|
+
str = toExponential(str, e);
|
|
765
|
+
} else {
|
|
766
|
+
i -= ne;
|
|
767
|
+
str = toFixedPoint(str, e, "0");
|
|
768
|
+
if (e + 1 > len) {
|
|
769
|
+
if (--i > 0)
|
|
770
|
+
for (str += "."; i--; str += "0")
|
|
771
|
+
;
|
|
772
|
+
} else {
|
|
773
|
+
i += e - len;
|
|
774
|
+
if (i > 0) {
|
|
775
|
+
if (e + 1 == len)
|
|
776
|
+
str += ".";
|
|
777
|
+
for (; i--; str += "0")
|
|
778
|
+
;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
return n.s < 0 && c0 ? "-" + str : str;
|
|
784
|
+
}
|
|
785
|
+
function maxOrMin(args, n) {
|
|
786
|
+
var k, y, i = 1, x = new BigNumber2(args[0]);
|
|
787
|
+
for (; i < args.length; i++) {
|
|
788
|
+
y = new BigNumber2(args[i]);
|
|
789
|
+
if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) {
|
|
790
|
+
x = y;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
return x;
|
|
794
|
+
}
|
|
795
|
+
function normalise(n, c, e) {
|
|
796
|
+
var i = 1, j = c.length;
|
|
797
|
+
for (; !c[--j]; c.pop())
|
|
798
|
+
;
|
|
799
|
+
for (j = c[0]; j >= 10; j /= 10, i++)
|
|
800
|
+
;
|
|
801
|
+
if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
|
|
802
|
+
n.c = n.e = null;
|
|
803
|
+
} else if (e < MIN_EXP) {
|
|
804
|
+
n.c = [n.e = 0];
|
|
805
|
+
} else {
|
|
806
|
+
n.e = e;
|
|
807
|
+
n.c = c;
|
|
808
|
+
}
|
|
809
|
+
return n;
|
|
810
|
+
}
|
|
811
|
+
parseNumeric2 = function() {
|
|
812
|
+
var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
|
|
813
|
+
return function(x, str, isNum, b) {
|
|
814
|
+
var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
|
|
815
|
+
if (isInfinityOrNaN.test(s)) {
|
|
816
|
+
x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
|
|
817
|
+
} else {
|
|
818
|
+
if (!isNum) {
|
|
819
|
+
s = s.replace(basePrefix, function(m, p1, p2) {
|
|
820
|
+
base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
|
|
821
|
+
return !b || b == base ? p1 : m;
|
|
822
|
+
});
|
|
823
|
+
if (b) {
|
|
824
|
+
base = b;
|
|
825
|
+
s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
|
|
826
|
+
}
|
|
827
|
+
if (str != s)
|
|
828
|
+
return new BigNumber2(s, base);
|
|
829
|
+
}
|
|
830
|
+
if (BigNumber2.DEBUG) {
|
|
831
|
+
throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
|
|
832
|
+
}
|
|
833
|
+
x.s = null;
|
|
834
|
+
}
|
|
835
|
+
x.c = x.e = null;
|
|
836
|
+
};
|
|
837
|
+
}();
|
|
838
|
+
function round(x, sd, rm, r) {
|
|
839
|
+
var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
|
|
840
|
+
if (xc) {
|
|
841
|
+
out: {
|
|
842
|
+
for (d = 1, k = xc[0]; k >= 10; k /= 10, d++)
|
|
843
|
+
;
|
|
844
|
+
i = sd - d;
|
|
845
|
+
if (i < 0) {
|
|
846
|
+
i += LOG_BASE;
|
|
847
|
+
j = sd;
|
|
848
|
+
n = xc[ni = 0];
|
|
849
|
+
rd = mathfloor(n / pows10[d - j - 1] % 10);
|
|
850
|
+
} else {
|
|
851
|
+
ni = mathceil((i + 1) / LOG_BASE);
|
|
852
|
+
if (ni >= xc.length) {
|
|
853
|
+
if (r) {
|
|
854
|
+
for (; xc.length <= ni; xc.push(0))
|
|
855
|
+
;
|
|
856
|
+
n = rd = 0;
|
|
857
|
+
d = 1;
|
|
858
|
+
i %= LOG_BASE;
|
|
859
|
+
j = i - LOG_BASE + 1;
|
|
860
|
+
} else {
|
|
861
|
+
break out;
|
|
862
|
+
}
|
|
863
|
+
} else {
|
|
864
|
+
n = k = xc[ni];
|
|
865
|
+
for (d = 1; k >= 10; k /= 10, d++)
|
|
866
|
+
;
|
|
867
|
+
i %= LOG_BASE;
|
|
868
|
+
j = i - LOG_BASE + d;
|
|
869
|
+
rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
r = r || sd < 0 || // Are there any non-zero digits after the rounding digit?
|
|
873
|
+
// The expression n % pows10[d - j - 1] returns all digits of n to the right
|
|
874
|
+
// of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
|
|
875
|
+
xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
|
|
876
|
+
r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
|
|
877
|
+
(i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
878
|
+
if (sd < 1 || !xc[0]) {
|
|
879
|
+
xc.length = 0;
|
|
880
|
+
if (r) {
|
|
881
|
+
sd -= x.e + 1;
|
|
882
|
+
xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
|
|
883
|
+
x.e = -sd || 0;
|
|
884
|
+
} else {
|
|
885
|
+
xc[0] = x.e = 0;
|
|
886
|
+
}
|
|
887
|
+
return x;
|
|
888
|
+
}
|
|
889
|
+
if (i == 0) {
|
|
890
|
+
xc.length = ni;
|
|
891
|
+
k = 1;
|
|
892
|
+
ni--;
|
|
893
|
+
} else {
|
|
894
|
+
xc.length = ni + 1;
|
|
895
|
+
k = pows10[LOG_BASE - i];
|
|
896
|
+
xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
|
|
897
|
+
}
|
|
898
|
+
if (r) {
|
|
899
|
+
for (; ; ) {
|
|
900
|
+
if (ni == 0) {
|
|
901
|
+
for (i = 1, j = xc[0]; j >= 10; j /= 10, i++)
|
|
902
|
+
;
|
|
903
|
+
j = xc[0] += k;
|
|
904
|
+
for (k = 1; j >= 10; j /= 10, k++)
|
|
905
|
+
;
|
|
906
|
+
if (i != k) {
|
|
907
|
+
x.e++;
|
|
908
|
+
if (xc[0] == BASE)
|
|
909
|
+
xc[0] = 1;
|
|
910
|
+
}
|
|
911
|
+
break;
|
|
912
|
+
} else {
|
|
913
|
+
xc[ni] += k;
|
|
914
|
+
if (xc[ni] != BASE)
|
|
915
|
+
break;
|
|
916
|
+
xc[ni--] = 0;
|
|
917
|
+
k = 1;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
for (i = xc.length; xc[--i] === 0; xc.pop())
|
|
922
|
+
;
|
|
923
|
+
}
|
|
924
|
+
if (x.e > MAX_EXP) {
|
|
925
|
+
x.c = x.e = null;
|
|
926
|
+
} else if (x.e < MIN_EXP) {
|
|
927
|
+
x.c = [x.e = 0];
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
return x;
|
|
931
|
+
}
|
|
932
|
+
function valueOf(n) {
|
|
933
|
+
var str, e = n.e;
|
|
934
|
+
if (e === null)
|
|
935
|
+
return n.toString();
|
|
936
|
+
str = coeffToString(n.c);
|
|
937
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
|
|
938
|
+
return n.s < 0 ? "-" + str : str;
|
|
939
|
+
}
|
|
940
|
+
P.absoluteValue = P.abs = function() {
|
|
941
|
+
var x = new BigNumber2(this);
|
|
942
|
+
if (x.s < 0)
|
|
943
|
+
x.s = 1;
|
|
944
|
+
return x;
|
|
945
|
+
};
|
|
946
|
+
P.comparedTo = function(y, b) {
|
|
947
|
+
return compare(this, new BigNumber2(y, b));
|
|
948
|
+
};
|
|
949
|
+
P.decimalPlaces = P.dp = function(dp, rm) {
|
|
950
|
+
var c, n, v, x = this;
|
|
951
|
+
if (dp != null) {
|
|
952
|
+
intCheck(dp, 0, MAX);
|
|
953
|
+
if (rm == null)
|
|
954
|
+
rm = ROUNDING_MODE;
|
|
955
|
+
else
|
|
956
|
+
intCheck(rm, 0, 8);
|
|
957
|
+
return round(new BigNumber2(x), dp + x.e + 1, rm);
|
|
958
|
+
}
|
|
959
|
+
if (!(c = x.c))
|
|
960
|
+
return null;
|
|
961
|
+
n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
962
|
+
if (v = c[v])
|
|
963
|
+
for (; v % 10 == 0; v /= 10, n--)
|
|
964
|
+
;
|
|
965
|
+
if (n < 0)
|
|
966
|
+
n = 0;
|
|
967
|
+
return n;
|
|
968
|
+
};
|
|
969
|
+
P.dividedBy = P.div = function(y, b) {
|
|
970
|
+
return div(this, new BigNumber2(y, b), DECIMAL_PLACES, ROUNDING_MODE);
|
|
971
|
+
};
|
|
972
|
+
P.dividedToIntegerBy = P.idiv = function(y, b) {
|
|
973
|
+
return div(this, new BigNumber2(y, b), 0, 1);
|
|
974
|
+
};
|
|
975
|
+
P.exponentiatedBy = P.pow = function(n, m) {
|
|
976
|
+
var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
|
|
977
|
+
n = new BigNumber2(n);
|
|
978
|
+
if (n.c && !n.isInteger()) {
|
|
979
|
+
throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
|
|
980
|
+
}
|
|
981
|
+
if (m != null)
|
|
982
|
+
m = new BigNumber2(m);
|
|
983
|
+
nIsBig = n.e > 14;
|
|
984
|
+
if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
|
|
985
|
+
y = new BigNumber2(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
|
|
986
|
+
return m ? y.mod(m) : y;
|
|
987
|
+
}
|
|
988
|
+
nIsNeg = n.s < 0;
|
|
989
|
+
if (m) {
|
|
990
|
+
if (m.c ? !m.c[0] : !m.s)
|
|
991
|
+
return new BigNumber2(NaN);
|
|
992
|
+
isModExp = !nIsNeg && x.isInteger() && m.isInteger();
|
|
993
|
+
if (isModExp)
|
|
994
|
+
x = x.mod(m);
|
|
995
|
+
} else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0 ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7 : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
|
|
996
|
+
k = x.s < 0 && isOdd(n) ? -0 : 0;
|
|
997
|
+
if (x.e > -1)
|
|
998
|
+
k = 1 / k;
|
|
999
|
+
return new BigNumber2(nIsNeg ? 1 / k : k);
|
|
1000
|
+
} else if (POW_PRECISION) {
|
|
1001
|
+
k = mathceil(POW_PRECISION / LOG_BASE + 2);
|
|
1002
|
+
}
|
|
1003
|
+
if (nIsBig) {
|
|
1004
|
+
half = new BigNumber2(0.5);
|
|
1005
|
+
if (nIsNeg)
|
|
1006
|
+
n.s = 1;
|
|
1007
|
+
nIsOdd = isOdd(n);
|
|
1008
|
+
} else {
|
|
1009
|
+
i = Math.abs(+valueOf(n));
|
|
1010
|
+
nIsOdd = i % 2;
|
|
1011
|
+
}
|
|
1012
|
+
y = new BigNumber2(ONE);
|
|
1013
|
+
for (; ; ) {
|
|
1014
|
+
if (nIsOdd) {
|
|
1015
|
+
y = y.times(x);
|
|
1016
|
+
if (!y.c)
|
|
1017
|
+
break;
|
|
1018
|
+
if (k) {
|
|
1019
|
+
if (y.c.length > k)
|
|
1020
|
+
y.c.length = k;
|
|
1021
|
+
} else if (isModExp) {
|
|
1022
|
+
y = y.mod(m);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
if (i) {
|
|
1026
|
+
i = mathfloor(i / 2);
|
|
1027
|
+
if (i === 0)
|
|
1028
|
+
break;
|
|
1029
|
+
nIsOdd = i % 2;
|
|
1030
|
+
} else {
|
|
1031
|
+
n = n.times(half);
|
|
1032
|
+
round(n, n.e + 1, 1);
|
|
1033
|
+
if (n.e > 14) {
|
|
1034
|
+
nIsOdd = isOdd(n);
|
|
1035
|
+
} else {
|
|
1036
|
+
i = +valueOf(n);
|
|
1037
|
+
if (i === 0)
|
|
1038
|
+
break;
|
|
1039
|
+
nIsOdd = i % 2;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
x = x.times(x);
|
|
1043
|
+
if (k) {
|
|
1044
|
+
if (x.c && x.c.length > k)
|
|
1045
|
+
x.c.length = k;
|
|
1046
|
+
} else if (isModExp) {
|
|
1047
|
+
x = x.mod(m);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
if (isModExp)
|
|
1051
|
+
return y;
|
|
1052
|
+
if (nIsNeg)
|
|
1053
|
+
y = ONE.div(y);
|
|
1054
|
+
return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
|
|
1055
|
+
};
|
|
1056
|
+
P.integerValue = function(rm) {
|
|
1057
|
+
var n = new BigNumber2(this);
|
|
1058
|
+
if (rm == null)
|
|
1059
|
+
rm = ROUNDING_MODE;
|
|
1060
|
+
else
|
|
1061
|
+
intCheck(rm, 0, 8);
|
|
1062
|
+
return round(n, n.e + 1, rm);
|
|
1063
|
+
};
|
|
1064
|
+
P.isEqualTo = P.eq = function(y, b) {
|
|
1065
|
+
return compare(this, new BigNumber2(y, b)) === 0;
|
|
1066
|
+
};
|
|
1067
|
+
P.isFinite = function() {
|
|
1068
|
+
return !!this.c;
|
|
1069
|
+
};
|
|
1070
|
+
P.isGreaterThan = P.gt = function(y, b) {
|
|
1071
|
+
return compare(this, new BigNumber2(y, b)) > 0;
|
|
1072
|
+
};
|
|
1073
|
+
P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
|
|
1074
|
+
return (b = compare(this, new BigNumber2(y, b))) === 1 || b === 0;
|
|
1075
|
+
};
|
|
1076
|
+
P.isInteger = function() {
|
|
1077
|
+
return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
|
|
1078
|
+
};
|
|
1079
|
+
P.isLessThan = P.lt = function(y, b) {
|
|
1080
|
+
return compare(this, new BigNumber2(y, b)) < 0;
|
|
1081
|
+
};
|
|
1082
|
+
P.isLessThanOrEqualTo = P.lte = function(y, b) {
|
|
1083
|
+
return (b = compare(this, new BigNumber2(y, b))) === -1 || b === 0;
|
|
1084
|
+
};
|
|
1085
|
+
P.isNaN = function() {
|
|
1086
|
+
return !this.s;
|
|
1087
|
+
};
|
|
1088
|
+
P.isNegative = function() {
|
|
1089
|
+
return this.s < 0;
|
|
1090
|
+
};
|
|
1091
|
+
P.isPositive = function() {
|
|
1092
|
+
return this.s > 0;
|
|
1093
|
+
};
|
|
1094
|
+
P.isZero = function() {
|
|
1095
|
+
return !!this.c && this.c[0] == 0;
|
|
1096
|
+
};
|
|
1097
|
+
P.minus = function(y, b) {
|
|
1098
|
+
var i, j, t, xLTy, x = this, a = x.s;
|
|
1099
|
+
y = new BigNumber2(y, b);
|
|
1100
|
+
b = y.s;
|
|
1101
|
+
if (!a || !b)
|
|
1102
|
+
return new BigNumber2(NaN);
|
|
1103
|
+
if (a != b) {
|
|
1104
|
+
y.s = -b;
|
|
1105
|
+
return x.plus(y);
|
|
1106
|
+
}
|
|
1107
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
1108
|
+
if (!xe || !ye) {
|
|
1109
|
+
if (!xc || !yc)
|
|
1110
|
+
return xc ? (y.s = -b, y) : new BigNumber2(yc ? x : NaN);
|
|
1111
|
+
if (!xc[0] || !yc[0]) {
|
|
1112
|
+
return yc[0] ? (y.s = -b, y) : new BigNumber2(xc[0] ? x : (
|
|
1113
|
+
// IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
|
|
1114
|
+
ROUNDING_MODE == 3 ? -0 : 0
|
|
1115
|
+
));
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
xe = bitFloor(xe);
|
|
1119
|
+
ye = bitFloor(ye);
|
|
1120
|
+
xc = xc.slice();
|
|
1121
|
+
if (a = xe - ye) {
|
|
1122
|
+
if (xLTy = a < 0) {
|
|
1123
|
+
a = -a;
|
|
1124
|
+
t = xc;
|
|
1125
|
+
} else {
|
|
1126
|
+
ye = xe;
|
|
1127
|
+
t = yc;
|
|
1128
|
+
}
|
|
1129
|
+
t.reverse();
|
|
1130
|
+
for (b = a; b--; t.push(0))
|
|
1131
|
+
;
|
|
1132
|
+
t.reverse();
|
|
1133
|
+
} else {
|
|
1134
|
+
j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
|
|
1135
|
+
for (a = b = 0; b < j; b++) {
|
|
1136
|
+
if (xc[b] != yc[b]) {
|
|
1137
|
+
xLTy = xc[b] < yc[b];
|
|
1138
|
+
break;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
if (xLTy) {
|
|
1143
|
+
t = xc;
|
|
1144
|
+
xc = yc;
|
|
1145
|
+
yc = t;
|
|
1146
|
+
y.s = -y.s;
|
|
1147
|
+
}
|
|
1148
|
+
b = (j = yc.length) - (i = xc.length);
|
|
1149
|
+
if (b > 0)
|
|
1150
|
+
for (; b--; xc[i++] = 0)
|
|
1151
|
+
;
|
|
1152
|
+
b = BASE - 1;
|
|
1153
|
+
for (; j > a; ) {
|
|
1154
|
+
if (xc[--j] < yc[j]) {
|
|
1155
|
+
for (i = j; i && !xc[--i]; xc[i] = b)
|
|
1156
|
+
;
|
|
1157
|
+
--xc[i];
|
|
1158
|
+
xc[j] += BASE;
|
|
1159
|
+
}
|
|
1160
|
+
xc[j] -= yc[j];
|
|
1161
|
+
}
|
|
1162
|
+
for (; xc[0] == 0; xc.splice(0, 1), --ye)
|
|
1163
|
+
;
|
|
1164
|
+
if (!xc[0]) {
|
|
1165
|
+
y.s = ROUNDING_MODE == 3 ? -1 : 1;
|
|
1166
|
+
y.c = [y.e = 0];
|
|
1167
|
+
return y;
|
|
1168
|
+
}
|
|
1169
|
+
return normalise(y, xc, ye);
|
|
1170
|
+
};
|
|
1171
|
+
P.modulo = P.mod = function(y, b) {
|
|
1172
|
+
var q, s, x = this;
|
|
1173
|
+
y = new BigNumber2(y, b);
|
|
1174
|
+
if (!x.c || !y.s || y.c && !y.c[0]) {
|
|
1175
|
+
return new BigNumber2(NaN);
|
|
1176
|
+
} else if (!y.c || x.c && !x.c[0]) {
|
|
1177
|
+
return new BigNumber2(x);
|
|
1178
|
+
}
|
|
1179
|
+
if (MODULO_MODE == 9) {
|
|
1180
|
+
s = y.s;
|
|
1181
|
+
y.s = 1;
|
|
1182
|
+
q = div(x, y, 0, 3);
|
|
1183
|
+
y.s = s;
|
|
1184
|
+
q.s *= s;
|
|
1185
|
+
} else {
|
|
1186
|
+
q = div(x, y, 0, MODULO_MODE);
|
|
1187
|
+
}
|
|
1188
|
+
y = x.minus(q.times(y));
|
|
1189
|
+
if (!y.c[0] && MODULO_MODE == 1)
|
|
1190
|
+
y.s = x.s;
|
|
1191
|
+
return y;
|
|
1192
|
+
};
|
|
1193
|
+
P.multipliedBy = P.times = function(y, b) {
|
|
1194
|
+
var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc, base, sqrtBase, x = this, xc = x.c, yc = (y = new BigNumber2(y, b)).c;
|
|
1195
|
+
if (!xc || !yc || !xc[0] || !yc[0]) {
|
|
1196
|
+
if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
|
|
1197
|
+
y.c = y.e = y.s = null;
|
|
1198
|
+
} else {
|
|
1199
|
+
y.s *= x.s;
|
|
1200
|
+
if (!xc || !yc) {
|
|
1201
|
+
y.c = y.e = null;
|
|
1202
|
+
} else {
|
|
1203
|
+
y.c = [0];
|
|
1204
|
+
y.e = 0;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
return y;
|
|
1208
|
+
}
|
|
1209
|
+
e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
|
|
1210
|
+
y.s *= x.s;
|
|
1211
|
+
xcL = xc.length;
|
|
1212
|
+
ycL = yc.length;
|
|
1213
|
+
if (xcL < ycL) {
|
|
1214
|
+
zc = xc;
|
|
1215
|
+
xc = yc;
|
|
1216
|
+
yc = zc;
|
|
1217
|
+
i = xcL;
|
|
1218
|
+
xcL = ycL;
|
|
1219
|
+
ycL = i;
|
|
1220
|
+
}
|
|
1221
|
+
for (i = xcL + ycL, zc = []; i--; zc.push(0))
|
|
1222
|
+
;
|
|
1223
|
+
base = BASE;
|
|
1224
|
+
sqrtBase = SQRT_BASE;
|
|
1225
|
+
for (i = ycL; --i >= 0; ) {
|
|
1226
|
+
c = 0;
|
|
1227
|
+
ylo = yc[i] % sqrtBase;
|
|
1228
|
+
yhi = yc[i] / sqrtBase | 0;
|
|
1229
|
+
for (k = xcL, j = i + k; j > i; ) {
|
|
1230
|
+
xlo = xc[--k] % sqrtBase;
|
|
1231
|
+
xhi = xc[k] / sqrtBase | 0;
|
|
1232
|
+
m = yhi * xlo + xhi * ylo;
|
|
1233
|
+
xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
|
|
1234
|
+
c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
|
|
1235
|
+
zc[j--] = xlo % base;
|
|
1236
|
+
}
|
|
1237
|
+
zc[j] = c;
|
|
1238
|
+
}
|
|
1239
|
+
if (c) {
|
|
1240
|
+
++e;
|
|
1241
|
+
} else {
|
|
1242
|
+
zc.splice(0, 1);
|
|
1243
|
+
}
|
|
1244
|
+
return normalise(y, zc, e);
|
|
1245
|
+
};
|
|
1246
|
+
P.negated = function() {
|
|
1247
|
+
var x = new BigNumber2(this);
|
|
1248
|
+
x.s = -x.s || null;
|
|
1249
|
+
return x;
|
|
1250
|
+
};
|
|
1251
|
+
P.plus = function(y, b) {
|
|
1252
|
+
var t, x = this, a = x.s;
|
|
1253
|
+
y = new BigNumber2(y, b);
|
|
1254
|
+
b = y.s;
|
|
1255
|
+
if (!a || !b)
|
|
1256
|
+
return new BigNumber2(NaN);
|
|
1257
|
+
if (a != b) {
|
|
1258
|
+
y.s = -b;
|
|
1259
|
+
return x.minus(y);
|
|
1260
|
+
}
|
|
1261
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
1262
|
+
if (!xe || !ye) {
|
|
1263
|
+
if (!xc || !yc)
|
|
1264
|
+
return new BigNumber2(a / 0);
|
|
1265
|
+
if (!xc[0] || !yc[0])
|
|
1266
|
+
return yc[0] ? y : new BigNumber2(xc[0] ? x : a * 0);
|
|
1267
|
+
}
|
|
1268
|
+
xe = bitFloor(xe);
|
|
1269
|
+
ye = bitFloor(ye);
|
|
1270
|
+
xc = xc.slice();
|
|
1271
|
+
if (a = xe - ye) {
|
|
1272
|
+
if (a > 0) {
|
|
1273
|
+
ye = xe;
|
|
1274
|
+
t = yc;
|
|
1275
|
+
} else {
|
|
1276
|
+
a = -a;
|
|
1277
|
+
t = xc;
|
|
1278
|
+
}
|
|
1279
|
+
t.reverse();
|
|
1280
|
+
for (; a--; t.push(0))
|
|
1281
|
+
;
|
|
1282
|
+
t.reverse();
|
|
1283
|
+
}
|
|
1284
|
+
a = xc.length;
|
|
1285
|
+
b = yc.length;
|
|
1286
|
+
if (a - b < 0) {
|
|
1287
|
+
t = yc;
|
|
1288
|
+
yc = xc;
|
|
1289
|
+
xc = t;
|
|
1290
|
+
b = a;
|
|
1291
|
+
}
|
|
1292
|
+
for (a = 0; b; ) {
|
|
1293
|
+
a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
|
|
1294
|
+
xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
|
|
1295
|
+
}
|
|
1296
|
+
if (a) {
|
|
1297
|
+
xc = [a].concat(xc);
|
|
1298
|
+
++ye;
|
|
1299
|
+
}
|
|
1300
|
+
return normalise(y, xc, ye);
|
|
1301
|
+
};
|
|
1302
|
+
P.precision = P.sd = function(sd, rm) {
|
|
1303
|
+
var c, n, v, x = this;
|
|
1304
|
+
if (sd != null && sd !== !!sd) {
|
|
1305
|
+
intCheck(sd, 1, MAX);
|
|
1306
|
+
if (rm == null)
|
|
1307
|
+
rm = ROUNDING_MODE;
|
|
1308
|
+
else
|
|
1309
|
+
intCheck(rm, 0, 8);
|
|
1310
|
+
return round(new BigNumber2(x), sd, rm);
|
|
1311
|
+
}
|
|
1312
|
+
if (!(c = x.c))
|
|
1313
|
+
return null;
|
|
1314
|
+
v = c.length - 1;
|
|
1315
|
+
n = v * LOG_BASE + 1;
|
|
1316
|
+
if (v = c[v]) {
|
|
1317
|
+
for (; v % 10 == 0; v /= 10, n--)
|
|
1318
|
+
;
|
|
1319
|
+
for (v = c[0]; v >= 10; v /= 10, n++)
|
|
1320
|
+
;
|
|
1321
|
+
}
|
|
1322
|
+
if (sd && x.e + 1 > n)
|
|
1323
|
+
n = x.e + 1;
|
|
1324
|
+
return n;
|
|
1325
|
+
};
|
|
1326
|
+
P.shiftedBy = function(k) {
|
|
1327
|
+
intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
|
1328
|
+
return this.times("1e" + k);
|
|
1329
|
+
};
|
|
1330
|
+
P.squareRoot = P.sqrt = function() {
|
|
1331
|
+
var m, n, r, rep, t, x = this, c = x.c, s = x.s, e = x.e, dp = DECIMAL_PLACES + 4, half = new BigNumber2("0.5");
|
|
1332
|
+
if (s !== 1 || !c || !c[0]) {
|
|
1333
|
+
return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
|
|
1334
|
+
}
|
|
1335
|
+
s = Math.sqrt(+valueOf(x));
|
|
1336
|
+
if (s == 0 || s == 1 / 0) {
|
|
1337
|
+
n = coeffToString(c);
|
|
1338
|
+
if ((n.length + e) % 2 == 0)
|
|
1339
|
+
n += "0";
|
|
1340
|
+
s = Math.sqrt(+n);
|
|
1341
|
+
e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
1342
|
+
if (s == 1 / 0) {
|
|
1343
|
+
n = "5e" + e;
|
|
1344
|
+
} else {
|
|
1345
|
+
n = s.toExponential();
|
|
1346
|
+
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
1347
|
+
}
|
|
1348
|
+
r = new BigNumber2(n);
|
|
1349
|
+
} else {
|
|
1350
|
+
r = new BigNumber2(s + "");
|
|
1351
|
+
}
|
|
1352
|
+
if (r.c[0]) {
|
|
1353
|
+
e = r.e;
|
|
1354
|
+
s = e + dp;
|
|
1355
|
+
if (s < 3)
|
|
1356
|
+
s = 0;
|
|
1357
|
+
for (; ; ) {
|
|
1358
|
+
t = r;
|
|
1359
|
+
r = half.times(t.plus(div(x, t, dp, 1)));
|
|
1360
|
+
if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
|
|
1361
|
+
if (r.e < e)
|
|
1362
|
+
--s;
|
|
1363
|
+
n = n.slice(s - 3, s + 1);
|
|
1364
|
+
if (n == "9999" || !rep && n == "4999") {
|
|
1365
|
+
if (!rep) {
|
|
1366
|
+
round(t, t.e + DECIMAL_PLACES + 2, 0);
|
|
1367
|
+
if (t.times(t).eq(x)) {
|
|
1368
|
+
r = t;
|
|
1369
|
+
break;
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
dp += 4;
|
|
1373
|
+
s += 4;
|
|
1374
|
+
rep = 1;
|
|
1375
|
+
} else {
|
|
1376
|
+
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
1377
|
+
round(r, r.e + DECIMAL_PLACES + 2, 1);
|
|
1378
|
+
m = !r.times(r).eq(x);
|
|
1379
|
+
}
|
|
1380
|
+
break;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
|
|
1386
|
+
};
|
|
1387
|
+
P.toExponential = function(dp, rm) {
|
|
1388
|
+
if (dp != null) {
|
|
1389
|
+
intCheck(dp, 0, MAX);
|
|
1390
|
+
dp++;
|
|
1391
|
+
}
|
|
1392
|
+
return format(this, dp, rm, 1);
|
|
1393
|
+
};
|
|
1394
|
+
P.toFixed = function(dp, rm) {
|
|
1395
|
+
if (dp != null) {
|
|
1396
|
+
intCheck(dp, 0, MAX);
|
|
1397
|
+
dp = dp + this.e + 1;
|
|
1398
|
+
}
|
|
1399
|
+
return format(this, dp, rm);
|
|
1400
|
+
};
|
|
1401
|
+
P.toFormat = function(dp, rm, format2) {
|
|
1402
|
+
var str, x = this;
|
|
1403
|
+
if (format2 == null) {
|
|
1404
|
+
if (dp != null && rm && typeof rm == "object") {
|
|
1405
|
+
format2 = rm;
|
|
1406
|
+
rm = null;
|
|
1407
|
+
} else if (dp && typeof dp == "object") {
|
|
1408
|
+
format2 = dp;
|
|
1409
|
+
dp = rm = null;
|
|
1410
|
+
} else {
|
|
1411
|
+
format2 = FORMAT;
|
|
1412
|
+
}
|
|
1413
|
+
} else if (typeof format2 != "object") {
|
|
1414
|
+
throw Error(bignumberError + "Argument not an object: " + format2);
|
|
1415
|
+
}
|
|
1416
|
+
str = x.toFixed(dp, rm);
|
|
1417
|
+
if (x.c) {
|
|
1418
|
+
var i, arr = str.split("."), g1 = +format2.groupSize, g2 = +format2.secondaryGroupSize, groupSeparator = format2.groupSeparator || "", intPart = arr[0], fractionPart = arr[1], isNeg = x.s < 0, intDigits = isNeg ? intPart.slice(1) : intPart, len = intDigits.length;
|
|
1419
|
+
if (g2) {
|
|
1420
|
+
i = g1;
|
|
1421
|
+
g1 = g2;
|
|
1422
|
+
g2 = i;
|
|
1423
|
+
len -= i;
|
|
1424
|
+
}
|
|
1425
|
+
if (g1 > 0 && len > 0) {
|
|
1426
|
+
i = len % g1 || g1;
|
|
1427
|
+
intPart = intDigits.substr(0, i);
|
|
1428
|
+
for (; i < len; i += g1)
|
|
1429
|
+
intPart += groupSeparator + intDigits.substr(i, g1);
|
|
1430
|
+
if (g2 > 0)
|
|
1431
|
+
intPart += groupSeparator + intDigits.slice(i);
|
|
1432
|
+
if (isNeg)
|
|
1433
|
+
intPart = "-" + intPart;
|
|
1434
|
+
}
|
|
1435
|
+
str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(
|
|
1436
|
+
new RegExp("\\d{" + g2 + "}\\B", "g"),
|
|
1437
|
+
"$&" + (format2.fractionGroupSeparator || "")
|
|
1438
|
+
) : fractionPart) : intPart;
|
|
1439
|
+
}
|
|
1440
|
+
return (format2.prefix || "") + str + (format2.suffix || "");
|
|
1441
|
+
};
|
|
1442
|
+
P.toFraction = function(md) {
|
|
1443
|
+
var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
|
|
1444
|
+
if (md != null) {
|
|
1445
|
+
n = new BigNumber2(md);
|
|
1446
|
+
if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
|
|
1447
|
+
throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
if (!xc)
|
|
1451
|
+
return new BigNumber2(x);
|
|
1452
|
+
d = new BigNumber2(ONE);
|
|
1453
|
+
n1 = d0 = new BigNumber2(ONE);
|
|
1454
|
+
d1 = n0 = new BigNumber2(ONE);
|
|
1455
|
+
s = coeffToString(xc);
|
|
1456
|
+
e = d.e = s.length - x.e - 1;
|
|
1457
|
+
d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
|
|
1458
|
+
md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
|
|
1459
|
+
exp = MAX_EXP;
|
|
1460
|
+
MAX_EXP = 1 / 0;
|
|
1461
|
+
n = new BigNumber2(s);
|
|
1462
|
+
n0.c[0] = 0;
|
|
1463
|
+
for (; ; ) {
|
|
1464
|
+
q = div(n, d, 0, 1);
|
|
1465
|
+
d2 = d0.plus(q.times(d1));
|
|
1466
|
+
if (d2.comparedTo(md) == 1)
|
|
1467
|
+
break;
|
|
1468
|
+
d0 = d1;
|
|
1469
|
+
d1 = d2;
|
|
1470
|
+
n1 = n0.plus(q.times(d2 = n1));
|
|
1471
|
+
n0 = d2;
|
|
1472
|
+
d = n.minus(q.times(d2 = d));
|
|
1473
|
+
n = d2;
|
|
1474
|
+
}
|
|
1475
|
+
d2 = div(md.minus(d0), d1, 0, 1);
|
|
1476
|
+
n0 = n0.plus(d2.times(n1));
|
|
1477
|
+
d0 = d0.plus(d2.times(d1));
|
|
1478
|
+
n0.s = n1.s = x.s;
|
|
1479
|
+
e = e * 2;
|
|
1480
|
+
r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
|
|
1481
|
+
div(n0, d0, e, ROUNDING_MODE).minus(x).abs()
|
|
1482
|
+
) < 1 ? [n1, d1] : [n0, d0];
|
|
1483
|
+
MAX_EXP = exp;
|
|
1484
|
+
return r;
|
|
1485
|
+
};
|
|
1486
|
+
P.toNumber = function() {
|
|
1487
|
+
return +valueOf(this);
|
|
1488
|
+
};
|
|
1489
|
+
P.toPrecision = function(sd, rm) {
|
|
1490
|
+
if (sd != null)
|
|
1491
|
+
intCheck(sd, 1, MAX);
|
|
1492
|
+
return format(this, sd, rm, 2);
|
|
1493
|
+
};
|
|
1494
|
+
P.toString = function(b) {
|
|
1495
|
+
var str, n = this, s = n.s, e = n.e;
|
|
1496
|
+
if (e === null) {
|
|
1497
|
+
if (s) {
|
|
1498
|
+
str = "Infinity";
|
|
1499
|
+
if (s < 0)
|
|
1500
|
+
str = "-" + str;
|
|
1501
|
+
} else {
|
|
1502
|
+
str = "NaN";
|
|
1503
|
+
}
|
|
1504
|
+
} else {
|
|
1505
|
+
if (b == null) {
|
|
1506
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
|
|
1507
|
+
} else if (b === 10 && alphabetHasNormalDecimalDigits) {
|
|
1508
|
+
n = round(new BigNumber2(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
|
|
1509
|
+
str = toFixedPoint(coeffToString(n.c), n.e, "0");
|
|
1510
|
+
} else {
|
|
1511
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
1512
|
+
str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
|
|
1513
|
+
}
|
|
1514
|
+
if (s < 0 && n.c[0])
|
|
1515
|
+
str = "-" + str;
|
|
1516
|
+
}
|
|
1517
|
+
return str;
|
|
1518
|
+
};
|
|
1519
|
+
P.valueOf = P.toJSON = function() {
|
|
1520
|
+
return valueOf(this);
|
|
1521
|
+
};
|
|
1522
|
+
P._isBigNumber = true;
|
|
1523
|
+
P[Symbol.toStringTag] = "BigNumber";
|
|
1524
|
+
P[Symbol.for("nodejs.util.inspect.custom")] = P.valueOf;
|
|
1525
|
+
if (configObject != null)
|
|
1526
|
+
BigNumber2.set(configObject);
|
|
1527
|
+
return BigNumber2;
|
|
1528
|
+
}
|
|
1529
|
+
function bitFloor(n) {
|
|
1530
|
+
var i = n | 0;
|
|
1531
|
+
return n > 0 || n === i ? i : i - 1;
|
|
1532
|
+
}
|
|
1533
|
+
function coeffToString(a) {
|
|
1534
|
+
var s, z, i = 1, j = a.length, r = a[0] + "";
|
|
1535
|
+
for (; i < j; ) {
|
|
1536
|
+
s = a[i++] + "";
|
|
1537
|
+
z = LOG_BASE - s.length;
|
|
1538
|
+
for (; z--; s = "0" + s)
|
|
1539
|
+
;
|
|
1540
|
+
r += s;
|
|
1541
|
+
}
|
|
1542
|
+
for (j = r.length; r.charCodeAt(--j) === 48; )
|
|
1543
|
+
;
|
|
1544
|
+
return r.slice(0, j + 1 || 1);
|
|
1545
|
+
}
|
|
1546
|
+
function compare(x, y) {
|
|
1547
|
+
var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
|
|
1548
|
+
if (!i || !j)
|
|
1549
|
+
return null;
|
|
1550
|
+
a = xc && !xc[0];
|
|
1551
|
+
b = yc && !yc[0];
|
|
1552
|
+
if (a || b)
|
|
1553
|
+
return a ? b ? 0 : -j : i;
|
|
1554
|
+
if (i != j)
|
|
1555
|
+
return i;
|
|
1556
|
+
a = i < 0;
|
|
1557
|
+
b = k == l;
|
|
1558
|
+
if (!xc || !yc)
|
|
1559
|
+
return b ? 0 : !xc ^ a ? 1 : -1;
|
|
1560
|
+
if (!b)
|
|
1561
|
+
return k > l ^ a ? 1 : -1;
|
|
1562
|
+
j = (k = xc.length) < (l = yc.length) ? k : l;
|
|
1563
|
+
for (i = 0; i < j; i++)
|
|
1564
|
+
if (xc[i] != yc[i])
|
|
1565
|
+
return xc[i] > yc[i] ^ a ? 1 : -1;
|
|
1566
|
+
return k == l ? 0 : k > l ^ a ? 1 : -1;
|
|
1567
|
+
}
|
|
1568
|
+
function intCheck(n, min, max, name) {
|
|
1569
|
+
if (n < min || n > max || n !== mathfloor(n)) {
|
|
1570
|
+
throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
function isOdd(n) {
|
|
1574
|
+
var k = n.c.length - 1;
|
|
1575
|
+
return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
|
|
1576
|
+
}
|
|
1577
|
+
function toExponential(str, e) {
|
|
1578
|
+
return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
|
|
1579
|
+
}
|
|
1580
|
+
function toFixedPoint(str, e, z) {
|
|
1581
|
+
var len, zs;
|
|
1582
|
+
if (e < 0) {
|
|
1583
|
+
for (zs = z + "."; ++e; zs += z)
|
|
1584
|
+
;
|
|
1585
|
+
str = zs + str;
|
|
1586
|
+
} else {
|
|
1587
|
+
len = str.length;
|
|
1588
|
+
if (++e > len) {
|
|
1589
|
+
for (zs = z, e -= len; --e; zs += z)
|
|
1590
|
+
;
|
|
1591
|
+
str += zs;
|
|
1592
|
+
} else if (e < len) {
|
|
1593
|
+
str = str.slice(0, e) + "." + str.slice(e);
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
return str;
|
|
1597
|
+
}
|
|
1598
|
+
var BigNumber = clone();
|
|
1599
|
+
var bignumber_default = BigNumber;
|
|
1600
|
+
|
|
1601
|
+
// src/number/index.ts
|
|
1602
|
+
var BIG_INTS = {
|
|
1603
|
+
t: { v: 10 ** 12, d: 13, n: "t" },
|
|
1604
|
+
b: { v: 10 ** 9, d: 10, n: "b" },
|
|
1605
|
+
m: { v: 10 ** 6, d: 7, n: "m" },
|
|
1606
|
+
k: { v: 10 ** 3, d: 4, n: "k" }
|
|
1607
|
+
};
|
|
1608
|
+
function unum(num = "0") {
|
|
1609
|
+
return new bignumber_default(numerfix(num));
|
|
1610
|
+
}
|
|
1611
|
+
function gte(num, n) {
|
|
1612
|
+
return unum(num).gte(unum(n));
|
|
1613
|
+
}
|
|
1614
|
+
function gt(num, n) {
|
|
1615
|
+
return unum(num).gt(unum(n));
|
|
1616
|
+
}
|
|
1617
|
+
function lte(num, n) {
|
|
1618
|
+
return unum(num).lte(unum(n));
|
|
1619
|
+
}
|
|
1620
|
+
function lt(num, n) {
|
|
1621
|
+
return unum(num).lt(unum(n));
|
|
1622
|
+
}
|
|
1623
|
+
function plus(array, options) {
|
|
1624
|
+
const rounding = (options == null ? void 0 : options.r) || bignumber_default.ROUND_DOWN;
|
|
1625
|
+
const decimal2 = (options == null ? void 0 : options.d) || 0;
|
|
1626
|
+
return array.filter((v) => unum(v).gt(0)).reduce((t, v) => t.plus(unum(v)), unum(0)).toFixed(decimal2, rounding);
|
|
1627
|
+
}
|
|
1628
|
+
function average(array, options) {
|
|
1629
|
+
const rounding = (options == null ? void 0 : options.r) || bignumber_default.ROUND_DOWN;
|
|
1630
|
+
const decimal2 = (options == null ? void 0 : options.d) || 0;
|
|
1631
|
+
if (array.length === 0)
|
|
1632
|
+
return "0";
|
|
1633
|
+
return unum(plus(array)).div(array.length).toFixed(decimal2, rounding);
|
|
1634
|
+
}
|
|
1635
|
+
function percentage(total, count, options) {
|
|
1636
|
+
options != null ? options : options = { d: 3, r: bignumber_default.ROUND_DOWN };
|
|
1637
|
+
const rounding = (options == null ? void 0 : options.r) || bignumber_default.ROUND_DOWN;
|
|
1638
|
+
const decimal2 = (options == null ? void 0 : options.d) || 3;
|
|
1639
|
+
if (unum(total).lte(0) || unum(count).lte(0))
|
|
1640
|
+
return "0";
|
|
1641
|
+
return unum(count).div(unum(total)).times(100).toFixed(decimal2, rounding);
|
|
1642
|
+
}
|
|
1643
|
+
function zerofill(value, n = 2, type = "positive") {
|
|
1644
|
+
const _value = integer(value);
|
|
1645
|
+
if (_value.length >= n)
|
|
1646
|
+
return value;
|
|
1647
|
+
const zero = "0".repeat(n - _value.length);
|
|
1648
|
+
if (type === "positive")
|
|
1649
|
+
return zero + value;
|
|
1650
|
+
if (type === "reverse")
|
|
1651
|
+
return zero + value;
|
|
1652
|
+
return "";
|
|
1653
|
+
}
|
|
1654
|
+
function numerfix(value) {
|
|
1655
|
+
const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
|
|
1656
|
+
if (_isNaN)
|
|
1657
|
+
console.warn(`numerfix(${value}): value is not the correct value. To ensure the normal operation of the program, it will be converted to zero`);
|
|
1658
|
+
return _isNaN ? "0" : String(value);
|
|
1659
|
+
}
|
|
1660
|
+
function integer(value) {
|
|
1661
|
+
return new bignumber_default(numerfix(value)).toFixed(0);
|
|
1662
|
+
}
|
|
1663
|
+
function decimal(value, n = 2) {
|
|
1664
|
+
let [integer2, decimal2] = numerfix(value).split(".");
|
|
1665
|
+
if (n <= 0)
|
|
1666
|
+
return integer2;
|
|
1667
|
+
if (!decimal2)
|
|
1668
|
+
decimal2 = "0";
|
|
1669
|
+
decimal2 = decimal2.slice(0, n);
|
|
1670
|
+
decimal2 = decimal2 + "0".repeat(n - decimal2.length);
|
|
1671
|
+
return `${integer2}.${decimal2}`;
|
|
1672
|
+
}
|
|
1673
|
+
function parseNumeric(num, delimiters = ["t", "b", "m"]) {
|
|
1674
|
+
const mappings = [
|
|
1675
|
+
delimiters.includes("t") && ((n) => gte(n, BIG_INTS.t.v) && BIG_INTS.t),
|
|
1676
|
+
delimiters.includes("b") && ((n) => gte(n, BIG_INTS.b.v) && lt(n, BIG_INTS.t.v) && BIG_INTS.b),
|
|
1677
|
+
delimiters.includes("m") && ((n) => gte(n, BIG_INTS.m.v) && lt(n, BIG_INTS.b.v) && BIG_INTS.m),
|
|
1678
|
+
delimiters.includes("k") && ((n) => gte(n, BIG_INTS.k.v) && lt(n, BIG_INTS.m.v) && BIG_INTS.k)
|
|
1679
|
+
];
|
|
1680
|
+
let options;
|
|
1681
|
+
for (const analy of mappings) {
|
|
1682
|
+
const opts = analy && analy(unum(num).toFixed(0));
|
|
1683
|
+
opts && (options = opts);
|
|
1684
|
+
}
|
|
1685
|
+
return options || { v: 1, d: 0, n: "" };
|
|
1686
|
+
}
|
|
1687
|
+
function formatNumeric(value = "0", options) {
|
|
1688
|
+
const {
|
|
1689
|
+
rounding = bignumber_default.ROUND_DOWN,
|
|
1690
|
+
delimiters,
|
|
1691
|
+
format,
|
|
1692
|
+
decimals = 2
|
|
1693
|
+
} = options || {};
|
|
1694
|
+
const config = parseNumeric(value, delimiters || []);
|
|
1695
|
+
const number = unum(value).div(config.v).toFormat(decimals, rounding, format);
|
|
1696
|
+
return `${number}${config.n}`;
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
// src/string/index.ts
|
|
1700
|
+
function cover(value, mode, symbol = "*") {
|
|
1701
|
+
return value.slice(0, mode[0]) + symbol.repeat(mode[1]) + value.slice(-mode[2]);
|
|
1702
|
+
}
|
|
183
1703
|
export {
|
|
1704
|
+
BIG_INTS,
|
|
1705
|
+
bignumber_default as Bignumber,
|
|
1706
|
+
Deferred,
|
|
184
1707
|
UA,
|
|
185
1708
|
arange,
|
|
1709
|
+
average,
|
|
186
1710
|
compose,
|
|
187
|
-
|
|
188
|
-
|
|
1711
|
+
cover,
|
|
1712
|
+
decimal,
|
|
1713
|
+
delay,
|
|
189
1714
|
formDataToObject,
|
|
1715
|
+
formatNumeric,
|
|
190
1716
|
formatSize,
|
|
191
1717
|
formatUnit,
|
|
192
1718
|
getTypeof,
|
|
1719
|
+
gt,
|
|
1720
|
+
gte,
|
|
1721
|
+
integer,
|
|
193
1722
|
isAndroid,
|
|
1723
|
+
isArray,
|
|
194
1724
|
isBrowser,
|
|
195
1725
|
isChrome,
|
|
196
1726
|
isEdge,
|
|
@@ -201,14 +1731,29 @@ export {
|
|
|
201
1731
|
isIE9,
|
|
202
1732
|
isIOS,
|
|
203
1733
|
isMobile,
|
|
1734
|
+
isNull,
|
|
1735
|
+
isNumber,
|
|
204
1736
|
isObject,
|
|
205
1737
|
isPhantomJS,
|
|
1738
|
+
isPlainObject,
|
|
1739
|
+
isString,
|
|
206
1740
|
isTypeof,
|
|
207
1741
|
isWeex,
|
|
208
1742
|
isWindow,
|
|
1743
|
+
loop,
|
|
1744
|
+
lt,
|
|
1745
|
+
lte,
|
|
1746
|
+
noop,
|
|
1747
|
+
numerfix,
|
|
209
1748
|
objectToFormData,
|
|
210
1749
|
pPipe,
|
|
1750
|
+
parseNumeric,
|
|
1751
|
+
percentage,
|
|
211
1752
|
pipe,
|
|
1753
|
+
plus,
|
|
1754
|
+
riposte,
|
|
1755
|
+
unum,
|
|
212
1756
|
weexPlatform,
|
|
213
|
-
whenever
|
|
1757
|
+
whenever,
|
|
1758
|
+
zerofill
|
|
214
1759
|
};
|