hufi-cli 0.5.2 → 0.5.5
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/cli.js +1486 -18
- package/package.json +3 -1
package/dist/cli.js
CHANGED
|
@@ -2629,7 +2629,7 @@ var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
|
2629
2629
|
|
|
2630
2630
|
// node_modules/@noble/hashes/esm/cryptoNode.js
|
|
2631
2631
|
import * as nc from "node:crypto";
|
|
2632
|
-
var
|
|
2632
|
+
var crypto2 = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : undefined;
|
|
2633
2633
|
|
|
2634
2634
|
// node_modules/@noble/hashes/esm/utils.js
|
|
2635
2635
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
@@ -2705,8 +2705,8 @@ function wrapXOFConstructorWithOpts(hashCons) {
|
|
|
2705
2705
|
return hashC;
|
|
2706
2706
|
}
|
|
2707
2707
|
function randomBytes2(bytesLength = 32) {
|
|
2708
|
-
if (
|
|
2709
|
-
return
|
|
2708
|
+
if (crypto2 && typeof crypto2.getRandomValues === "function") {
|
|
2709
|
+
return crypto2.getRandomValues(new Uint8Array(bytesLength));
|
|
2710
2710
|
}
|
|
2711
2711
|
throw new Error("crypto.getRandomValues must be defined");
|
|
2712
2712
|
}
|
|
@@ -9357,7 +9357,8 @@ function keyFile() {
|
|
|
9357
9357
|
}
|
|
9358
9358
|
var DEFAULT_CONFIG = {
|
|
9359
9359
|
recordingApiUrl: "https://ro.hu.finance",
|
|
9360
|
-
launcherApiUrl: "https://cl.hu.finance"
|
|
9360
|
+
launcherApiUrl: "https://cl.hu.finance",
|
|
9361
|
+
defaultChainId: 137
|
|
9361
9362
|
};
|
|
9362
9363
|
function ensureConfigDir() {
|
|
9363
9364
|
if (!existsSync(CONFIG_DIR)) {
|
|
@@ -9402,6 +9403,9 @@ function saveKey(key, address) {
|
|
|
9402
9403
|
writeFileSync(keyFile(), JSON.stringify({ address, privateKey: key }, null, 2) + `
|
|
9403
9404
|
`);
|
|
9404
9405
|
}
|
|
9406
|
+
function getDefaultChainId() {
|
|
9407
|
+
return loadConfig().defaultChainId ?? 137;
|
|
9408
|
+
}
|
|
9405
9409
|
function loadKey() {
|
|
9406
9410
|
if (!existsSync(keyFile()))
|
|
9407
9411
|
return null;
|
|
@@ -9588,6 +9592,1450 @@ function createExchangeCommand() {
|
|
|
9588
9592
|
return exchange;
|
|
9589
9593
|
}
|
|
9590
9594
|
|
|
9595
|
+
// node_modules/bignumber.js/dist/bignumber.mjs
|
|
9596
|
+
var BigNumber = clone();
|
|
9597
|
+
var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
9598
|
+
var mathceil = Math.ceil;
|
|
9599
|
+
var mathfloor = Math.floor;
|
|
9600
|
+
var bignumberError = "[BigNumber Error] ";
|
|
9601
|
+
var BASE = 100000000000000;
|
|
9602
|
+
var LOG_BASE = 14;
|
|
9603
|
+
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
9604
|
+
var POWS_TEN = [1, 10, 100, 1000, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 10000000000, 100000000000, 1000000000000, 10000000000000];
|
|
9605
|
+
var SQRT_BASE = 1e7;
|
|
9606
|
+
var MAX = 1e9;
|
|
9607
|
+
function clone(configObject) {
|
|
9608
|
+
var div, convertBase, parseUnusualNumeric, 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 = {
|
|
9609
|
+
prefix: "",
|
|
9610
|
+
groupSize: 3,
|
|
9611
|
+
secondaryGroupSize: 0,
|
|
9612
|
+
groupSeparator: ",",
|
|
9613
|
+
decimalSeparator: ".",
|
|
9614
|
+
fractionGroupSize: 0,
|
|
9615
|
+
fractionGroupSeparator: " ",
|
|
9616
|
+
suffix: ""
|
|
9617
|
+
}, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
9618
|
+
function BigNumber2(v, b) {
|
|
9619
|
+
var alphabet, c, caseChanged, e, i, len, str, t, x = this;
|
|
9620
|
+
if (!(x instanceof BigNumber2))
|
|
9621
|
+
return new BigNumber2(v, b);
|
|
9622
|
+
t = typeof v;
|
|
9623
|
+
if (b == null) {
|
|
9624
|
+
if (isBigNumber(v)) {
|
|
9625
|
+
x.s = v.s;
|
|
9626
|
+
if (!v.c || v.e > MAX_EXP) {
|
|
9627
|
+
x.c = x.e = null;
|
|
9628
|
+
} else if (v.e < MIN_EXP) {
|
|
9629
|
+
x.c = [x.e = 0];
|
|
9630
|
+
} else {
|
|
9631
|
+
x.e = v.e;
|
|
9632
|
+
x.c = v.c.slice();
|
|
9633
|
+
}
|
|
9634
|
+
return;
|
|
9635
|
+
}
|
|
9636
|
+
if (t == "number") {
|
|
9637
|
+
if (v * 0 != 0) {
|
|
9638
|
+
x.s = isNaN(v) ? null : v < 0 ? -1 : 1;
|
|
9639
|
+
x.c = x.e = null;
|
|
9640
|
+
return;
|
|
9641
|
+
}
|
|
9642
|
+
x.s = 1 / v < 0 ? (v = -v, -1) : 1;
|
|
9643
|
+
if (v === ~~v) {
|
|
9644
|
+
for (e = 0, i = v;i >= 10; i /= 10, e++)
|
|
9645
|
+
;
|
|
9646
|
+
if (e > MAX_EXP) {
|
|
9647
|
+
x.c = x.e = null;
|
|
9648
|
+
} else {
|
|
9649
|
+
x.e = e;
|
|
9650
|
+
x.c = [v];
|
|
9651
|
+
}
|
|
9652
|
+
return;
|
|
9653
|
+
}
|
|
9654
|
+
str = String(v);
|
|
9655
|
+
} else {
|
|
9656
|
+
if (t == "string") {
|
|
9657
|
+
str = v;
|
|
9658
|
+
if (!isNumeric.test(str)) {
|
|
9659
|
+
return parseUnusualNumeric(x, str);
|
|
9660
|
+
}
|
|
9661
|
+
} else if (t == "bigint") {
|
|
9662
|
+
str = String(v);
|
|
9663
|
+
} else {
|
|
9664
|
+
throw Error(bignumberError + "Invalid argument: " + v);
|
|
9665
|
+
}
|
|
9666
|
+
x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
|
|
9667
|
+
}
|
|
9668
|
+
if ((e = str.indexOf(".")) > -1)
|
|
9669
|
+
str = str.replace(".", "");
|
|
9670
|
+
if ((i = str.search(/e/i)) > 0) {
|
|
9671
|
+
if (e < 0)
|
|
9672
|
+
e = i;
|
|
9673
|
+
e += +str.slice(i + 1);
|
|
9674
|
+
str = str.substring(0, i);
|
|
9675
|
+
} else if (e < 0) {
|
|
9676
|
+
e = str.length;
|
|
9677
|
+
}
|
|
9678
|
+
} else {
|
|
9679
|
+
if (t != "string") {
|
|
9680
|
+
throw Error(bignumberError + "String expected: " + v);
|
|
9681
|
+
}
|
|
9682
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
9683
|
+
str = v;
|
|
9684
|
+
x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
|
|
9685
|
+
alphabet = ALPHABET.slice(0, b);
|
|
9686
|
+
e = i = 0;
|
|
9687
|
+
for (len = str.length;i < len; i++) {
|
|
9688
|
+
if (alphabet.indexOf(c = str.charAt(i)) < 0) {
|
|
9689
|
+
if (c == ".") {
|
|
9690
|
+
if (i > e) {
|
|
9691
|
+
e = len;
|
|
9692
|
+
continue;
|
|
9693
|
+
}
|
|
9694
|
+
} else if (!caseChanged) {
|
|
9695
|
+
if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
|
|
9696
|
+
caseChanged = true;
|
|
9697
|
+
i = -1;
|
|
9698
|
+
e = 0;
|
|
9699
|
+
continue;
|
|
9700
|
+
}
|
|
9701
|
+
}
|
|
9702
|
+
return parseUnusualNumeric(x, v, b);
|
|
9703
|
+
}
|
|
9704
|
+
}
|
|
9705
|
+
str = convertBase(str, b, 10, x.s);
|
|
9706
|
+
if ((e = str.indexOf(".")) > -1)
|
|
9707
|
+
str = str.replace(".", "");
|
|
9708
|
+
else
|
|
9709
|
+
e = str.length;
|
|
9710
|
+
}
|
|
9711
|
+
for (i = 0;str.charCodeAt(i) === 48; i++)
|
|
9712
|
+
;
|
|
9713
|
+
for (len = str.length;str.charCodeAt(--len) === 48; )
|
|
9714
|
+
;
|
|
9715
|
+
if (str = str.slice(i, ++len)) {
|
|
9716
|
+
len -= i;
|
|
9717
|
+
e = e - i - 1;
|
|
9718
|
+
if (e > MAX_EXP) {
|
|
9719
|
+
x.c = x.e = null;
|
|
9720
|
+
} else if (e < MIN_EXP) {
|
|
9721
|
+
x.c = [x.e = 0];
|
|
9722
|
+
} else {
|
|
9723
|
+
x.e = e;
|
|
9724
|
+
x.c = [];
|
|
9725
|
+
i = (e + 1) % LOG_BASE;
|
|
9726
|
+
if (e < 0)
|
|
9727
|
+
i += LOG_BASE;
|
|
9728
|
+
if (i < len) {
|
|
9729
|
+
if (i)
|
|
9730
|
+
x.c.push(+str.slice(0, i));
|
|
9731
|
+
for (len -= LOG_BASE;i < len; ) {
|
|
9732
|
+
x.c.push(+str.slice(i, i += LOG_BASE));
|
|
9733
|
+
}
|
|
9734
|
+
i = LOG_BASE - (str = str.slice(i)).length;
|
|
9735
|
+
} else {
|
|
9736
|
+
i -= len;
|
|
9737
|
+
}
|
|
9738
|
+
for (;i--; str += "0")
|
|
9739
|
+
;
|
|
9740
|
+
x.c.push(+str);
|
|
9741
|
+
}
|
|
9742
|
+
} else {
|
|
9743
|
+
x.c = [x.e = 0];
|
|
9744
|
+
}
|
|
9745
|
+
}
|
|
9746
|
+
BigNumber2.clone = clone;
|
|
9747
|
+
BigNumber2.ROUND_UP = 0;
|
|
9748
|
+
BigNumber2.ROUND_DOWN = 1;
|
|
9749
|
+
BigNumber2.ROUND_CEIL = 2;
|
|
9750
|
+
BigNumber2.ROUND_FLOOR = 3;
|
|
9751
|
+
BigNumber2.ROUND_HALF_UP = 4;
|
|
9752
|
+
BigNumber2.ROUND_HALF_DOWN = 5;
|
|
9753
|
+
BigNumber2.ROUND_HALF_EVEN = 6;
|
|
9754
|
+
BigNumber2.ROUND_HALF_CEIL = 7;
|
|
9755
|
+
BigNumber2.ROUND_HALF_FLOOR = 8;
|
|
9756
|
+
BigNumber2.EUCLID = 9;
|
|
9757
|
+
BigNumber2.config = BigNumber2.set = function(obj) {
|
|
9758
|
+
var p, v;
|
|
9759
|
+
if (obj != null) {
|
|
9760
|
+
if (typeof obj == "object") {
|
|
9761
|
+
if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
|
|
9762
|
+
v = obj[p];
|
|
9763
|
+
intCheck(v, 0, MAX, p);
|
|
9764
|
+
DECIMAL_PLACES = v;
|
|
9765
|
+
}
|
|
9766
|
+
if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
|
|
9767
|
+
v = obj[p];
|
|
9768
|
+
intCheck(v, 0, 8, p);
|
|
9769
|
+
ROUNDING_MODE = v;
|
|
9770
|
+
}
|
|
9771
|
+
if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
|
|
9772
|
+
v = obj[p];
|
|
9773
|
+
if (v && v.pop) {
|
|
9774
|
+
intCheck(v[0], -MAX, 0, p);
|
|
9775
|
+
intCheck(v[1], 0, MAX, p);
|
|
9776
|
+
TO_EXP_NEG = v[0];
|
|
9777
|
+
TO_EXP_POS = v[1];
|
|
9778
|
+
} else {
|
|
9779
|
+
intCheck(v, -MAX, MAX, p);
|
|
9780
|
+
TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
|
|
9781
|
+
}
|
|
9782
|
+
}
|
|
9783
|
+
if (obj.hasOwnProperty(p = "RANGE")) {
|
|
9784
|
+
v = obj[p];
|
|
9785
|
+
if (v && v.pop) {
|
|
9786
|
+
intCheck(v[0], -MAX, -1, p);
|
|
9787
|
+
intCheck(v[1], 1, MAX, p);
|
|
9788
|
+
MIN_EXP = v[0];
|
|
9789
|
+
MAX_EXP = v[1];
|
|
9790
|
+
} else {
|
|
9791
|
+
intCheck(v, -MAX, MAX, p);
|
|
9792
|
+
if (v) {
|
|
9793
|
+
MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
|
|
9794
|
+
} else {
|
|
9795
|
+
throw Error(bignumberError + p + " cannot be zero: " + v);
|
|
9796
|
+
}
|
|
9797
|
+
}
|
|
9798
|
+
}
|
|
9799
|
+
if (obj.hasOwnProperty(p = "CRYPTO")) {
|
|
9800
|
+
v = obj[p];
|
|
9801
|
+
if (v === !!v) {
|
|
9802
|
+
if (v) {
|
|
9803
|
+
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
|
9804
|
+
CRYPTO = v;
|
|
9805
|
+
} else {
|
|
9806
|
+
CRYPTO = !v;
|
|
9807
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
9808
|
+
}
|
|
9809
|
+
} else {
|
|
9810
|
+
CRYPTO = v;
|
|
9811
|
+
}
|
|
9812
|
+
} else {
|
|
9813
|
+
throw Error(bignumberError + p + " not true or false: " + v);
|
|
9814
|
+
}
|
|
9815
|
+
}
|
|
9816
|
+
if (obj.hasOwnProperty(p = "MODULO_MODE")) {
|
|
9817
|
+
v = obj[p];
|
|
9818
|
+
intCheck(v, 0, 9, p);
|
|
9819
|
+
MODULO_MODE = v;
|
|
9820
|
+
}
|
|
9821
|
+
if (obj.hasOwnProperty(p = "POW_PRECISION")) {
|
|
9822
|
+
v = obj[p];
|
|
9823
|
+
intCheck(v, 0, MAX, p);
|
|
9824
|
+
POW_PRECISION = v;
|
|
9825
|
+
}
|
|
9826
|
+
if (obj.hasOwnProperty(p = "FORMAT")) {
|
|
9827
|
+
v = obj[p];
|
|
9828
|
+
if (typeof v == "object")
|
|
9829
|
+
FORMAT = v;
|
|
9830
|
+
else
|
|
9831
|
+
throw Error(bignumberError + p + " not an object: " + v);
|
|
9832
|
+
}
|
|
9833
|
+
if (obj.hasOwnProperty(p = "ALPHABET")) {
|
|
9834
|
+
v = obj[p];
|
|
9835
|
+
if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
|
|
9836
|
+
ALPHABET = v;
|
|
9837
|
+
} else {
|
|
9838
|
+
throw Error(bignumberError + p + " invalid: " + v);
|
|
9839
|
+
}
|
|
9840
|
+
}
|
|
9841
|
+
} else {
|
|
9842
|
+
throw Error(bignumberError + "Object expected: " + obj);
|
|
9843
|
+
}
|
|
9844
|
+
}
|
|
9845
|
+
return {
|
|
9846
|
+
DECIMAL_PLACES,
|
|
9847
|
+
ROUNDING_MODE,
|
|
9848
|
+
EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
|
|
9849
|
+
RANGE: [MIN_EXP, MAX_EXP],
|
|
9850
|
+
CRYPTO,
|
|
9851
|
+
MODULO_MODE,
|
|
9852
|
+
POW_PRECISION,
|
|
9853
|
+
FORMAT,
|
|
9854
|
+
ALPHABET
|
|
9855
|
+
};
|
|
9856
|
+
};
|
|
9857
|
+
BigNumber2.isBigNumber = function(v) {
|
|
9858
|
+
if (!isBigNumber(v))
|
|
9859
|
+
return false;
|
|
9860
|
+
var i, n, c = v.c, e = v.e, s = v.s;
|
|
9861
|
+
if ({}.toString.call(c) != "[object Array]") {
|
|
9862
|
+
return c === null && e === null && (s === null || s === 1 || s === -1);
|
|
9863
|
+
}
|
|
9864
|
+
if (s !== 1 && s !== -1 || e < -MAX || e > MAX || e !== mathfloor(e)) {
|
|
9865
|
+
return false;
|
|
9866
|
+
}
|
|
9867
|
+
if (c[0] === 0) {
|
|
9868
|
+
return e === 0 && c.length === 1;
|
|
9869
|
+
}
|
|
9870
|
+
i = (e + 1) % LOG_BASE;
|
|
9871
|
+
if (i < 1)
|
|
9872
|
+
i += LOG_BASE;
|
|
9873
|
+
if (String(c[0]).length !== i) {
|
|
9874
|
+
return false;
|
|
9875
|
+
}
|
|
9876
|
+
for (i = 0;i < c.length; i++) {
|
|
9877
|
+
n = c[i];
|
|
9878
|
+
if (n < 0 || n >= BASE || n !== mathfloor(n))
|
|
9879
|
+
return false;
|
|
9880
|
+
}
|
|
9881
|
+
return n !== 0;
|
|
9882
|
+
};
|
|
9883
|
+
BigNumber2.maximum = BigNumber2.max = function() {
|
|
9884
|
+
return maxOrMin(arguments, -1);
|
|
9885
|
+
};
|
|
9886
|
+
BigNumber2.minimum = BigNumber2.min = function() {
|
|
9887
|
+
return maxOrMin(arguments, 1);
|
|
9888
|
+
};
|
|
9889
|
+
BigNumber2.random = function() {
|
|
9890
|
+
var pow2_53 = 9007199254740992;
|
|
9891
|
+
var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
|
|
9892
|
+
return mathfloor(Math.random() * pow2_53);
|
|
9893
|
+
} : function() {
|
|
9894
|
+
return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
|
|
9895
|
+
};
|
|
9896
|
+
return function(dp) {
|
|
9897
|
+
var a, b, e, k, v, i = 0, c = [], rand = new BigNumber2(ONE);
|
|
9898
|
+
if (dp == null)
|
|
9899
|
+
dp = DECIMAL_PLACES;
|
|
9900
|
+
else
|
|
9901
|
+
intCheck(dp, 0, MAX);
|
|
9902
|
+
k = mathceil(dp / LOG_BASE);
|
|
9903
|
+
if (CRYPTO) {
|
|
9904
|
+
if (crypto.getRandomValues) {
|
|
9905
|
+
a = crypto.getRandomValues(new Uint32Array(k *= 2));
|
|
9906
|
+
for (;i < k; ) {
|
|
9907
|
+
v = a[i] * 131072 + (a[i + 1] >>> 11);
|
|
9908
|
+
if (v >= 9000000000000000) {
|
|
9909
|
+
b = crypto.getRandomValues(new Uint32Array(2));
|
|
9910
|
+
a[i] = b[0];
|
|
9911
|
+
a[i + 1] = b[1];
|
|
9912
|
+
} else {
|
|
9913
|
+
c.push(v % 100000000000000);
|
|
9914
|
+
i += 2;
|
|
9915
|
+
}
|
|
9916
|
+
}
|
|
9917
|
+
i = k / 2;
|
|
9918
|
+
} else if (crypto.randomBytes) {
|
|
9919
|
+
a = crypto.randomBytes(k *= 7);
|
|
9920
|
+
for (;i < k; ) {
|
|
9921
|
+
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];
|
|
9922
|
+
if (v >= 9000000000000000) {
|
|
9923
|
+
crypto.randomBytes(7).copy(a, i);
|
|
9924
|
+
} else {
|
|
9925
|
+
c.push(v % 100000000000000);
|
|
9926
|
+
i += 7;
|
|
9927
|
+
}
|
|
9928
|
+
}
|
|
9929
|
+
i = k / 7;
|
|
9930
|
+
} else {
|
|
9931
|
+
CRYPTO = false;
|
|
9932
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
9933
|
+
}
|
|
9934
|
+
}
|
|
9935
|
+
if (!CRYPTO) {
|
|
9936
|
+
for (;i < k; ) {
|
|
9937
|
+
v = random53bitInt();
|
|
9938
|
+
if (v < 9000000000000000)
|
|
9939
|
+
c[i++] = v % 100000000000000;
|
|
9940
|
+
}
|
|
9941
|
+
}
|
|
9942
|
+
k = c[--i];
|
|
9943
|
+
dp %= LOG_BASE;
|
|
9944
|
+
if (k && dp) {
|
|
9945
|
+
v = POWS_TEN[LOG_BASE - dp];
|
|
9946
|
+
c[i] = mathfloor(k / v) * v;
|
|
9947
|
+
}
|
|
9948
|
+
for (;c[i] === 0; c.pop(), i--)
|
|
9949
|
+
;
|
|
9950
|
+
if (i < 0) {
|
|
9951
|
+
c = [e = 0];
|
|
9952
|
+
} else {
|
|
9953
|
+
for (e = -1;c[0] === 0; c.splice(0, 1), e -= LOG_BASE)
|
|
9954
|
+
;
|
|
9955
|
+
for (i = 1, v = c[0];v >= 10; v /= 10, i++)
|
|
9956
|
+
;
|
|
9957
|
+
if (i < LOG_BASE)
|
|
9958
|
+
e -= LOG_BASE - i;
|
|
9959
|
+
}
|
|
9960
|
+
rand.e = e;
|
|
9961
|
+
rand.c = c;
|
|
9962
|
+
return rand;
|
|
9963
|
+
};
|
|
9964
|
+
}();
|
|
9965
|
+
BigNumber2.sum = function() {
|
|
9966
|
+
var i = 1, args = arguments, sum = new BigNumber2(args[0]);
|
|
9967
|
+
for (;i < args.length; )
|
|
9968
|
+
sum = sum.plus(args[i++]);
|
|
9969
|
+
return sum;
|
|
9970
|
+
};
|
|
9971
|
+
convertBase = function() {
|
|
9972
|
+
var decimal = "0123456789";
|
|
9973
|
+
function toBaseOut(str, baseIn, baseOut, alphabet) {
|
|
9974
|
+
var j, arr = [0], arrL, i = 0, len = str.length;
|
|
9975
|
+
for (;i < len; ) {
|
|
9976
|
+
for (arrL = arr.length;arrL--; arr[arrL] *= baseIn)
|
|
9977
|
+
;
|
|
9978
|
+
arr[0] += alphabet.indexOf(str.charAt(i++));
|
|
9979
|
+
for (j = 0;j < arr.length; j++) {
|
|
9980
|
+
if (arr[j] > baseOut - 1) {
|
|
9981
|
+
if (arr[j + 1] == null)
|
|
9982
|
+
arr[j + 1] = 0;
|
|
9983
|
+
arr[j + 1] += arr[j] / baseOut | 0;
|
|
9984
|
+
arr[j] %= baseOut;
|
|
9985
|
+
}
|
|
9986
|
+
}
|
|
9987
|
+
}
|
|
9988
|
+
return arr.reverse();
|
|
9989
|
+
}
|
|
9990
|
+
return function(str, baseIn, baseOut, sign, callerIsToString) {
|
|
9991
|
+
var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
|
|
9992
|
+
if (i >= 0) {
|
|
9993
|
+
k = POW_PRECISION;
|
|
9994
|
+
POW_PRECISION = 0;
|
|
9995
|
+
str = str.replace(".", "");
|
|
9996
|
+
y = new BigNumber2(baseIn);
|
|
9997
|
+
x = y.pow(str.length - i);
|
|
9998
|
+
POW_PRECISION = k;
|
|
9999
|
+
y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, "0"), 10, baseOut, decimal);
|
|
10000
|
+
y.e = y.c.length;
|
|
10001
|
+
}
|
|
10002
|
+
xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal) : (alphabet = decimal, ALPHABET));
|
|
10003
|
+
e = k = xc.length;
|
|
10004
|
+
for (;xc[--k] == 0; xc.pop())
|
|
10005
|
+
;
|
|
10006
|
+
if (!xc[0])
|
|
10007
|
+
return alphabet.charAt(0);
|
|
10008
|
+
if (i < 0) {
|
|
10009
|
+
--e;
|
|
10010
|
+
} else {
|
|
10011
|
+
x.c = xc;
|
|
10012
|
+
x.e = e;
|
|
10013
|
+
x.s = sign;
|
|
10014
|
+
x = div(x, y, dp, rm, baseOut);
|
|
10015
|
+
xc = x.c;
|
|
10016
|
+
r = x.r;
|
|
10017
|
+
e = x.e;
|
|
10018
|
+
}
|
|
10019
|
+
d = e + dp + 1;
|
|
10020
|
+
i = xc[d];
|
|
10021
|
+
k = baseOut / 2;
|
|
10022
|
+
r = r || d < 0 || xc[d + 1] != null;
|
|
10023
|
+
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));
|
|
10024
|
+
if (d < 1 || !xc[0]) {
|
|
10025
|
+
str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
|
|
10026
|
+
} else {
|
|
10027
|
+
xc.length = d;
|
|
10028
|
+
if (r) {
|
|
10029
|
+
for (--baseOut;++xc[--d] > baseOut; ) {
|
|
10030
|
+
xc[d] = 0;
|
|
10031
|
+
if (!d) {
|
|
10032
|
+
++e;
|
|
10033
|
+
xc = [1].concat(xc);
|
|
10034
|
+
}
|
|
10035
|
+
}
|
|
10036
|
+
}
|
|
10037
|
+
for (k = xc.length;!xc[--k]; )
|
|
10038
|
+
;
|
|
10039
|
+
for (i = 0, str = "";i <= k; str += alphabet.charAt(xc[i++]))
|
|
10040
|
+
;
|
|
10041
|
+
str = toFixedPoint(str, e, alphabet.charAt(0));
|
|
10042
|
+
}
|
|
10043
|
+
return str;
|
|
10044
|
+
};
|
|
10045
|
+
}();
|
|
10046
|
+
div = function() {
|
|
10047
|
+
function multiply(x, k, base) {
|
|
10048
|
+
var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
|
|
10049
|
+
for (x = x.slice();i--; ) {
|
|
10050
|
+
xlo = x[i] % SQRT_BASE;
|
|
10051
|
+
xhi = x[i] / SQRT_BASE | 0;
|
|
10052
|
+
m = khi * xlo + xhi * klo;
|
|
10053
|
+
temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
|
|
10054
|
+
carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
|
|
10055
|
+
x[i] = temp % base;
|
|
10056
|
+
}
|
|
10057
|
+
if (carry)
|
|
10058
|
+
x = [carry].concat(x);
|
|
10059
|
+
return x;
|
|
10060
|
+
}
|
|
10061
|
+
function compare(a, b, aL, bL) {
|
|
10062
|
+
var i, cmp;
|
|
10063
|
+
if (aL != bL) {
|
|
10064
|
+
cmp = aL > bL ? 1 : -1;
|
|
10065
|
+
} else {
|
|
10066
|
+
for (i = cmp = 0;i < aL; i++) {
|
|
10067
|
+
if (a[i] != b[i]) {
|
|
10068
|
+
cmp = a[i] > b[i] ? 1 : -1;
|
|
10069
|
+
break;
|
|
10070
|
+
}
|
|
10071
|
+
}
|
|
10072
|
+
}
|
|
10073
|
+
return cmp;
|
|
10074
|
+
}
|
|
10075
|
+
function subtract(a, b, aL, base) {
|
|
10076
|
+
var i = 0;
|
|
10077
|
+
for (;aL--; ) {
|
|
10078
|
+
a[aL] -= i;
|
|
10079
|
+
i = a[aL] < b[aL] ? 1 : 0;
|
|
10080
|
+
a[aL] = i * base + a[aL] - b[aL];
|
|
10081
|
+
}
|
|
10082
|
+
for (;!a[0] && a.length > 1; a.splice(0, 1))
|
|
10083
|
+
;
|
|
10084
|
+
}
|
|
10085
|
+
return function(x, y, dp, rm, base) {
|
|
10086
|
+
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;
|
|
10087
|
+
if (!xc || !xc[0] || !yc || !yc[0]) {
|
|
10088
|
+
return new BigNumber2(!x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : xc && xc[0] == 0 || !yc ? s * 0 : s / 0);
|
|
10089
|
+
}
|
|
10090
|
+
q = new BigNumber2(s);
|
|
10091
|
+
qc = q.c = [];
|
|
10092
|
+
e = x.e - y.e;
|
|
10093
|
+
s = dp + e + 1;
|
|
10094
|
+
if (!base) {
|
|
10095
|
+
base = BASE;
|
|
10096
|
+
e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
|
|
10097
|
+
s = s / LOG_BASE | 0;
|
|
10098
|
+
}
|
|
10099
|
+
for (i = 0;yc[i] == (xc[i] || 0); i++)
|
|
10100
|
+
;
|
|
10101
|
+
if (yc[i] > (xc[i] || 0))
|
|
10102
|
+
e--;
|
|
10103
|
+
if (s < 0) {
|
|
10104
|
+
qc.push(1);
|
|
10105
|
+
more = true;
|
|
10106
|
+
} else {
|
|
10107
|
+
xL = xc.length;
|
|
10108
|
+
yL = yc.length;
|
|
10109
|
+
i = 0;
|
|
10110
|
+
s += 2;
|
|
10111
|
+
n = mathfloor(base / (yc[0] + 1));
|
|
10112
|
+
if (n > 1) {
|
|
10113
|
+
yc = multiply(yc, n, base);
|
|
10114
|
+
xc = multiply(xc, n, base);
|
|
10115
|
+
yL = yc.length;
|
|
10116
|
+
xL = xc.length;
|
|
10117
|
+
}
|
|
10118
|
+
xi = yL;
|
|
10119
|
+
rem = xc.slice(0, yL);
|
|
10120
|
+
remL = rem.length;
|
|
10121
|
+
for (;remL < yL; rem[remL++] = 0)
|
|
10122
|
+
;
|
|
10123
|
+
yz = yc.slice();
|
|
10124
|
+
yz = [0].concat(yz);
|
|
10125
|
+
yc0 = yc[0];
|
|
10126
|
+
if (yc[1] >= base / 2)
|
|
10127
|
+
yc0++;
|
|
10128
|
+
do {
|
|
10129
|
+
n = 0;
|
|
10130
|
+
cmp = compare(yc, rem, yL, remL);
|
|
10131
|
+
if (cmp < 0) {
|
|
10132
|
+
rem0 = rem[0];
|
|
10133
|
+
if (yL != remL)
|
|
10134
|
+
rem0 = rem0 * base + (rem[1] || 0);
|
|
10135
|
+
n = mathfloor(rem0 / yc0);
|
|
10136
|
+
if (n > 1) {
|
|
10137
|
+
if (n >= base)
|
|
10138
|
+
n = base - 1;
|
|
10139
|
+
prod = multiply(yc, n, base);
|
|
10140
|
+
prodL = prod.length;
|
|
10141
|
+
remL = rem.length;
|
|
10142
|
+
while (compare(prod, rem, prodL, remL) == 1) {
|
|
10143
|
+
n--;
|
|
10144
|
+
subtract(prod, yL < prodL ? yz : yc, prodL, base);
|
|
10145
|
+
prodL = prod.length;
|
|
10146
|
+
cmp = 1;
|
|
10147
|
+
}
|
|
10148
|
+
} else {
|
|
10149
|
+
if (n == 0) {
|
|
10150
|
+
cmp = n = 1;
|
|
10151
|
+
}
|
|
10152
|
+
prod = yc.slice();
|
|
10153
|
+
prodL = prod.length;
|
|
10154
|
+
}
|
|
10155
|
+
if (prodL < remL)
|
|
10156
|
+
prod = [0].concat(prod);
|
|
10157
|
+
subtract(rem, prod, remL, base);
|
|
10158
|
+
remL = rem.length;
|
|
10159
|
+
if (cmp == -1) {
|
|
10160
|
+
while (compare(yc, rem, yL, remL) < 1) {
|
|
10161
|
+
n++;
|
|
10162
|
+
subtract(rem, yL < remL ? yz : yc, remL, base);
|
|
10163
|
+
remL = rem.length;
|
|
10164
|
+
}
|
|
10165
|
+
}
|
|
10166
|
+
} else if (cmp === 0) {
|
|
10167
|
+
n++;
|
|
10168
|
+
rem = [0];
|
|
10169
|
+
}
|
|
10170
|
+
qc[i++] = n;
|
|
10171
|
+
if (rem[0]) {
|
|
10172
|
+
rem[remL++] = xc[xi] || 0;
|
|
10173
|
+
} else {
|
|
10174
|
+
rem = [xc[xi]];
|
|
10175
|
+
remL = 1;
|
|
10176
|
+
}
|
|
10177
|
+
} while ((xi++ < xL || rem[0] != null) && s--);
|
|
10178
|
+
more = rem[0] != null;
|
|
10179
|
+
if (!qc[0])
|
|
10180
|
+
qc.splice(0, 1);
|
|
10181
|
+
}
|
|
10182
|
+
if (base == BASE) {
|
|
10183
|
+
for (i = 1, s = qc[0];s >= 10; s /= 10, i++)
|
|
10184
|
+
;
|
|
10185
|
+
round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
|
|
10186
|
+
} else {
|
|
10187
|
+
q.e = e;
|
|
10188
|
+
q.r = +more;
|
|
10189
|
+
}
|
|
10190
|
+
return q;
|
|
10191
|
+
};
|
|
10192
|
+
}();
|
|
10193
|
+
function format(n, i, rm, id2) {
|
|
10194
|
+
var c0, e, ne, len, str;
|
|
10195
|
+
if (rm == null)
|
|
10196
|
+
rm = ROUNDING_MODE;
|
|
10197
|
+
else
|
|
10198
|
+
intCheck(rm, 0, 8);
|
|
10199
|
+
if (!n.c)
|
|
10200
|
+
return n.toString();
|
|
10201
|
+
c0 = n.c[0];
|
|
10202
|
+
ne = n.e;
|
|
10203
|
+
if (i == null) {
|
|
10204
|
+
str = coeffToString(n.c);
|
|
10205
|
+
str = id2 == 1 || id2 == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
|
|
10206
|
+
} else {
|
|
10207
|
+
n = round(new BigNumber2(n), i, rm);
|
|
10208
|
+
e = n.e;
|
|
10209
|
+
str = coeffToString(n.c);
|
|
10210
|
+
len = str.length;
|
|
10211
|
+
if (id2 == 1 || id2 == 2 && (i <= e || e <= TO_EXP_NEG)) {
|
|
10212
|
+
for (;len < i; str += "0", len++)
|
|
10213
|
+
;
|
|
10214
|
+
str = toExponential(str, e);
|
|
10215
|
+
} else {
|
|
10216
|
+
i -= ne + (id2 === 2 && e > ne);
|
|
10217
|
+
str = toFixedPoint(str, e, "0");
|
|
10218
|
+
if (e + 1 > len) {
|
|
10219
|
+
if (--i > 0)
|
|
10220
|
+
for (str += ".";i--; str += "0")
|
|
10221
|
+
;
|
|
10222
|
+
} else {
|
|
10223
|
+
i += e - len;
|
|
10224
|
+
if (i > 0) {
|
|
10225
|
+
if (e + 1 == len)
|
|
10226
|
+
str += ".";
|
|
10227
|
+
for (;i--; str += "0")
|
|
10228
|
+
;
|
|
10229
|
+
}
|
|
10230
|
+
}
|
|
10231
|
+
}
|
|
10232
|
+
}
|
|
10233
|
+
return n.s < 0 && c0 ? "-" + str : str;
|
|
10234
|
+
}
|
|
10235
|
+
function isBigNumber(v) {
|
|
10236
|
+
return v instanceof BigNumber2 || !!v && v._isBigNumber === true;
|
|
10237
|
+
}
|
|
10238
|
+
function maxOrMin(args, n) {
|
|
10239
|
+
var k, y, i = 1, x = new BigNumber2(args[0]);
|
|
10240
|
+
for (;i < args.length; i++) {
|
|
10241
|
+
y = new BigNumber2(args[i]);
|
|
10242
|
+
if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) {
|
|
10243
|
+
x = y;
|
|
10244
|
+
}
|
|
10245
|
+
}
|
|
10246
|
+
return x;
|
|
10247
|
+
}
|
|
10248
|
+
function normalise(n, c, e) {
|
|
10249
|
+
var i = 1, j = c.length;
|
|
10250
|
+
for (;!c[--j]; c.pop())
|
|
10251
|
+
;
|
|
10252
|
+
for (j = c[0];j >= 10; j /= 10, i++)
|
|
10253
|
+
;
|
|
10254
|
+
if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
|
|
10255
|
+
n.c = n.e = null;
|
|
10256
|
+
} else if (e < MIN_EXP) {
|
|
10257
|
+
n.c = [n.e = 0];
|
|
10258
|
+
} else {
|
|
10259
|
+
n.e = e;
|
|
10260
|
+
n.c = c;
|
|
10261
|
+
}
|
|
10262
|
+
return n;
|
|
10263
|
+
}
|
|
10264
|
+
parseUnusualNumeric = function() {
|
|
10265
|
+
var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
|
|
10266
|
+
return function(x, str, b) {
|
|
10267
|
+
var base, s = str.replace(whitespaceOrPlus, "");
|
|
10268
|
+
if (isInfinityOrNaN.test(s)) {
|
|
10269
|
+
x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
|
|
10270
|
+
x.c = x.e = null;
|
|
10271
|
+
return;
|
|
10272
|
+
}
|
|
10273
|
+
s = s.replace(basePrefix, function(m, p1, p2) {
|
|
10274
|
+
base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
|
|
10275
|
+
return !b || b == base ? p1 : m;
|
|
10276
|
+
});
|
|
10277
|
+
if (b) {
|
|
10278
|
+
base = b;
|
|
10279
|
+
s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
|
|
10280
|
+
}
|
|
10281
|
+
if (str != s)
|
|
10282
|
+
return new BigNumber2(s, base);
|
|
10283
|
+
throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
|
|
10284
|
+
};
|
|
10285
|
+
}();
|
|
10286
|
+
function round(x, sd, rm, r) {
|
|
10287
|
+
var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
|
|
10288
|
+
if (xc) {
|
|
10289
|
+
out: {
|
|
10290
|
+
for (d = 1, k = xc[0];k >= 10; k /= 10, d++)
|
|
10291
|
+
;
|
|
10292
|
+
i = sd - d;
|
|
10293
|
+
if (i < 0) {
|
|
10294
|
+
i += LOG_BASE;
|
|
10295
|
+
j = sd;
|
|
10296
|
+
n = xc[ni = 0];
|
|
10297
|
+
rd = mathfloor(n / pows10[d - j - 1] % 10);
|
|
10298
|
+
} else {
|
|
10299
|
+
ni = mathceil((i + 1) / LOG_BASE);
|
|
10300
|
+
if (ni >= xc.length) {
|
|
10301
|
+
if (r) {
|
|
10302
|
+
for (;xc.length <= ni; xc.push(0))
|
|
10303
|
+
;
|
|
10304
|
+
n = rd = 0;
|
|
10305
|
+
d = 1;
|
|
10306
|
+
i %= LOG_BASE;
|
|
10307
|
+
j = i - LOG_BASE + 1;
|
|
10308
|
+
} else {
|
|
10309
|
+
break out;
|
|
10310
|
+
}
|
|
10311
|
+
} else {
|
|
10312
|
+
n = k = xc[ni];
|
|
10313
|
+
for (d = 1;k >= 10; k /= 10, d++)
|
|
10314
|
+
;
|
|
10315
|
+
i %= LOG_BASE;
|
|
10316
|
+
j = i - LOG_BASE + d;
|
|
10317
|
+
rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
|
|
10318
|
+
}
|
|
10319
|
+
}
|
|
10320
|
+
r = r || sd < 0 || xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
|
|
10321
|
+
r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && (i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
10322
|
+
if (sd < 1 || !xc[0]) {
|
|
10323
|
+
xc.length = 0;
|
|
10324
|
+
if (r) {
|
|
10325
|
+
sd -= x.e + 1;
|
|
10326
|
+
xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
|
|
10327
|
+
x.e = -sd || 0;
|
|
10328
|
+
} else {
|
|
10329
|
+
xc[0] = x.e = 0;
|
|
10330
|
+
}
|
|
10331
|
+
return x;
|
|
10332
|
+
}
|
|
10333
|
+
if (i == 0) {
|
|
10334
|
+
xc.length = ni;
|
|
10335
|
+
k = 1;
|
|
10336
|
+
ni--;
|
|
10337
|
+
} else {
|
|
10338
|
+
xc.length = ni + 1;
|
|
10339
|
+
k = pows10[LOG_BASE - i];
|
|
10340
|
+
xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
|
|
10341
|
+
}
|
|
10342
|
+
if (r) {
|
|
10343
|
+
for (;; ) {
|
|
10344
|
+
if (ni == 0) {
|
|
10345
|
+
for (i = 1, j = xc[0];j >= 10; j /= 10, i++)
|
|
10346
|
+
;
|
|
10347
|
+
j = xc[0] += k;
|
|
10348
|
+
for (k = 1;j >= 10; j /= 10, k++)
|
|
10349
|
+
;
|
|
10350
|
+
if (i != k) {
|
|
10351
|
+
x.e++;
|
|
10352
|
+
if (xc[0] == BASE)
|
|
10353
|
+
xc[0] = 1;
|
|
10354
|
+
}
|
|
10355
|
+
break;
|
|
10356
|
+
} else {
|
|
10357
|
+
xc[ni] += k;
|
|
10358
|
+
if (xc[ni] != BASE)
|
|
10359
|
+
break;
|
|
10360
|
+
xc[ni--] = 0;
|
|
10361
|
+
k = 1;
|
|
10362
|
+
}
|
|
10363
|
+
}
|
|
10364
|
+
}
|
|
10365
|
+
for (i = xc.length;xc[--i] === 0; xc.pop())
|
|
10366
|
+
;
|
|
10367
|
+
}
|
|
10368
|
+
if (x.e > MAX_EXP) {
|
|
10369
|
+
x.c = x.e = null;
|
|
10370
|
+
} else if (x.e < MIN_EXP) {
|
|
10371
|
+
x.c = [x.e = 0];
|
|
10372
|
+
}
|
|
10373
|
+
}
|
|
10374
|
+
return x;
|
|
10375
|
+
}
|
|
10376
|
+
function valueOf(n) {
|
|
10377
|
+
var str, e = n.e;
|
|
10378
|
+
if (e === null)
|
|
10379
|
+
return n.toString();
|
|
10380
|
+
str = coeffToString(n.c);
|
|
10381
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
|
|
10382
|
+
return n.s < 0 ? "-" + str : str;
|
|
10383
|
+
}
|
|
10384
|
+
P.absoluteValue = P.abs = function() {
|
|
10385
|
+
var x = new BigNumber2(this);
|
|
10386
|
+
if (x.s < 0)
|
|
10387
|
+
x.s = 1;
|
|
10388
|
+
return x;
|
|
10389
|
+
};
|
|
10390
|
+
P.comparedTo = function(y, b) {
|
|
10391
|
+
return compare(this, new BigNumber2(y, b));
|
|
10392
|
+
};
|
|
10393
|
+
P.decimalPlaces = P.dp = function(dp, rm) {
|
|
10394
|
+
var c, n, v, x = this;
|
|
10395
|
+
if (dp != null) {
|
|
10396
|
+
intCheck(dp, 0, MAX);
|
|
10397
|
+
if (rm == null)
|
|
10398
|
+
rm = ROUNDING_MODE;
|
|
10399
|
+
else
|
|
10400
|
+
intCheck(rm, 0, 8);
|
|
10401
|
+
return round(new BigNumber2(x), dp + x.e + 1, rm);
|
|
10402
|
+
}
|
|
10403
|
+
if (!(c = x.c))
|
|
10404
|
+
return null;
|
|
10405
|
+
n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
10406
|
+
if (v = c[v])
|
|
10407
|
+
for (;v % 10 == 0; v /= 10, n--)
|
|
10408
|
+
;
|
|
10409
|
+
if (n < 0)
|
|
10410
|
+
n = 0;
|
|
10411
|
+
return n;
|
|
10412
|
+
};
|
|
10413
|
+
P.dividedBy = P.div = function(y, b) {
|
|
10414
|
+
return div(this, new BigNumber2(y, b), DECIMAL_PLACES, ROUNDING_MODE);
|
|
10415
|
+
};
|
|
10416
|
+
P.dividedToIntegerBy = P.idiv = function(y, b) {
|
|
10417
|
+
return div(this, new BigNumber2(y, b), 0, 1);
|
|
10418
|
+
};
|
|
10419
|
+
P.exponentiatedBy = P.pow = function(n, m) {
|
|
10420
|
+
var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
|
|
10421
|
+
n = new BigNumber2(n);
|
|
10422
|
+
if (n.c && !n.isInteger()) {
|
|
10423
|
+
throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
|
|
10424
|
+
}
|
|
10425
|
+
if (m != null)
|
|
10426
|
+
m = new BigNumber2(m);
|
|
10427
|
+
nIsBig = n.e > 14;
|
|
10428
|
+
if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
|
|
10429
|
+
y = new BigNumber2(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
|
|
10430
|
+
return m ? y.mod(m) : y;
|
|
10431
|
+
}
|
|
10432
|
+
nIsNeg = n.s < 0;
|
|
10433
|
+
if (m) {
|
|
10434
|
+
if (m.c ? !m.c[0] : !m.s)
|
|
10435
|
+
return new BigNumber2(NaN);
|
|
10436
|
+
isModExp = !nIsNeg && x.isInteger() && m.isInteger();
|
|
10437
|
+
if (isModExp)
|
|
10438
|
+
x = x.mod(m);
|
|
10439
|
+
} else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0 ? x.c[0] > 1 || nIsBig && x.c[1] >= 240000000 : x.c[0] < 80000000000000 || nIsBig && x.c[0] <= 99999750000000))) {
|
|
10440
|
+
k = x.s < 0 && isOdd(n) ? -0 : 0;
|
|
10441
|
+
if (x.e > -1)
|
|
10442
|
+
k = 1 / k;
|
|
10443
|
+
return new BigNumber2(nIsNeg ? 1 / k : k);
|
|
10444
|
+
} else if (POW_PRECISION) {
|
|
10445
|
+
k = mathceil(POW_PRECISION / LOG_BASE + 2);
|
|
10446
|
+
}
|
|
10447
|
+
if (nIsBig) {
|
|
10448
|
+
half = new BigNumber2(0.5);
|
|
10449
|
+
if (nIsNeg)
|
|
10450
|
+
n.s = 1;
|
|
10451
|
+
nIsOdd = isOdd(n);
|
|
10452
|
+
} else {
|
|
10453
|
+
i = Math.abs(+valueOf(n));
|
|
10454
|
+
nIsOdd = i % 2;
|
|
10455
|
+
}
|
|
10456
|
+
y = new BigNumber2(ONE);
|
|
10457
|
+
for (;; ) {
|
|
10458
|
+
if (nIsOdd) {
|
|
10459
|
+
y = y.times(x);
|
|
10460
|
+
if (!y.c)
|
|
10461
|
+
break;
|
|
10462
|
+
if (k) {
|
|
10463
|
+
if (y.c.length > k)
|
|
10464
|
+
y.c.length = k;
|
|
10465
|
+
} else if (isModExp) {
|
|
10466
|
+
y = y.mod(m);
|
|
10467
|
+
}
|
|
10468
|
+
}
|
|
10469
|
+
if (i) {
|
|
10470
|
+
i = mathfloor(i / 2);
|
|
10471
|
+
if (i === 0)
|
|
10472
|
+
break;
|
|
10473
|
+
nIsOdd = i % 2;
|
|
10474
|
+
} else {
|
|
10475
|
+
n = n.times(half);
|
|
10476
|
+
round(n, n.e + 1, 1);
|
|
10477
|
+
if (n.e > 14) {
|
|
10478
|
+
nIsOdd = isOdd(n);
|
|
10479
|
+
} else {
|
|
10480
|
+
i = +valueOf(n);
|
|
10481
|
+
if (i === 0)
|
|
10482
|
+
break;
|
|
10483
|
+
nIsOdd = i % 2;
|
|
10484
|
+
}
|
|
10485
|
+
}
|
|
10486
|
+
x = x.times(x);
|
|
10487
|
+
if (k) {
|
|
10488
|
+
if (x.c && x.c.length > k)
|
|
10489
|
+
x.c.length = k;
|
|
10490
|
+
} else if (isModExp) {
|
|
10491
|
+
x = x.mod(m);
|
|
10492
|
+
}
|
|
10493
|
+
}
|
|
10494
|
+
if (isModExp)
|
|
10495
|
+
return y;
|
|
10496
|
+
if (nIsNeg)
|
|
10497
|
+
y = ONE.div(y);
|
|
10498
|
+
return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
|
|
10499
|
+
};
|
|
10500
|
+
P.integerValue = function(rm) {
|
|
10501
|
+
var n = new BigNumber2(this);
|
|
10502
|
+
if (rm == null)
|
|
10503
|
+
rm = ROUNDING_MODE;
|
|
10504
|
+
else
|
|
10505
|
+
intCheck(rm, 0, 8);
|
|
10506
|
+
return round(n, n.e + 1, rm);
|
|
10507
|
+
};
|
|
10508
|
+
P.isEqualTo = P.eq = function(y, b) {
|
|
10509
|
+
return compare(this, new BigNumber2(y, b)) === 0;
|
|
10510
|
+
};
|
|
10511
|
+
P.isFinite = function() {
|
|
10512
|
+
return !!this.c;
|
|
10513
|
+
};
|
|
10514
|
+
P.isGreaterThan = P.gt = function(y, b) {
|
|
10515
|
+
return compare(this, new BigNumber2(y, b)) > 0;
|
|
10516
|
+
};
|
|
10517
|
+
P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
|
|
10518
|
+
return (b = compare(this, new BigNumber2(y, b))) === 1 || b === 0;
|
|
10519
|
+
};
|
|
10520
|
+
P.isInteger = function() {
|
|
10521
|
+
return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
|
|
10522
|
+
};
|
|
10523
|
+
P.isLessThan = P.lt = function(y, b) {
|
|
10524
|
+
return compare(this, new BigNumber2(y, b)) < 0;
|
|
10525
|
+
};
|
|
10526
|
+
P.isLessThanOrEqualTo = P.lte = function(y, b) {
|
|
10527
|
+
return (b = compare(this, new BigNumber2(y, b))) === -1 || b === 0;
|
|
10528
|
+
};
|
|
10529
|
+
P.isNaN = function() {
|
|
10530
|
+
return !this.s;
|
|
10531
|
+
};
|
|
10532
|
+
P.isNegative = function() {
|
|
10533
|
+
return this.s < 0;
|
|
10534
|
+
};
|
|
10535
|
+
P.isPositive = function() {
|
|
10536
|
+
return this.s > 0;
|
|
10537
|
+
};
|
|
10538
|
+
P.isZero = function() {
|
|
10539
|
+
return !!this.c && this.c[0] == 0;
|
|
10540
|
+
};
|
|
10541
|
+
P.minus = function(y, b) {
|
|
10542
|
+
var i, j, t, xLTy, x = this, a = x.s;
|
|
10543
|
+
y = new BigNumber2(y, b);
|
|
10544
|
+
b = y.s;
|
|
10545
|
+
if (!a || !b)
|
|
10546
|
+
return new BigNumber2(NaN);
|
|
10547
|
+
if (a != b) {
|
|
10548
|
+
y.s = -b;
|
|
10549
|
+
return x.plus(y);
|
|
10550
|
+
}
|
|
10551
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
10552
|
+
if (!xe || !ye) {
|
|
10553
|
+
if (!xc || !yc)
|
|
10554
|
+
return xc ? (y.s = -b, y) : new BigNumber2(yc ? x : NaN);
|
|
10555
|
+
if (!xc[0] || !yc[0]) {
|
|
10556
|
+
return yc[0] ? (y.s = -b, y) : new BigNumber2(xc[0] ? x : ROUNDING_MODE == 3 ? -0 : 0);
|
|
10557
|
+
}
|
|
10558
|
+
}
|
|
10559
|
+
xe = bitFloor(xe);
|
|
10560
|
+
ye = bitFloor(ye);
|
|
10561
|
+
xc = xc.slice();
|
|
10562
|
+
if (a = xe - ye) {
|
|
10563
|
+
if (xLTy = a < 0) {
|
|
10564
|
+
a = -a;
|
|
10565
|
+
t = xc;
|
|
10566
|
+
} else {
|
|
10567
|
+
ye = xe;
|
|
10568
|
+
t = yc;
|
|
10569
|
+
}
|
|
10570
|
+
t.reverse();
|
|
10571
|
+
for (b = a;b--; t.push(0))
|
|
10572
|
+
;
|
|
10573
|
+
t.reverse();
|
|
10574
|
+
} else {
|
|
10575
|
+
j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
|
|
10576
|
+
for (a = b = 0;b < j; b++) {
|
|
10577
|
+
if (xc[b] != yc[b]) {
|
|
10578
|
+
xLTy = xc[b] < yc[b];
|
|
10579
|
+
break;
|
|
10580
|
+
}
|
|
10581
|
+
}
|
|
10582
|
+
}
|
|
10583
|
+
if (xLTy) {
|
|
10584
|
+
t = xc;
|
|
10585
|
+
xc = yc;
|
|
10586
|
+
yc = t;
|
|
10587
|
+
y.s = -y.s;
|
|
10588
|
+
}
|
|
10589
|
+
b = (j = yc.length) - (i = xc.length);
|
|
10590
|
+
if (b > 0)
|
|
10591
|
+
for (;b--; xc[i++] = 0)
|
|
10592
|
+
;
|
|
10593
|
+
b = BASE - 1;
|
|
10594
|
+
for (;j > a; ) {
|
|
10595
|
+
if (xc[--j] < yc[j]) {
|
|
10596
|
+
for (i = j;i && !xc[--i]; xc[i] = b)
|
|
10597
|
+
;
|
|
10598
|
+
--xc[i];
|
|
10599
|
+
xc[j] += BASE;
|
|
10600
|
+
}
|
|
10601
|
+
xc[j] -= yc[j];
|
|
10602
|
+
}
|
|
10603
|
+
for (;xc[0] == 0; xc.splice(0, 1), --ye)
|
|
10604
|
+
;
|
|
10605
|
+
if (!xc[0]) {
|
|
10606
|
+
y.s = ROUNDING_MODE == 3 ? -1 : 1;
|
|
10607
|
+
y.c = [y.e = 0];
|
|
10608
|
+
return y;
|
|
10609
|
+
}
|
|
10610
|
+
return normalise(y, xc, ye);
|
|
10611
|
+
};
|
|
10612
|
+
P.modulo = P.mod = function(y, b) {
|
|
10613
|
+
var q, s, x = this;
|
|
10614
|
+
y = new BigNumber2(y, b);
|
|
10615
|
+
if (!x.c || !y.s || y.c && !y.c[0]) {
|
|
10616
|
+
return new BigNumber2(NaN);
|
|
10617
|
+
} else if (!y.c || x.c && !x.c[0]) {
|
|
10618
|
+
return new BigNumber2(x);
|
|
10619
|
+
}
|
|
10620
|
+
if (MODULO_MODE == 9) {
|
|
10621
|
+
s = y.s;
|
|
10622
|
+
y.s = 1;
|
|
10623
|
+
q = div(x, y, 0, 3);
|
|
10624
|
+
y.s = s;
|
|
10625
|
+
q.s *= s;
|
|
10626
|
+
} else {
|
|
10627
|
+
q = div(x, y, 0, MODULO_MODE);
|
|
10628
|
+
}
|
|
10629
|
+
y = x.minus(q.times(y));
|
|
10630
|
+
if (!y.c[0] && MODULO_MODE == 1)
|
|
10631
|
+
y.s = x.s;
|
|
10632
|
+
return y;
|
|
10633
|
+
};
|
|
10634
|
+
P.multipliedBy = P.times = function(y, b) {
|
|
10635
|
+
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;
|
|
10636
|
+
if (!xc || !yc || !xc[0] || !yc[0]) {
|
|
10637
|
+
if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
|
|
10638
|
+
y.c = y.e = y.s = null;
|
|
10639
|
+
} else {
|
|
10640
|
+
y.s *= x.s;
|
|
10641
|
+
if (!xc || !yc) {
|
|
10642
|
+
y.c = y.e = null;
|
|
10643
|
+
} else {
|
|
10644
|
+
y.c = [0];
|
|
10645
|
+
y.e = 0;
|
|
10646
|
+
}
|
|
10647
|
+
}
|
|
10648
|
+
return y;
|
|
10649
|
+
}
|
|
10650
|
+
e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
|
|
10651
|
+
y.s *= x.s;
|
|
10652
|
+
xcL = xc.length;
|
|
10653
|
+
ycL = yc.length;
|
|
10654
|
+
if (xcL < ycL) {
|
|
10655
|
+
zc = xc;
|
|
10656
|
+
xc = yc;
|
|
10657
|
+
yc = zc;
|
|
10658
|
+
i = xcL;
|
|
10659
|
+
xcL = ycL;
|
|
10660
|
+
ycL = i;
|
|
10661
|
+
}
|
|
10662
|
+
for (i = xcL + ycL, zc = [];i--; zc.push(0))
|
|
10663
|
+
;
|
|
10664
|
+
base = BASE;
|
|
10665
|
+
sqrtBase = SQRT_BASE;
|
|
10666
|
+
for (i = ycL;--i >= 0; ) {
|
|
10667
|
+
c = 0;
|
|
10668
|
+
ylo = yc[i] % sqrtBase;
|
|
10669
|
+
yhi = yc[i] / sqrtBase | 0;
|
|
10670
|
+
for (k = xcL, j = i + k;j > i; ) {
|
|
10671
|
+
xlo = xc[--k] % sqrtBase;
|
|
10672
|
+
xhi = xc[k] / sqrtBase | 0;
|
|
10673
|
+
m = yhi * xlo + xhi * ylo;
|
|
10674
|
+
xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
|
|
10675
|
+
c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
|
|
10676
|
+
zc[j--] = xlo % base;
|
|
10677
|
+
}
|
|
10678
|
+
zc[j] = c;
|
|
10679
|
+
}
|
|
10680
|
+
if (c) {
|
|
10681
|
+
++e;
|
|
10682
|
+
} else {
|
|
10683
|
+
zc.splice(0, 1);
|
|
10684
|
+
}
|
|
10685
|
+
return normalise(y, zc, e);
|
|
10686
|
+
};
|
|
10687
|
+
P.negated = function() {
|
|
10688
|
+
var x = new BigNumber2(this);
|
|
10689
|
+
x.s = -x.s || null;
|
|
10690
|
+
return x;
|
|
10691
|
+
};
|
|
10692
|
+
P.plus = function(y, b) {
|
|
10693
|
+
var t, x = this, a = x.s;
|
|
10694
|
+
y = new BigNumber2(y, b);
|
|
10695
|
+
b = y.s;
|
|
10696
|
+
if (!a || !b)
|
|
10697
|
+
return new BigNumber2(NaN);
|
|
10698
|
+
if (a != b) {
|
|
10699
|
+
y.s = -b;
|
|
10700
|
+
return x.minus(y);
|
|
10701
|
+
}
|
|
10702
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
10703
|
+
if (!xe || !ye) {
|
|
10704
|
+
if (!xc || !yc)
|
|
10705
|
+
return new BigNumber2(a / 0);
|
|
10706
|
+
if (!xc[0] || !yc[0])
|
|
10707
|
+
return yc[0] ? y : new BigNumber2(xc[0] ? x : a * 0);
|
|
10708
|
+
}
|
|
10709
|
+
xe = bitFloor(xe);
|
|
10710
|
+
ye = bitFloor(ye);
|
|
10711
|
+
xc = xc.slice();
|
|
10712
|
+
if (a = xe - ye) {
|
|
10713
|
+
if (a > 0) {
|
|
10714
|
+
ye = xe;
|
|
10715
|
+
t = yc;
|
|
10716
|
+
} else {
|
|
10717
|
+
a = -a;
|
|
10718
|
+
t = xc;
|
|
10719
|
+
}
|
|
10720
|
+
t.reverse();
|
|
10721
|
+
for (;a--; t.push(0))
|
|
10722
|
+
;
|
|
10723
|
+
t.reverse();
|
|
10724
|
+
}
|
|
10725
|
+
a = xc.length;
|
|
10726
|
+
b = yc.length;
|
|
10727
|
+
if (a - b < 0) {
|
|
10728
|
+
t = yc;
|
|
10729
|
+
yc = xc;
|
|
10730
|
+
xc = t;
|
|
10731
|
+
b = a;
|
|
10732
|
+
}
|
|
10733
|
+
for (a = 0;b; ) {
|
|
10734
|
+
a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
|
|
10735
|
+
xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
|
|
10736
|
+
}
|
|
10737
|
+
if (a) {
|
|
10738
|
+
xc = [a].concat(xc);
|
|
10739
|
+
++ye;
|
|
10740
|
+
}
|
|
10741
|
+
return normalise(y, xc, ye);
|
|
10742
|
+
};
|
|
10743
|
+
P.precision = P.sd = function(sd, rm) {
|
|
10744
|
+
var c, n, v, x = this;
|
|
10745
|
+
if (sd != null && sd !== !!sd) {
|
|
10746
|
+
intCheck(sd, 1, MAX);
|
|
10747
|
+
if (rm == null)
|
|
10748
|
+
rm = ROUNDING_MODE;
|
|
10749
|
+
else
|
|
10750
|
+
intCheck(rm, 0, 8);
|
|
10751
|
+
return round(new BigNumber2(x), sd, rm);
|
|
10752
|
+
}
|
|
10753
|
+
if (!(c = x.c))
|
|
10754
|
+
return null;
|
|
10755
|
+
v = c.length - 1;
|
|
10756
|
+
n = v * LOG_BASE + 1;
|
|
10757
|
+
if (v = c[v]) {
|
|
10758
|
+
for (;v % 10 == 0; v /= 10, n--)
|
|
10759
|
+
;
|
|
10760
|
+
for (v = c[0];v >= 10; v /= 10, n++)
|
|
10761
|
+
;
|
|
10762
|
+
}
|
|
10763
|
+
if (sd && x.e + 1 > n)
|
|
10764
|
+
n = x.e + 1;
|
|
10765
|
+
return n;
|
|
10766
|
+
};
|
|
10767
|
+
P.shiftedBy = function(k) {
|
|
10768
|
+
intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
|
10769
|
+
return this.times("1e" + k);
|
|
10770
|
+
};
|
|
10771
|
+
P.squareRoot = P.sqrt = function() {
|
|
10772
|
+
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");
|
|
10773
|
+
if (s !== 1 || !c || !c[0]) {
|
|
10774
|
+
return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
|
|
10775
|
+
}
|
|
10776
|
+
s = Math.sqrt(+valueOf(x));
|
|
10777
|
+
if (s == 0 || s == 1 / 0) {
|
|
10778
|
+
n = coeffToString(c);
|
|
10779
|
+
if ((n.length + e) % 2 == 0)
|
|
10780
|
+
n += "0";
|
|
10781
|
+
s = Math.sqrt(+n);
|
|
10782
|
+
e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
10783
|
+
if (s == 1 / 0) {
|
|
10784
|
+
n = "5e" + e;
|
|
10785
|
+
} else {
|
|
10786
|
+
n = s.toExponential();
|
|
10787
|
+
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
10788
|
+
}
|
|
10789
|
+
r = new BigNumber2(n);
|
|
10790
|
+
} else {
|
|
10791
|
+
r = new BigNumber2(s + "");
|
|
10792
|
+
}
|
|
10793
|
+
if (r.c[0]) {
|
|
10794
|
+
e = r.e;
|
|
10795
|
+
s = e + dp;
|
|
10796
|
+
if (s < 3)
|
|
10797
|
+
s = 0;
|
|
10798
|
+
for (;; ) {
|
|
10799
|
+
t = r;
|
|
10800
|
+
r = half.times(t.plus(div(x, t, dp, 1)));
|
|
10801
|
+
if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
|
|
10802
|
+
if (r.e < e)
|
|
10803
|
+
--s;
|
|
10804
|
+
n = n.slice(s - 3, s + 1);
|
|
10805
|
+
if (n == "9999" || !rep && n == "4999") {
|
|
10806
|
+
if (!rep) {
|
|
10807
|
+
round(t, t.e + DECIMAL_PLACES + 2, 0);
|
|
10808
|
+
if (t.times(t).eq(x)) {
|
|
10809
|
+
r = t;
|
|
10810
|
+
break;
|
|
10811
|
+
}
|
|
10812
|
+
}
|
|
10813
|
+
dp += 4;
|
|
10814
|
+
s += 4;
|
|
10815
|
+
rep = 1;
|
|
10816
|
+
} else {
|
|
10817
|
+
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
10818
|
+
round(r, r.e + DECIMAL_PLACES + 2, 1);
|
|
10819
|
+
m = !r.times(r).eq(x);
|
|
10820
|
+
}
|
|
10821
|
+
break;
|
|
10822
|
+
}
|
|
10823
|
+
}
|
|
10824
|
+
}
|
|
10825
|
+
}
|
|
10826
|
+
return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
|
|
10827
|
+
};
|
|
10828
|
+
P.toExponential = function(dp, rm) {
|
|
10829
|
+
if (dp != null) {
|
|
10830
|
+
intCheck(dp, 0, MAX);
|
|
10831
|
+
dp++;
|
|
10832
|
+
}
|
|
10833
|
+
return format(this, dp, rm, 1);
|
|
10834
|
+
};
|
|
10835
|
+
P.toFixed = function(dp, rm) {
|
|
10836
|
+
if (dp != null) {
|
|
10837
|
+
intCheck(dp, 0, MAX);
|
|
10838
|
+
dp = dp + this.e + 1;
|
|
10839
|
+
}
|
|
10840
|
+
return format(this, dp, rm);
|
|
10841
|
+
};
|
|
10842
|
+
P.toFormat = function(dp, rm, format2) {
|
|
10843
|
+
var str, x = this;
|
|
10844
|
+
if (format2 == null) {
|
|
10845
|
+
if (dp != null && rm && typeof rm == "object") {
|
|
10846
|
+
format2 = rm;
|
|
10847
|
+
rm = null;
|
|
10848
|
+
} else if (dp && typeof dp == "object") {
|
|
10849
|
+
format2 = dp;
|
|
10850
|
+
dp = rm = null;
|
|
10851
|
+
} else {
|
|
10852
|
+
format2 = FORMAT;
|
|
10853
|
+
}
|
|
10854
|
+
} else if (typeof format2 != "object") {
|
|
10855
|
+
throw Error(bignumberError + "Argument not an object: " + format2);
|
|
10856
|
+
}
|
|
10857
|
+
str = x.toFixed(dp, rm);
|
|
10858
|
+
if (x.c) {
|
|
10859
|
+
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;
|
|
10860
|
+
if (g2) {
|
|
10861
|
+
i = g1;
|
|
10862
|
+
g1 = g2;
|
|
10863
|
+
g2 = i;
|
|
10864
|
+
len -= i;
|
|
10865
|
+
}
|
|
10866
|
+
if (g1 > 0 && len > 0) {
|
|
10867
|
+
i = len % g1 || g1;
|
|
10868
|
+
intPart = intDigits.substr(0, i);
|
|
10869
|
+
for (;i < len; i += g1)
|
|
10870
|
+
intPart += groupSeparator + intDigits.substr(i, g1);
|
|
10871
|
+
if (g2 > 0)
|
|
10872
|
+
intPart += groupSeparator + intDigits.slice(i);
|
|
10873
|
+
if (isNeg)
|
|
10874
|
+
intPart = "-" + intPart;
|
|
10875
|
+
}
|
|
10876
|
+
str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(new RegExp("\\d{" + g2 + "}\\B", "g"), "$&" + (format2.fractionGroupSeparator || "")) : fractionPart) : intPart;
|
|
10877
|
+
}
|
|
10878
|
+
return (format2.prefix || "") + str + (format2.suffix || "");
|
|
10879
|
+
};
|
|
10880
|
+
P.toFraction = function(md) {
|
|
10881
|
+
var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
|
|
10882
|
+
if (md != null) {
|
|
10883
|
+
n = new BigNumber2(md);
|
|
10884
|
+
if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
|
|
10885
|
+
throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
|
|
10886
|
+
}
|
|
10887
|
+
}
|
|
10888
|
+
if (!xc)
|
|
10889
|
+
return new BigNumber2(x);
|
|
10890
|
+
d = new BigNumber2(ONE);
|
|
10891
|
+
n1 = d0 = new BigNumber2(ONE);
|
|
10892
|
+
d1 = n0 = new BigNumber2(ONE);
|
|
10893
|
+
s = coeffToString(xc);
|
|
10894
|
+
e = d.e = s.length - x.e - 1;
|
|
10895
|
+
d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
|
|
10896
|
+
md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
|
|
10897
|
+
exp = MAX_EXP;
|
|
10898
|
+
MAX_EXP = 1 / 0;
|
|
10899
|
+
n = new BigNumber2(s);
|
|
10900
|
+
n0.c[0] = 0;
|
|
10901
|
+
for (;; ) {
|
|
10902
|
+
q = div(n, d, 0, 1);
|
|
10903
|
+
d2 = d0.plus(q.times(d1));
|
|
10904
|
+
if (d2.comparedTo(md) == 1)
|
|
10905
|
+
break;
|
|
10906
|
+
d0 = d1;
|
|
10907
|
+
d1 = d2;
|
|
10908
|
+
n1 = n0.plus(q.times(d2 = n1));
|
|
10909
|
+
n0 = d2;
|
|
10910
|
+
d = n.minus(q.times(d2 = d));
|
|
10911
|
+
n = d2;
|
|
10912
|
+
}
|
|
10913
|
+
d2 = div(md.minus(d0), d1, 0, 1);
|
|
10914
|
+
n0 = n0.plus(d2.times(n1));
|
|
10915
|
+
d0 = d0.plus(d2.times(d1));
|
|
10916
|
+
n0.s = n1.s = x.s;
|
|
10917
|
+
e = e * 2;
|
|
10918
|
+
r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
|
|
10919
|
+
MAX_EXP = exp;
|
|
10920
|
+
return r;
|
|
10921
|
+
};
|
|
10922
|
+
P.toNumber = function() {
|
|
10923
|
+
return +valueOf(this);
|
|
10924
|
+
};
|
|
10925
|
+
P.toObject = function() {
|
|
10926
|
+
var x = this;
|
|
10927
|
+
return {
|
|
10928
|
+
c: x.c ? x.c.slice() : null,
|
|
10929
|
+
e: x.e,
|
|
10930
|
+
s: x.s
|
|
10931
|
+
};
|
|
10932
|
+
};
|
|
10933
|
+
P.toPrecision = function(sd, rm) {
|
|
10934
|
+
if (sd != null)
|
|
10935
|
+
intCheck(sd, 1, MAX);
|
|
10936
|
+
return format(this, sd, rm, 2);
|
|
10937
|
+
};
|
|
10938
|
+
P.toString = function(b) {
|
|
10939
|
+
var str, n = this, s = n.s, e = n.e;
|
|
10940
|
+
if (e === null) {
|
|
10941
|
+
if (s) {
|
|
10942
|
+
str = "Infinity";
|
|
10943
|
+
if (s < 0)
|
|
10944
|
+
str = "-" + str;
|
|
10945
|
+
} else {
|
|
10946
|
+
str = "NaN";
|
|
10947
|
+
}
|
|
10948
|
+
} else {
|
|
10949
|
+
if (b == null) {
|
|
10950
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
|
|
10951
|
+
} else {
|
|
10952
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
10953
|
+
str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
|
|
10954
|
+
}
|
|
10955
|
+
if (s < 0 && n.c[0])
|
|
10956
|
+
str = "-" + str;
|
|
10957
|
+
}
|
|
10958
|
+
return str;
|
|
10959
|
+
};
|
|
10960
|
+
P.valueOf = P.toJSON = function() {
|
|
10961
|
+
return valueOf(this);
|
|
10962
|
+
};
|
|
10963
|
+
P._isBigNumber = true;
|
|
10964
|
+
if (configObject != null)
|
|
10965
|
+
BigNumber2.set(configObject);
|
|
10966
|
+
return BigNumber2;
|
|
10967
|
+
}
|
|
10968
|
+
function bitFloor(n) {
|
|
10969
|
+
var i = n | 0;
|
|
10970
|
+
return n > 0 || n === i ? i : i - 1;
|
|
10971
|
+
}
|
|
10972
|
+
function coeffToString(a) {
|
|
10973
|
+
var s, z, i = 1, j = a.length, r = a[0] + "";
|
|
10974
|
+
for (;i < j; ) {
|
|
10975
|
+
s = a[i++] + "";
|
|
10976
|
+
z = LOG_BASE - s.length;
|
|
10977
|
+
for (;z--; s = "0" + s)
|
|
10978
|
+
;
|
|
10979
|
+
r += s;
|
|
10980
|
+
}
|
|
10981
|
+
for (j = r.length;r.charCodeAt(--j) === 48; )
|
|
10982
|
+
;
|
|
10983
|
+
return r.slice(0, j + 1 || 1);
|
|
10984
|
+
}
|
|
10985
|
+
function compare(x, y) {
|
|
10986
|
+
var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
|
|
10987
|
+
if (!i || !j)
|
|
10988
|
+
return null;
|
|
10989
|
+
a = xc && !xc[0];
|
|
10990
|
+
b = yc && !yc[0];
|
|
10991
|
+
if (a || b)
|
|
10992
|
+
return a ? b ? 0 : -j : i;
|
|
10993
|
+
if (i != j)
|
|
10994
|
+
return i;
|
|
10995
|
+
a = i < 0;
|
|
10996
|
+
b = k == l;
|
|
10997
|
+
if (!xc || !yc)
|
|
10998
|
+
return b ? 0 : !xc ^ a ? 1 : -1;
|
|
10999
|
+
if (!b)
|
|
11000
|
+
return k > l ^ a ? 1 : -1;
|
|
11001
|
+
j = (k = xc.length) < (l = yc.length) ? k : l;
|
|
11002
|
+
for (i = 0;i < j; i++)
|
|
11003
|
+
if (xc[i] != yc[i])
|
|
11004
|
+
return xc[i] > yc[i] ^ a ? 1 : -1;
|
|
11005
|
+
return k == l ? 0 : k > l ^ a ? 1 : -1;
|
|
11006
|
+
}
|
|
11007
|
+
function intCheck(n, min, max, name) {
|
|
11008
|
+
if (n < min || n > max || n !== mathfloor(n)) {
|
|
11009
|
+
throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
|
|
11010
|
+
}
|
|
11011
|
+
}
|
|
11012
|
+
function isOdd(n) {
|
|
11013
|
+
var k = n.c.length - 1;
|
|
11014
|
+
return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
|
|
11015
|
+
}
|
|
11016
|
+
function toExponential(str, e) {
|
|
11017
|
+
return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
|
|
11018
|
+
}
|
|
11019
|
+
function toFixedPoint(str, e, z) {
|
|
11020
|
+
var len, zs;
|
|
11021
|
+
if (e < 0) {
|
|
11022
|
+
for (zs = z + ".";++e; zs += z)
|
|
11023
|
+
;
|
|
11024
|
+
str = zs + str;
|
|
11025
|
+
} else {
|
|
11026
|
+
len = str.length;
|
|
11027
|
+
if (++e > len) {
|
|
11028
|
+
for (zs = z, e -= len;--e; zs += z)
|
|
11029
|
+
;
|
|
11030
|
+
str += zs;
|
|
11031
|
+
} else if (e < len) {
|
|
11032
|
+
str = str.slice(0, e) + "." + str.slice(e);
|
|
11033
|
+
}
|
|
11034
|
+
}
|
|
11035
|
+
return str;
|
|
11036
|
+
}
|
|
11037
|
+
var bignumber_default = BigNumber;
|
|
11038
|
+
|
|
9591
11039
|
// src/services/recording/campaign.ts
|
|
9592
11040
|
async function checkJoinStatus(baseUrl, accessToken, chainId, address) {
|
|
9593
11041
|
return await requestJson(`${baseUrl}/campaigns/check-join-status`, {
|
|
@@ -9648,7 +11096,7 @@ function getLauncherUrl() {
|
|
|
9648
11096
|
}
|
|
9649
11097
|
function createCampaignCommand() {
|
|
9650
11098
|
const campaign = new Command("campaign").description("Campaign management commands");
|
|
9651
|
-
campaign.command("list").description("List available campaigns").option("-c, --chain-id <id>", "Chain ID", Number,
|
|
11099
|
+
campaign.command("list").description("List available campaigns").option("-c, --chain-id <id>", "Chain ID (default: from config)", Number, getDefaultChainId()).option("-s, --status <status>", "Filter by status (active, completed, cancelled, to_cancel)", "active").option("-l, --limit <n>", "Max results", Number, 20).option("--json", "Output as JSON").action(async (opts) => {
|
|
9652
11100
|
const config = loadConfig();
|
|
9653
11101
|
try {
|
|
9654
11102
|
const launcherResult = await listLauncherCampaigns(getLauncherUrl(), opts.chainId, opts.limit, opts.status);
|
|
@@ -9677,11 +11125,13 @@ function createCampaignCommand() {
|
|
|
9677
11125
|
const joined = joinedKeys.has(key);
|
|
9678
11126
|
const tag = joined ? " [JOINED]" : "";
|
|
9679
11127
|
const decimals = c.fund_token_decimals ?? 0;
|
|
9680
|
-
const
|
|
9681
|
-
|
|
9682
|
-
|
|
9683
|
-
|
|
9684
|
-
const
|
|
11128
|
+
const fmt = (v) => {
|
|
11129
|
+
const bn = new bignumber_default(v).dividedBy(new bignumber_default(10).pow(decimals));
|
|
11130
|
+
return bn.toFormat();
|
|
11131
|
+
};
|
|
11132
|
+
const fundAmount = new bignumber_default(c.fund_amount);
|
|
11133
|
+
const balanceNum = new bignumber_default(c.balance);
|
|
11134
|
+
const pct = fundAmount.gt(0) ? balanceNum.dividedBy(fundAmount).times(100).toFixed(1) : "0.0";
|
|
9685
11135
|
printText(` ${c.exchange_name} ${c.symbol} (${c.type})${tag}`);
|
|
9686
11136
|
printText(` chain: ${c.chain_id}`);
|
|
9687
11137
|
printText(` address: ${c.address}`);
|
|
@@ -9711,9 +11161,11 @@ function createCampaignCommand() {
|
|
|
9711
11161
|
printText(` address: ${c.address}`);
|
|
9712
11162
|
printText(` chain: ${c.chain_id}`);
|
|
9713
11163
|
printText(` status: ${c.status}`);
|
|
9714
|
-
|
|
9715
|
-
|
|
9716
|
-
printText(`
|
|
11164
|
+
const showDecimals = c.fund_token_decimals ?? 0;
|
|
11165
|
+
const showFmt = (v) => new bignumber_default(v).dividedBy(new bignumber_default(10).pow(showDecimals)).toFormat();
|
|
11166
|
+
printText(` funded: ${showFmt(c.fund_amount)} ${c.fund_token_symbol}`);
|
|
11167
|
+
printText(` balance: ${showFmt(c.balance)} ${c.fund_token_symbol}`);
|
|
11168
|
+
printText(` paid: ${showFmt(c.amount_paid)} ${c.fund_token_symbol}`);
|
|
9717
11169
|
printText(` start: ${c.start_date}`);
|
|
9718
11170
|
printText(` end: ${c.end_date}`);
|
|
9719
11171
|
printText(` launcher: ${c.launcher}`);
|
|
@@ -9748,7 +11200,11 @@ function createCampaignCommand() {
|
|
|
9748
11200
|
process.exitCode = 1;
|
|
9749
11201
|
}
|
|
9750
11202
|
});
|
|
9751
|
-
campaign.command("status").description("Check campaign join status").
|
|
11203
|
+
const statusCmd = campaign.command("status").description("Check campaign join status").option("-c, --chain-id <id>", "Chain ID (default: from config)", Number, getDefaultChainId()).option("-a, --address <address>", "Campaign escrow address").option("--json", "Output as JSON").action(async (opts) => {
|
|
11204
|
+
if (!opts.address) {
|
|
11205
|
+
statusCmd.help();
|
|
11206
|
+
return;
|
|
11207
|
+
}
|
|
9752
11208
|
const { baseUrl, accessToken } = requireAuth2();
|
|
9753
11209
|
try {
|
|
9754
11210
|
const status = await checkJoinStatus(baseUrl, accessToken, opts.chainId, opts.address);
|
|
@@ -9767,7 +11223,11 @@ function createCampaignCommand() {
|
|
|
9767
11223
|
process.exitCode = 1;
|
|
9768
11224
|
}
|
|
9769
11225
|
});
|
|
9770
|
-
campaign.command("join").description("Join a campaign").
|
|
11226
|
+
const joinCmd = campaign.command("join").description("Join a campaign").option("-c, --chain-id <id>", "Chain ID (default: from config)", Number, getDefaultChainId()).option("-a, --address <address>", "Campaign escrow address").option("--json", "Output as JSON").action(async (opts) => {
|
|
11227
|
+
if (!opts.address) {
|
|
11228
|
+
joinCmd.help();
|
|
11229
|
+
return;
|
|
11230
|
+
}
|
|
9771
11231
|
const { baseUrl, accessToken } = requireAuth2();
|
|
9772
11232
|
try {
|
|
9773
11233
|
const joinStatus = await checkJoinStatus(baseUrl, accessToken, opts.chainId, opts.address);
|
|
@@ -9793,7 +11253,11 @@ function createCampaignCommand() {
|
|
|
9793
11253
|
process.exitCode = 1;
|
|
9794
11254
|
}
|
|
9795
11255
|
});
|
|
9796
|
-
campaign.command("progress").description("Check your progress in a campaign").option("-c, --chain-id <id>", "Chain ID", Number,
|
|
11256
|
+
const progressCmd = campaign.command("progress").description("Check your progress in a campaign").option("-c, --chain-id <id>", "Chain ID (default: from config)", Number, getDefaultChainId()).option("-a, --address <address>", "Campaign escrow address").option("--json", "Output as JSON").action(async (opts) => {
|
|
11257
|
+
if (!opts.address) {
|
|
11258
|
+
progressCmd.help();
|
|
11259
|
+
return;
|
|
11260
|
+
}
|
|
9797
11261
|
const { baseUrl, accessToken } = requireAuth2();
|
|
9798
11262
|
try {
|
|
9799
11263
|
const result = await getMyProgress(baseUrl, accessToken, opts.chainId, opts.address);
|
|
@@ -9815,7 +11279,11 @@ function createCampaignCommand() {
|
|
|
9815
11279
|
process.exitCode = 1;
|
|
9816
11280
|
}
|
|
9817
11281
|
});
|
|
9818
|
-
campaign.command("leaderboard").description("View campaign leaderboard").option("-c, --chain-id <id>", "Chain ID", Number,
|
|
11282
|
+
const leaderboardCmd = campaign.command("leaderboard").description("View campaign leaderboard").option("-c, --chain-id <id>", "Chain ID (default: from config)", Number, getDefaultChainId()).option("-a, --address <address>", "Campaign escrow address").option("-r, --rank-by <field>", "Rank by (rewards, current_progress)", "rewards").option("-l, --limit <n>", "Max results", Number, 20).option("--json", "Output as JSON").action(async (opts) => {
|
|
11283
|
+
if (!opts.address) {
|
|
11284
|
+
leaderboardCmd.help();
|
|
11285
|
+
return;
|
|
11286
|
+
}
|
|
9819
11287
|
try {
|
|
9820
11288
|
const baseUrl = loadConfig().recordingApiUrl.replace(/\/+$/, "");
|
|
9821
11289
|
const result = await getLeaderboard(baseUrl, opts.chainId, opts.address, opts.rankBy, opts.limit);
|
|
@@ -9844,7 +11312,7 @@ function createCampaignCommand() {
|
|
|
9844
11312
|
|
|
9845
11313
|
// src/cli.ts
|
|
9846
11314
|
var program2 = new Command;
|
|
9847
|
-
program2.name("hufi").description("CLI tool for hu.fi DeFi platform").version("0.5.
|
|
11315
|
+
program2.name("hufi").description("CLI tool for hu.fi DeFi platform").version("0.5.5").option("--config-file <path>", "Custom config file path (default: ~/.hufi-cli/config.json)").option("--key-file <path>", "Custom key file path (default: ~/.hufi-cli/key.json)").hook("preAction", (thisCommand) => {
|
|
9848
11316
|
const opts = thisCommand.opts();
|
|
9849
11317
|
if (opts.configFile) {
|
|
9850
11318
|
setConfigFile(opts.configFile);
|