@hyperline/cli 0.1.0-build.1.64d0170 → 0.1.0-build.1.673268c
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/bin/hyperline-main.js +2180 -2180
- package/package.json +1 -1
|
@@ -43224,7 +43224,7 @@ Examples:
|
|
|
43224
43224
|
// build/commands/generated/taxes.js
|
|
43225
43225
|
function registerTaxesCommands(parent) {
|
|
43226
43226
|
const resource = parent.command("taxes").description("Manage taxes");
|
|
43227
|
-
resource.command("list-tax-rates").description(`List custom tax
|
|
43227
|
+
resource.command("list-tax-rates").description(`List custom and default tax rate mappings with optional filters for id, name, description, and invoicing_entity_id. Paginated with take/skip.`).option("--take <number>", `take`).option("--skip <number>", `skip`).option("--id <value>", `id`).option("--id.not <value>", `id__not`).option("--id.is-null <value>", `id__isNull`).option("--id.is-not-null <value>", `id__isNotNull`).option("--id.equals <value>", `id__equals`).option("--id.contains <value>", `id__contains`).option("--id.starts-with <value>", `id__startsWith`).option("--id.end-with <value>", `id__endWith`).option("--name <value>", `name`).option("--name.not <value>", `name__not`).option("--name.is-null <value>", `name__isNull`).option("--name.is-not-null <value>", `name__isNotNull`).option("--name.equals <value>", `name__equals`).option("--name.contains <value>", `name__contains`).option("--name.starts-with <value>", `name__startsWith`).option("--name.end-with <value>", `name__endWith`).option("--description <value>", `description`).option("--description.not <value>", `description__not`).option("--description.is-null <value>", `description__isNull`).option("--description.is-not-null <value>", `description__isNotNull`).option("--description.equals <value>", `description__equals`).option("--description.contains <value>", `description__contains`).option("--description.starts-with <value>", `description__startsWith`).option("--description.end-with <value>", `description__endWith`).option("--invoicing-entity-id <value>", `invoicing_entity_id`).option("--invoicing-entity-id.not <value>", `invoicing_entity_id__not`).option("--invoicing-entity-id.is-null <value>", `invoicing_entity_id__isNull`).option("--invoicing-entity-id.is-not-null <value>", `invoicing_entity_id__isNotNull`).option("--invoicing-entity-id.equals <value>", `invoicing_entity_id__equals`).option("--invoicing-entity-id.contains <value>", `invoicing_entity_id__contains`).option("--invoicing-entity-id.starts-with <value>", `invoicing_entity_id__startsWith`).option("--invoicing-entity-id.end-with <value>", `invoicing_entity_id__endWith`).addHelpText("after", `
|
|
43228
43228
|
Examples:
|
|
43229
43229
|
hyperline taxes list-tax-rates
|
|
43230
43230
|
hyperline taxes list-tax-rates --take <take> --id <id>`).action(async (opts) => {
|
|
@@ -43344,7 +43344,7 @@ Examples:
|
|
|
43344
43344
|
]
|
|
43345
43345
|
});
|
|
43346
43346
|
});
|
|
43347
|
-
resource.command("get-tax-rate").description(`Retrieve
|
|
43347
|
+
resource.command("get-tax-rate").description(`Retrieve a custom or default tax rate mapping by ID.`).requiredOption("--id <value>", `id parameter`).addHelpText("after", `
|
|
43348
43348
|
Examples:
|
|
43349
43349
|
hyperline taxes get-tax-rate --id <id>`).action(async (opts) => {
|
|
43350
43350
|
const ctx = resource.parent?.opts()._ctx;
|
|
@@ -58019,2182 +58019,6 @@ import tracer from "dd-trace";
|
|
|
58019
58019
|
import { GetBucketLocationCommand, S3Client } from "@aws-sdk/client-s3";
|
|
58020
58020
|
import { GetCallerIdentityCommand, STSClient } from "@aws-sdk/client-sts";
|
|
58021
58021
|
|
|
58022
|
-
// ../../node_modules/decimal.js/decimal.mjs
|
|
58023
|
-
var EXP_LIMIT = 9e15;
|
|
58024
|
-
var MAX_DIGITS = 1e9;
|
|
58025
|
-
var NUMERALS = "0123456789abcdef";
|
|
58026
|
-
var LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";
|
|
58027
|
-
var PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789";
|
|
58028
|
-
var DEFAULTS = {
|
|
58029
|
-
// These values must be integers within the stated ranges (inclusive).
|
|
58030
|
-
// Most of these values can be changed at run-time using the `Decimal.config` method.
|
|
58031
|
-
// The maximum number of significant digits of the result of a calculation or base conversion.
|
|
58032
|
-
// E.g. `Decimal.config({ precision: 20 });`
|
|
58033
|
-
precision: 20,
|
|
58034
|
-
// 1 to MAX_DIGITS
|
|
58035
|
-
// The rounding mode used when rounding to `precision`.
|
|
58036
|
-
//
|
|
58037
|
-
// ROUND_UP 0 Away from zero.
|
|
58038
|
-
// ROUND_DOWN 1 Towards zero.
|
|
58039
|
-
// ROUND_CEIL 2 Towards +Infinity.
|
|
58040
|
-
// ROUND_FLOOR 3 Towards -Infinity.
|
|
58041
|
-
// ROUND_HALF_UP 4 Towards nearest neighbour. If equidistant, up.
|
|
58042
|
-
// ROUND_HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
|
|
58043
|
-
// ROUND_HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
|
|
58044
|
-
// ROUND_HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
|
|
58045
|
-
// ROUND_HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
|
|
58046
|
-
//
|
|
58047
|
-
// E.g.
|
|
58048
|
-
// `Decimal.rounding = 4;`
|
|
58049
|
-
// `Decimal.rounding = Decimal.ROUND_HALF_UP;`
|
|
58050
|
-
rounding: 4,
|
|
58051
|
-
// 0 to 8
|
|
58052
|
-
// The modulo mode used when calculating the modulus: a mod n.
|
|
58053
|
-
// The quotient (q = a / n) is calculated according to the corresponding rounding mode.
|
|
58054
|
-
// The remainder (r) is calculated as: r = a - n * q.
|
|
58055
|
-
//
|
|
58056
|
-
// UP 0 The remainder is positive if the dividend is negative, else is negative.
|
|
58057
|
-
// DOWN 1 The remainder has the same sign as the dividend (JavaScript %).
|
|
58058
|
-
// FLOOR 3 The remainder has the same sign as the divisor (Python %).
|
|
58059
|
-
// HALF_EVEN 6 The IEEE 754 remainder function.
|
|
58060
|
-
// EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)). Always positive.
|
|
58061
|
-
//
|
|
58062
|
-
// Truncated division (1), floored division (3), the IEEE 754 remainder (6), and Euclidian
|
|
58063
|
-
// division (9) are commonly used for the modulus operation. The other rounding modes can also
|
|
58064
|
-
// be used, but they may not give useful results.
|
|
58065
|
-
modulo: 1,
|
|
58066
|
-
// 0 to 9
|
|
58067
|
-
// The exponent value at and beneath which `toString` returns exponential notation.
|
|
58068
|
-
// JavaScript numbers: -7
|
|
58069
|
-
toExpNeg: -7,
|
|
58070
|
-
// 0 to -EXP_LIMIT
|
|
58071
|
-
// The exponent value at and above which `toString` returns exponential notation.
|
|
58072
|
-
// JavaScript numbers: 21
|
|
58073
|
-
toExpPos: 21,
|
|
58074
|
-
// 0 to EXP_LIMIT
|
|
58075
|
-
// The minimum exponent value, beneath which underflow to zero occurs.
|
|
58076
|
-
// JavaScript numbers: -324 (5e-324)
|
|
58077
|
-
minE: -EXP_LIMIT,
|
|
58078
|
-
// -1 to -EXP_LIMIT
|
|
58079
|
-
// The maximum exponent value, above which overflow to Infinity occurs.
|
|
58080
|
-
// JavaScript numbers: 308 (1.7976931348623157e+308)
|
|
58081
|
-
maxE: EXP_LIMIT,
|
|
58082
|
-
// 1 to EXP_LIMIT
|
|
58083
|
-
// Whether to use cryptographically-secure random number generation, if available.
|
|
58084
|
-
crypto: false
|
|
58085
|
-
// true/false
|
|
58086
|
-
};
|
|
58087
|
-
var inexact;
|
|
58088
|
-
var quadrant;
|
|
58089
|
-
var external = true;
|
|
58090
|
-
var decimalError = "[DecimalError] ";
|
|
58091
|
-
var invalidArgument = decimalError + "Invalid argument: ";
|
|
58092
|
-
var precisionLimitExceeded = decimalError + "Precision limit exceeded";
|
|
58093
|
-
var cryptoUnavailable = decimalError + "crypto unavailable";
|
|
58094
|
-
var tag = "[object Decimal]";
|
|
58095
|
-
var mathfloor = Math.floor;
|
|
58096
|
-
var mathpow = Math.pow;
|
|
58097
|
-
var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
|
|
58098
|
-
var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
|
|
58099
|
-
var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
|
|
58100
|
-
var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
|
|
58101
|
-
var BASE = 1e7;
|
|
58102
|
-
var LOG_BASE = 7;
|
|
58103
|
-
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
58104
|
-
var LN10_PRECISION = LN10.length - 1;
|
|
58105
|
-
var PI_PRECISION = PI.length - 1;
|
|
58106
|
-
var P = { toStringTag: tag };
|
|
58107
|
-
P.absoluteValue = P.abs = function() {
|
|
58108
|
-
var x = new this.constructor(this);
|
|
58109
|
-
if (x.s < 0) x.s = 1;
|
|
58110
|
-
return finalise(x);
|
|
58111
|
-
};
|
|
58112
|
-
P.ceil = function() {
|
|
58113
|
-
return finalise(new this.constructor(this), this.e + 1, 2);
|
|
58114
|
-
};
|
|
58115
|
-
P.clampedTo = P.clamp = function(min2, max2) {
|
|
58116
|
-
var k, x = this, Ctor = x.constructor;
|
|
58117
|
-
min2 = new Ctor(min2);
|
|
58118
|
-
max2 = new Ctor(max2);
|
|
58119
|
-
if (!min2.s || !max2.s) return new Ctor(NaN);
|
|
58120
|
-
if (min2.gt(max2)) throw Error(invalidArgument + max2);
|
|
58121
|
-
k = x.cmp(min2);
|
|
58122
|
-
return k < 0 ? min2 : x.cmp(max2) > 0 ? max2 : new Ctor(x);
|
|
58123
|
-
};
|
|
58124
|
-
P.comparedTo = P.cmp = function(y) {
|
|
58125
|
-
var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
|
|
58126
|
-
if (!xd || !yd) {
|
|
58127
|
-
return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
|
|
58128
|
-
}
|
|
58129
|
-
if (!xd[0] || !yd[0]) return xd[0] ? xs : yd[0] ? -ys : 0;
|
|
58130
|
-
if (xs !== ys) return xs;
|
|
58131
|
-
if (x.e !== y.e) return x.e > y.e ^ xs < 0 ? 1 : -1;
|
|
58132
|
-
xdL = xd.length;
|
|
58133
|
-
ydL = yd.length;
|
|
58134
|
-
for (i = 0, j = xdL < ydL ? xdL : ydL; i < j; ++i) {
|
|
58135
|
-
if (xd[i] !== yd[i]) return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
|
|
58136
|
-
}
|
|
58137
|
-
return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
|
|
58138
|
-
};
|
|
58139
|
-
P.cosine = P.cos = function() {
|
|
58140
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
58141
|
-
if (!x.d) return new Ctor(NaN);
|
|
58142
|
-
if (!x.d[0]) return new Ctor(1);
|
|
58143
|
-
pr = Ctor.precision;
|
|
58144
|
-
rm = Ctor.rounding;
|
|
58145
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
|
58146
|
-
Ctor.rounding = 1;
|
|
58147
|
-
x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
|
|
58148
|
-
Ctor.precision = pr;
|
|
58149
|
-
Ctor.rounding = rm;
|
|
58150
|
-
return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
|
|
58151
|
-
};
|
|
58152
|
-
P.cubeRoot = P.cbrt = function() {
|
|
58153
|
-
var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
|
|
58154
|
-
if (!x.isFinite() || x.isZero()) return new Ctor(x);
|
|
58155
|
-
external = false;
|
|
58156
|
-
s = x.s * mathpow(x.s * x, 1 / 3);
|
|
58157
|
-
if (!s || Math.abs(s) == 1 / 0) {
|
|
58158
|
-
n = digitsToString(x.d);
|
|
58159
|
-
e = x.e;
|
|
58160
|
-
if (s = (e - n.length + 1) % 3) n += s == 1 || s == -2 ? "0" : "00";
|
|
58161
|
-
s = mathpow(n, 1 / 3);
|
|
58162
|
-
e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
|
|
58163
|
-
if (s == 1 / 0) {
|
|
58164
|
-
n = "5e" + e;
|
|
58165
|
-
} else {
|
|
58166
|
-
n = s.toExponential();
|
|
58167
|
-
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
58168
|
-
}
|
|
58169
|
-
r = new Ctor(n);
|
|
58170
|
-
r.s = x.s;
|
|
58171
|
-
} else {
|
|
58172
|
-
r = new Ctor(s.toString());
|
|
58173
|
-
}
|
|
58174
|
-
sd = (e = Ctor.precision) + 3;
|
|
58175
|
-
for (; ; ) {
|
|
58176
|
-
t = r;
|
|
58177
|
-
t3 = t.times(t).times(t);
|
|
58178
|
-
t3plusx = t3.plus(x);
|
|
58179
|
-
r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
|
|
58180
|
-
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
58181
|
-
n = n.slice(sd - 3, sd + 1);
|
|
58182
|
-
if (n == "9999" || !rep && n == "4999") {
|
|
58183
|
-
if (!rep) {
|
|
58184
|
-
finalise(t, e + 1, 0);
|
|
58185
|
-
if (t.times(t).times(t).eq(x)) {
|
|
58186
|
-
r = t;
|
|
58187
|
-
break;
|
|
58188
|
-
}
|
|
58189
|
-
}
|
|
58190
|
-
sd += 4;
|
|
58191
|
-
rep = 1;
|
|
58192
|
-
} else {
|
|
58193
|
-
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
58194
|
-
finalise(r, e + 1, 1);
|
|
58195
|
-
m = !r.times(r).times(r).eq(x);
|
|
58196
|
-
}
|
|
58197
|
-
break;
|
|
58198
|
-
}
|
|
58199
|
-
}
|
|
58200
|
-
}
|
|
58201
|
-
external = true;
|
|
58202
|
-
return finalise(r, e, Ctor.rounding, m);
|
|
58203
|
-
};
|
|
58204
|
-
P.decimalPlaces = P.dp = function() {
|
|
58205
|
-
var w, d = this.d, n = NaN;
|
|
58206
|
-
if (d) {
|
|
58207
|
-
w = d.length - 1;
|
|
58208
|
-
n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
58209
|
-
w = d[w];
|
|
58210
|
-
if (w) for (; w % 10 == 0; w /= 10) n--;
|
|
58211
|
-
if (n < 0) n = 0;
|
|
58212
|
-
}
|
|
58213
|
-
return n;
|
|
58214
|
-
};
|
|
58215
|
-
P.dividedBy = P.div = function(y) {
|
|
58216
|
-
return divide(this, new this.constructor(y));
|
|
58217
|
-
};
|
|
58218
|
-
P.dividedToIntegerBy = P.divToInt = function(y) {
|
|
58219
|
-
var x = this, Ctor = x.constructor;
|
|
58220
|
-
return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
|
|
58221
|
-
};
|
|
58222
|
-
P.equals = P.eq = function(y) {
|
|
58223
|
-
return this.cmp(y) === 0;
|
|
58224
|
-
};
|
|
58225
|
-
P.floor = function() {
|
|
58226
|
-
return finalise(new this.constructor(this), this.e + 1, 3);
|
|
58227
|
-
};
|
|
58228
|
-
P.greaterThan = P.gt = function(y) {
|
|
58229
|
-
return this.cmp(y) > 0;
|
|
58230
|
-
};
|
|
58231
|
-
P.greaterThanOrEqualTo = P.gte = function(y) {
|
|
58232
|
-
var k = this.cmp(y);
|
|
58233
|
-
return k == 1 || k === 0;
|
|
58234
|
-
};
|
|
58235
|
-
P.hyperbolicCosine = P.cosh = function() {
|
|
58236
|
-
var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
|
|
58237
|
-
if (!x.isFinite()) return new Ctor(x.s ? 1 / 0 : NaN);
|
|
58238
|
-
if (x.isZero()) return one;
|
|
58239
|
-
pr = Ctor.precision;
|
|
58240
|
-
rm = Ctor.rounding;
|
|
58241
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
|
58242
|
-
Ctor.rounding = 1;
|
|
58243
|
-
len = x.d.length;
|
|
58244
|
-
if (len < 32) {
|
|
58245
|
-
k = Math.ceil(len / 3);
|
|
58246
|
-
n = (1 / tinyPow(4, k)).toString();
|
|
58247
|
-
} else {
|
|
58248
|
-
k = 16;
|
|
58249
|
-
n = "2.3283064365386962890625e-10";
|
|
58250
|
-
}
|
|
58251
|
-
x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
|
|
58252
|
-
var cosh2_x, i = k, d8 = new Ctor(8);
|
|
58253
|
-
for (; i--; ) {
|
|
58254
|
-
cosh2_x = x.times(x);
|
|
58255
|
-
x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
|
|
58256
|
-
}
|
|
58257
|
-
return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
|
|
58258
|
-
};
|
|
58259
|
-
P.hyperbolicSine = P.sinh = function() {
|
|
58260
|
-
var k, pr, rm, len, x = this, Ctor = x.constructor;
|
|
58261
|
-
if (!x.isFinite() || x.isZero()) return new Ctor(x);
|
|
58262
|
-
pr = Ctor.precision;
|
|
58263
|
-
rm = Ctor.rounding;
|
|
58264
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
|
58265
|
-
Ctor.rounding = 1;
|
|
58266
|
-
len = x.d.length;
|
|
58267
|
-
if (len < 3) {
|
|
58268
|
-
x = taylorSeries(Ctor, 2, x, x, true);
|
|
58269
|
-
} else {
|
|
58270
|
-
k = 1.4 * Math.sqrt(len);
|
|
58271
|
-
k = k > 16 ? 16 : k | 0;
|
|
58272
|
-
x = x.times(1 / tinyPow(5, k));
|
|
58273
|
-
x = taylorSeries(Ctor, 2, x, x, true);
|
|
58274
|
-
var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
58275
|
-
for (; k--; ) {
|
|
58276
|
-
sinh2_x = x.times(x);
|
|
58277
|
-
x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
|
|
58278
|
-
}
|
|
58279
|
-
}
|
|
58280
|
-
Ctor.precision = pr;
|
|
58281
|
-
Ctor.rounding = rm;
|
|
58282
|
-
return finalise(x, pr, rm, true);
|
|
58283
|
-
};
|
|
58284
|
-
P.hyperbolicTangent = P.tanh = function() {
|
|
58285
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
58286
|
-
if (!x.isFinite()) return new Ctor(x.s);
|
|
58287
|
-
if (x.isZero()) return new Ctor(x);
|
|
58288
|
-
pr = Ctor.precision;
|
|
58289
|
-
rm = Ctor.rounding;
|
|
58290
|
-
Ctor.precision = pr + 7;
|
|
58291
|
-
Ctor.rounding = 1;
|
|
58292
|
-
return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
|
|
58293
|
-
};
|
|
58294
|
-
P.inverseCosine = P.acos = function() {
|
|
58295
|
-
var x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
|
|
58296
|
-
if (k !== -1) {
|
|
58297
|
-
return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
|
|
58298
|
-
}
|
|
58299
|
-
if (x.isZero()) return getPi(Ctor, pr + 4, rm).times(0.5);
|
|
58300
|
-
Ctor.precision = pr + 6;
|
|
58301
|
-
Ctor.rounding = 1;
|
|
58302
|
-
x = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
|
|
58303
|
-
Ctor.precision = pr;
|
|
58304
|
-
Ctor.rounding = rm;
|
|
58305
|
-
return x.times(2);
|
|
58306
|
-
};
|
|
58307
|
-
P.inverseHyperbolicCosine = P.acosh = function() {
|
|
58308
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
58309
|
-
if (x.lte(1)) return new Ctor(x.eq(1) ? 0 : NaN);
|
|
58310
|
-
if (!x.isFinite()) return new Ctor(x);
|
|
58311
|
-
pr = Ctor.precision;
|
|
58312
|
-
rm = Ctor.rounding;
|
|
58313
|
-
Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
|
|
58314
|
-
Ctor.rounding = 1;
|
|
58315
|
-
external = false;
|
|
58316
|
-
x = x.times(x).minus(1).sqrt().plus(x);
|
|
58317
|
-
external = true;
|
|
58318
|
-
Ctor.precision = pr;
|
|
58319
|
-
Ctor.rounding = rm;
|
|
58320
|
-
return x.ln();
|
|
58321
|
-
};
|
|
58322
|
-
P.inverseHyperbolicSine = P.asinh = function() {
|
|
58323
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
58324
|
-
if (!x.isFinite() || x.isZero()) return new Ctor(x);
|
|
58325
|
-
pr = Ctor.precision;
|
|
58326
|
-
rm = Ctor.rounding;
|
|
58327
|
-
Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
|
|
58328
|
-
Ctor.rounding = 1;
|
|
58329
|
-
external = false;
|
|
58330
|
-
x = x.times(x).plus(1).sqrt().plus(x);
|
|
58331
|
-
external = true;
|
|
58332
|
-
Ctor.precision = pr;
|
|
58333
|
-
Ctor.rounding = rm;
|
|
58334
|
-
return x.ln();
|
|
58335
|
-
};
|
|
58336
|
-
P.inverseHyperbolicTangent = P.atanh = function() {
|
|
58337
|
-
var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
|
|
58338
|
-
if (!x.isFinite()) return new Ctor(NaN);
|
|
58339
|
-
if (x.e >= 0) return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
|
|
58340
|
-
pr = Ctor.precision;
|
|
58341
|
-
rm = Ctor.rounding;
|
|
58342
|
-
xsd = x.sd();
|
|
58343
|
-
if (Math.max(xsd, pr) < 2 * -x.e - 1) return finalise(new Ctor(x), pr, rm, true);
|
|
58344
|
-
Ctor.precision = wpr = xsd - x.e;
|
|
58345
|
-
x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
|
|
58346
|
-
Ctor.precision = pr + 4;
|
|
58347
|
-
Ctor.rounding = 1;
|
|
58348
|
-
x = x.ln();
|
|
58349
|
-
Ctor.precision = pr;
|
|
58350
|
-
Ctor.rounding = rm;
|
|
58351
|
-
return x.times(0.5);
|
|
58352
|
-
};
|
|
58353
|
-
P.inverseSine = P.asin = function() {
|
|
58354
|
-
var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
|
|
58355
|
-
if (x.isZero()) return new Ctor(x);
|
|
58356
|
-
k = x.abs().cmp(1);
|
|
58357
|
-
pr = Ctor.precision;
|
|
58358
|
-
rm = Ctor.rounding;
|
|
58359
|
-
if (k !== -1) {
|
|
58360
|
-
if (k === 0) {
|
|
58361
|
-
halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
58362
|
-
halfPi.s = x.s;
|
|
58363
|
-
return halfPi;
|
|
58364
|
-
}
|
|
58365
|
-
return new Ctor(NaN);
|
|
58366
|
-
}
|
|
58367
|
-
Ctor.precision = pr + 6;
|
|
58368
|
-
Ctor.rounding = 1;
|
|
58369
|
-
x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
|
|
58370
|
-
Ctor.precision = pr;
|
|
58371
|
-
Ctor.rounding = rm;
|
|
58372
|
-
return x.times(2);
|
|
58373
|
-
};
|
|
58374
|
-
P.inverseTangent = P.atan = function() {
|
|
58375
|
-
var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
|
|
58376
|
-
if (!x.isFinite()) {
|
|
58377
|
-
if (!x.s) return new Ctor(NaN);
|
|
58378
|
-
if (pr + 4 <= PI_PRECISION) {
|
|
58379
|
-
r = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
58380
|
-
r.s = x.s;
|
|
58381
|
-
return r;
|
|
58382
|
-
}
|
|
58383
|
-
} else if (x.isZero()) {
|
|
58384
|
-
return new Ctor(x);
|
|
58385
|
-
} else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
|
|
58386
|
-
r = getPi(Ctor, pr + 4, rm).times(0.25);
|
|
58387
|
-
r.s = x.s;
|
|
58388
|
-
return r;
|
|
58389
|
-
}
|
|
58390
|
-
Ctor.precision = wpr = pr + 10;
|
|
58391
|
-
Ctor.rounding = 1;
|
|
58392
|
-
k = Math.min(28, wpr / LOG_BASE + 2 | 0);
|
|
58393
|
-
for (i = k; i; --i) x = x.div(x.times(x).plus(1).sqrt().plus(1));
|
|
58394
|
-
external = false;
|
|
58395
|
-
j = Math.ceil(wpr / LOG_BASE);
|
|
58396
|
-
n = 1;
|
|
58397
|
-
x2 = x.times(x);
|
|
58398
|
-
r = new Ctor(x);
|
|
58399
|
-
px = x;
|
|
58400
|
-
for (; i !== -1; ) {
|
|
58401
|
-
px = px.times(x2);
|
|
58402
|
-
t = r.minus(px.div(n += 2));
|
|
58403
|
-
px = px.times(x2);
|
|
58404
|
-
r = t.plus(px.div(n += 2));
|
|
58405
|
-
if (r.d[j] !== void 0) for (i = j; r.d[i] === t.d[i] && i--; ) ;
|
|
58406
|
-
}
|
|
58407
|
-
if (k) r = r.times(2 << k - 1);
|
|
58408
|
-
external = true;
|
|
58409
|
-
return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
|
|
58410
|
-
};
|
|
58411
|
-
P.isFinite = function() {
|
|
58412
|
-
return !!this.d;
|
|
58413
|
-
};
|
|
58414
|
-
P.isInteger = P.isInt = function() {
|
|
58415
|
-
return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
|
|
58416
|
-
};
|
|
58417
|
-
P.isNaN = function() {
|
|
58418
|
-
return !this.s;
|
|
58419
|
-
};
|
|
58420
|
-
P.isNegative = P.isNeg = function() {
|
|
58421
|
-
return this.s < 0;
|
|
58422
|
-
};
|
|
58423
|
-
P.isPositive = P.isPos = function() {
|
|
58424
|
-
return this.s > 0;
|
|
58425
|
-
};
|
|
58426
|
-
P.isZero = function() {
|
|
58427
|
-
return !!this.d && this.d[0] === 0;
|
|
58428
|
-
};
|
|
58429
|
-
P.lessThan = P.lt = function(y) {
|
|
58430
|
-
return this.cmp(y) < 0;
|
|
58431
|
-
};
|
|
58432
|
-
P.lessThanOrEqualTo = P.lte = function(y) {
|
|
58433
|
-
return this.cmp(y) < 1;
|
|
58434
|
-
};
|
|
58435
|
-
P.logarithm = P.log = function(base) {
|
|
58436
|
-
var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
|
|
58437
|
-
if (base == null) {
|
|
58438
|
-
base = new Ctor(10);
|
|
58439
|
-
isBase10 = true;
|
|
58440
|
-
} else {
|
|
58441
|
-
base = new Ctor(base);
|
|
58442
|
-
d = base.d;
|
|
58443
|
-
if (base.s < 0 || !d || !d[0] || base.eq(1)) return new Ctor(NaN);
|
|
58444
|
-
isBase10 = base.eq(10);
|
|
58445
|
-
}
|
|
58446
|
-
d = arg.d;
|
|
58447
|
-
if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
|
|
58448
|
-
return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
|
|
58449
|
-
}
|
|
58450
|
-
if (isBase10) {
|
|
58451
|
-
if (d.length > 1) {
|
|
58452
|
-
inf = true;
|
|
58453
|
-
} else {
|
|
58454
|
-
for (k = d[0]; k % 10 === 0; ) k /= 10;
|
|
58455
|
-
inf = k !== 1;
|
|
58456
|
-
}
|
|
58457
|
-
}
|
|
58458
|
-
external = false;
|
|
58459
|
-
sd = pr + guard;
|
|
58460
|
-
num = naturalLogarithm(arg, sd);
|
|
58461
|
-
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
58462
|
-
r = divide(num, denominator, sd, 1);
|
|
58463
|
-
if (checkRoundingDigits(r.d, k = pr, rm)) {
|
|
58464
|
-
do {
|
|
58465
|
-
sd += 10;
|
|
58466
|
-
num = naturalLogarithm(arg, sd);
|
|
58467
|
-
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
58468
|
-
r = divide(num, denominator, sd, 1);
|
|
58469
|
-
if (!inf) {
|
|
58470
|
-
if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 1e14) {
|
|
58471
|
-
r = finalise(r, pr + 1, 0);
|
|
58472
|
-
}
|
|
58473
|
-
break;
|
|
58474
|
-
}
|
|
58475
|
-
} while (checkRoundingDigits(r.d, k += 10, rm));
|
|
58476
|
-
}
|
|
58477
|
-
external = true;
|
|
58478
|
-
return finalise(r, pr, rm);
|
|
58479
|
-
};
|
|
58480
|
-
P.minus = P.sub = function(y) {
|
|
58481
|
-
var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
|
|
58482
|
-
y = new Ctor(y);
|
|
58483
|
-
if (!x.d || !y.d) {
|
|
58484
|
-
if (!x.s || !y.s) y = new Ctor(NaN);
|
|
58485
|
-
else if (x.d) y.s = -y.s;
|
|
58486
|
-
else y = new Ctor(y.d || x.s !== y.s ? x : NaN);
|
|
58487
|
-
return y;
|
|
58488
|
-
}
|
|
58489
|
-
if (x.s != y.s) {
|
|
58490
|
-
y.s = -y.s;
|
|
58491
|
-
return x.plus(y);
|
|
58492
|
-
}
|
|
58493
|
-
xd = x.d;
|
|
58494
|
-
yd = y.d;
|
|
58495
|
-
pr = Ctor.precision;
|
|
58496
|
-
rm = Ctor.rounding;
|
|
58497
|
-
if (!xd[0] || !yd[0]) {
|
|
58498
|
-
if (yd[0]) y.s = -y.s;
|
|
58499
|
-
else if (xd[0]) y = new Ctor(x);
|
|
58500
|
-
else return new Ctor(rm === 3 ? -0 : 0);
|
|
58501
|
-
return external ? finalise(y, pr, rm) : y;
|
|
58502
|
-
}
|
|
58503
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
58504
|
-
xe = mathfloor(x.e / LOG_BASE);
|
|
58505
|
-
xd = xd.slice();
|
|
58506
|
-
k = xe - e;
|
|
58507
|
-
if (k) {
|
|
58508
|
-
xLTy = k < 0;
|
|
58509
|
-
if (xLTy) {
|
|
58510
|
-
d = xd;
|
|
58511
|
-
k = -k;
|
|
58512
|
-
len = yd.length;
|
|
58513
|
-
} else {
|
|
58514
|
-
d = yd;
|
|
58515
|
-
e = xe;
|
|
58516
|
-
len = xd.length;
|
|
58517
|
-
}
|
|
58518
|
-
i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
|
|
58519
|
-
if (k > i) {
|
|
58520
|
-
k = i;
|
|
58521
|
-
d.length = 1;
|
|
58522
|
-
}
|
|
58523
|
-
d.reverse();
|
|
58524
|
-
for (i = k; i--; ) d.push(0);
|
|
58525
|
-
d.reverse();
|
|
58526
|
-
} else {
|
|
58527
|
-
i = xd.length;
|
|
58528
|
-
len = yd.length;
|
|
58529
|
-
xLTy = i < len;
|
|
58530
|
-
if (xLTy) len = i;
|
|
58531
|
-
for (i = 0; i < len; i++) {
|
|
58532
|
-
if (xd[i] != yd[i]) {
|
|
58533
|
-
xLTy = xd[i] < yd[i];
|
|
58534
|
-
break;
|
|
58535
|
-
}
|
|
58536
|
-
}
|
|
58537
|
-
k = 0;
|
|
58538
|
-
}
|
|
58539
|
-
if (xLTy) {
|
|
58540
|
-
d = xd;
|
|
58541
|
-
xd = yd;
|
|
58542
|
-
yd = d;
|
|
58543
|
-
y.s = -y.s;
|
|
58544
|
-
}
|
|
58545
|
-
len = xd.length;
|
|
58546
|
-
for (i = yd.length - len; i > 0; --i) xd[len++] = 0;
|
|
58547
|
-
for (i = yd.length; i > k; ) {
|
|
58548
|
-
if (xd[--i] < yd[i]) {
|
|
58549
|
-
for (j = i; j && xd[--j] === 0; ) xd[j] = BASE - 1;
|
|
58550
|
-
--xd[j];
|
|
58551
|
-
xd[i] += BASE;
|
|
58552
|
-
}
|
|
58553
|
-
xd[i] -= yd[i];
|
|
58554
|
-
}
|
|
58555
|
-
for (; xd[--len] === 0; ) xd.pop();
|
|
58556
|
-
for (; xd[0] === 0; xd.shift()) --e;
|
|
58557
|
-
if (!xd[0]) return new Ctor(rm === 3 ? -0 : 0);
|
|
58558
|
-
y.d = xd;
|
|
58559
|
-
y.e = getBase10Exponent(xd, e);
|
|
58560
|
-
return external ? finalise(y, pr, rm) : y;
|
|
58561
|
-
};
|
|
58562
|
-
P.modulo = P.mod = function(y) {
|
|
58563
|
-
var q, x = this, Ctor = x.constructor;
|
|
58564
|
-
y = new Ctor(y);
|
|
58565
|
-
if (!x.d || !y.s || y.d && !y.d[0]) return new Ctor(NaN);
|
|
58566
|
-
if (!y.d || x.d && !x.d[0]) {
|
|
58567
|
-
return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
|
|
58568
|
-
}
|
|
58569
|
-
external = false;
|
|
58570
|
-
if (Ctor.modulo == 9) {
|
|
58571
|
-
q = divide(x, y.abs(), 0, 3, 1);
|
|
58572
|
-
q.s *= y.s;
|
|
58573
|
-
} else {
|
|
58574
|
-
q = divide(x, y, 0, Ctor.modulo, 1);
|
|
58575
|
-
}
|
|
58576
|
-
q = q.times(y);
|
|
58577
|
-
external = true;
|
|
58578
|
-
return x.minus(q);
|
|
58579
|
-
};
|
|
58580
|
-
P.naturalExponential = P.exp = function() {
|
|
58581
|
-
return naturalExponential(this);
|
|
58582
|
-
};
|
|
58583
|
-
P.naturalLogarithm = P.ln = function() {
|
|
58584
|
-
return naturalLogarithm(this);
|
|
58585
|
-
};
|
|
58586
|
-
P.negated = P.neg = function() {
|
|
58587
|
-
var x = new this.constructor(this);
|
|
58588
|
-
x.s = -x.s;
|
|
58589
|
-
return finalise(x);
|
|
58590
|
-
};
|
|
58591
|
-
P.plus = P.add = function(y) {
|
|
58592
|
-
var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
|
|
58593
|
-
y = new Ctor(y);
|
|
58594
|
-
if (!x.d || !y.d) {
|
|
58595
|
-
if (!x.s || !y.s) y = new Ctor(NaN);
|
|
58596
|
-
else if (!x.d) y = new Ctor(y.d || x.s === y.s ? x : NaN);
|
|
58597
|
-
return y;
|
|
58598
|
-
}
|
|
58599
|
-
if (x.s != y.s) {
|
|
58600
|
-
y.s = -y.s;
|
|
58601
|
-
return x.minus(y);
|
|
58602
|
-
}
|
|
58603
|
-
xd = x.d;
|
|
58604
|
-
yd = y.d;
|
|
58605
|
-
pr = Ctor.precision;
|
|
58606
|
-
rm = Ctor.rounding;
|
|
58607
|
-
if (!xd[0] || !yd[0]) {
|
|
58608
|
-
if (!yd[0]) y = new Ctor(x);
|
|
58609
|
-
return external ? finalise(y, pr, rm) : y;
|
|
58610
|
-
}
|
|
58611
|
-
k = mathfloor(x.e / LOG_BASE);
|
|
58612
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
58613
|
-
xd = xd.slice();
|
|
58614
|
-
i = k - e;
|
|
58615
|
-
if (i) {
|
|
58616
|
-
if (i < 0) {
|
|
58617
|
-
d = xd;
|
|
58618
|
-
i = -i;
|
|
58619
|
-
len = yd.length;
|
|
58620
|
-
} else {
|
|
58621
|
-
d = yd;
|
|
58622
|
-
e = k;
|
|
58623
|
-
len = xd.length;
|
|
58624
|
-
}
|
|
58625
|
-
k = Math.ceil(pr / LOG_BASE);
|
|
58626
|
-
len = k > len ? k + 1 : len + 1;
|
|
58627
|
-
if (i > len) {
|
|
58628
|
-
i = len;
|
|
58629
|
-
d.length = 1;
|
|
58630
|
-
}
|
|
58631
|
-
d.reverse();
|
|
58632
|
-
for (; i--; ) d.push(0);
|
|
58633
|
-
d.reverse();
|
|
58634
|
-
}
|
|
58635
|
-
len = xd.length;
|
|
58636
|
-
i = yd.length;
|
|
58637
|
-
if (len - i < 0) {
|
|
58638
|
-
i = len;
|
|
58639
|
-
d = yd;
|
|
58640
|
-
yd = xd;
|
|
58641
|
-
xd = d;
|
|
58642
|
-
}
|
|
58643
|
-
for (carry = 0; i; ) {
|
|
58644
|
-
carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
|
|
58645
|
-
xd[i] %= BASE;
|
|
58646
|
-
}
|
|
58647
|
-
if (carry) {
|
|
58648
|
-
xd.unshift(carry);
|
|
58649
|
-
++e;
|
|
58650
|
-
}
|
|
58651
|
-
for (len = xd.length; xd[--len] == 0; ) xd.pop();
|
|
58652
|
-
y.d = xd;
|
|
58653
|
-
y.e = getBase10Exponent(xd, e);
|
|
58654
|
-
return external ? finalise(y, pr, rm) : y;
|
|
58655
|
-
};
|
|
58656
|
-
P.precision = P.sd = function(z2) {
|
|
58657
|
-
var k, x = this;
|
|
58658
|
-
if (z2 !== void 0 && z2 !== !!z2 && z2 !== 1 && z2 !== 0) throw Error(invalidArgument + z2);
|
|
58659
|
-
if (x.d) {
|
|
58660
|
-
k = getPrecision(x.d);
|
|
58661
|
-
if (z2 && x.e + 1 > k) k = x.e + 1;
|
|
58662
|
-
} else {
|
|
58663
|
-
k = NaN;
|
|
58664
|
-
}
|
|
58665
|
-
return k;
|
|
58666
|
-
};
|
|
58667
|
-
P.round = function() {
|
|
58668
|
-
var x = this, Ctor = x.constructor;
|
|
58669
|
-
return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
|
|
58670
|
-
};
|
|
58671
|
-
P.sine = P.sin = function() {
|
|
58672
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
58673
|
-
if (!x.isFinite()) return new Ctor(NaN);
|
|
58674
|
-
if (x.isZero()) return new Ctor(x);
|
|
58675
|
-
pr = Ctor.precision;
|
|
58676
|
-
rm = Ctor.rounding;
|
|
58677
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
|
58678
|
-
Ctor.rounding = 1;
|
|
58679
|
-
x = sine(Ctor, toLessThanHalfPi(Ctor, x));
|
|
58680
|
-
Ctor.precision = pr;
|
|
58681
|
-
Ctor.rounding = rm;
|
|
58682
|
-
return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
|
|
58683
|
-
};
|
|
58684
|
-
P.squareRoot = P.sqrt = function() {
|
|
58685
|
-
var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
|
|
58686
|
-
if (s !== 1 || !d || !d[0]) {
|
|
58687
|
-
return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
|
|
58688
|
-
}
|
|
58689
|
-
external = false;
|
|
58690
|
-
s = Math.sqrt(+x);
|
|
58691
|
-
if (s == 0 || s == 1 / 0) {
|
|
58692
|
-
n = digitsToString(d);
|
|
58693
|
-
if ((n.length + e) % 2 == 0) n += "0";
|
|
58694
|
-
s = Math.sqrt(n);
|
|
58695
|
-
e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
58696
|
-
if (s == 1 / 0) {
|
|
58697
|
-
n = "5e" + e;
|
|
58698
|
-
} else {
|
|
58699
|
-
n = s.toExponential();
|
|
58700
|
-
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
58701
|
-
}
|
|
58702
|
-
r = new Ctor(n);
|
|
58703
|
-
} else {
|
|
58704
|
-
r = new Ctor(s.toString());
|
|
58705
|
-
}
|
|
58706
|
-
sd = (e = Ctor.precision) + 3;
|
|
58707
|
-
for (; ; ) {
|
|
58708
|
-
t = r;
|
|
58709
|
-
r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
|
|
58710
|
-
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
58711
|
-
n = n.slice(sd - 3, sd + 1);
|
|
58712
|
-
if (n == "9999" || !rep && n == "4999") {
|
|
58713
|
-
if (!rep) {
|
|
58714
|
-
finalise(t, e + 1, 0);
|
|
58715
|
-
if (t.times(t).eq(x)) {
|
|
58716
|
-
r = t;
|
|
58717
|
-
break;
|
|
58718
|
-
}
|
|
58719
|
-
}
|
|
58720
|
-
sd += 4;
|
|
58721
|
-
rep = 1;
|
|
58722
|
-
} else {
|
|
58723
|
-
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
58724
|
-
finalise(r, e + 1, 1);
|
|
58725
|
-
m = !r.times(r).eq(x);
|
|
58726
|
-
}
|
|
58727
|
-
break;
|
|
58728
|
-
}
|
|
58729
|
-
}
|
|
58730
|
-
}
|
|
58731
|
-
external = true;
|
|
58732
|
-
return finalise(r, e, Ctor.rounding, m);
|
|
58733
|
-
};
|
|
58734
|
-
P.tangent = P.tan = function() {
|
|
58735
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
58736
|
-
if (!x.isFinite()) return new Ctor(NaN);
|
|
58737
|
-
if (x.isZero()) return new Ctor(x);
|
|
58738
|
-
pr = Ctor.precision;
|
|
58739
|
-
rm = Ctor.rounding;
|
|
58740
|
-
Ctor.precision = pr + 10;
|
|
58741
|
-
Ctor.rounding = 1;
|
|
58742
|
-
x = x.sin();
|
|
58743
|
-
x.s = 1;
|
|
58744
|
-
x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
|
|
58745
|
-
Ctor.precision = pr;
|
|
58746
|
-
Ctor.rounding = rm;
|
|
58747
|
-
return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
|
|
58748
|
-
};
|
|
58749
|
-
P.times = P.mul = function(y) {
|
|
58750
|
-
var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
|
|
58751
|
-
y.s *= x.s;
|
|
58752
|
-
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
58753
|
-
return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
|
|
58754
|
-
}
|
|
58755
|
-
e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
|
|
58756
|
-
xdL = xd.length;
|
|
58757
|
-
ydL = yd.length;
|
|
58758
|
-
if (xdL < ydL) {
|
|
58759
|
-
r = xd;
|
|
58760
|
-
xd = yd;
|
|
58761
|
-
yd = r;
|
|
58762
|
-
rL = xdL;
|
|
58763
|
-
xdL = ydL;
|
|
58764
|
-
ydL = rL;
|
|
58765
|
-
}
|
|
58766
|
-
r = [];
|
|
58767
|
-
rL = xdL + ydL;
|
|
58768
|
-
for (i = rL; i--; ) r.push(0);
|
|
58769
|
-
for (i = ydL; --i >= 0; ) {
|
|
58770
|
-
carry = 0;
|
|
58771
|
-
for (k = xdL + i; k > i; ) {
|
|
58772
|
-
t = r[k] + yd[i] * xd[k - i - 1] + carry;
|
|
58773
|
-
r[k--] = t % BASE | 0;
|
|
58774
|
-
carry = t / BASE | 0;
|
|
58775
|
-
}
|
|
58776
|
-
r[k] = (r[k] + carry) % BASE | 0;
|
|
58777
|
-
}
|
|
58778
|
-
for (; !r[--rL]; ) r.pop();
|
|
58779
|
-
if (carry) ++e;
|
|
58780
|
-
else r.shift();
|
|
58781
|
-
y.d = r;
|
|
58782
|
-
y.e = getBase10Exponent(r, e);
|
|
58783
|
-
return external ? finalise(y, Ctor.precision, Ctor.rounding) : y;
|
|
58784
|
-
};
|
|
58785
|
-
P.toBinary = function(sd, rm) {
|
|
58786
|
-
return toStringBinary(this, 2, sd, rm);
|
|
58787
|
-
};
|
|
58788
|
-
P.toDecimalPlaces = P.toDP = function(dp, rm) {
|
|
58789
|
-
var x = this, Ctor = x.constructor;
|
|
58790
|
-
x = new Ctor(x);
|
|
58791
|
-
if (dp === void 0) return x;
|
|
58792
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
58793
|
-
if (rm === void 0) rm = Ctor.rounding;
|
|
58794
|
-
else checkInt32(rm, 0, 8);
|
|
58795
|
-
return finalise(x, dp + x.e + 1, rm);
|
|
58796
|
-
};
|
|
58797
|
-
P.toExponential = function(dp, rm) {
|
|
58798
|
-
var str, x = this, Ctor = x.constructor;
|
|
58799
|
-
if (dp === void 0) {
|
|
58800
|
-
str = finiteToString(x, true);
|
|
58801
|
-
} else {
|
|
58802
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
58803
|
-
if (rm === void 0) rm = Ctor.rounding;
|
|
58804
|
-
else checkInt32(rm, 0, 8);
|
|
58805
|
-
x = finalise(new Ctor(x), dp + 1, rm);
|
|
58806
|
-
str = finiteToString(x, true, dp + 1);
|
|
58807
|
-
}
|
|
58808
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
58809
|
-
};
|
|
58810
|
-
P.toFixed = function(dp, rm) {
|
|
58811
|
-
var str, y, x = this, Ctor = x.constructor;
|
|
58812
|
-
if (dp === void 0) {
|
|
58813
|
-
str = finiteToString(x);
|
|
58814
|
-
} else {
|
|
58815
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
58816
|
-
if (rm === void 0) rm = Ctor.rounding;
|
|
58817
|
-
else checkInt32(rm, 0, 8);
|
|
58818
|
-
y = finalise(new Ctor(x), dp + x.e + 1, rm);
|
|
58819
|
-
str = finiteToString(y, false, dp + y.e + 1);
|
|
58820
|
-
}
|
|
58821
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
58822
|
-
};
|
|
58823
|
-
P.toFraction = function(maxD) {
|
|
58824
|
-
var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
|
|
58825
|
-
if (!xd) return new Ctor(x);
|
|
58826
|
-
n1 = d0 = new Ctor(1);
|
|
58827
|
-
d1 = n0 = new Ctor(0);
|
|
58828
|
-
d = new Ctor(d1);
|
|
58829
|
-
e = d.e = getPrecision(xd) - x.e - 1;
|
|
58830
|
-
k = e % LOG_BASE;
|
|
58831
|
-
d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
|
|
58832
|
-
if (maxD == null) {
|
|
58833
|
-
maxD = e > 0 ? d : n1;
|
|
58834
|
-
} else {
|
|
58835
|
-
n = new Ctor(maxD);
|
|
58836
|
-
if (!n.isInt() || n.lt(n1)) throw Error(invalidArgument + n);
|
|
58837
|
-
maxD = n.gt(d) ? e > 0 ? d : n1 : n;
|
|
58838
|
-
}
|
|
58839
|
-
external = false;
|
|
58840
|
-
n = new Ctor(digitsToString(xd));
|
|
58841
|
-
pr = Ctor.precision;
|
|
58842
|
-
Ctor.precision = e = xd.length * LOG_BASE * 2;
|
|
58843
|
-
for (; ; ) {
|
|
58844
|
-
q = divide(n, d, 0, 1, 1);
|
|
58845
|
-
d2 = d0.plus(q.times(d1));
|
|
58846
|
-
if (d2.cmp(maxD) == 1) break;
|
|
58847
|
-
d0 = d1;
|
|
58848
|
-
d1 = d2;
|
|
58849
|
-
d2 = n1;
|
|
58850
|
-
n1 = n0.plus(q.times(d2));
|
|
58851
|
-
n0 = d2;
|
|
58852
|
-
d2 = d;
|
|
58853
|
-
d = n.minus(q.times(d2));
|
|
58854
|
-
n = d2;
|
|
58855
|
-
}
|
|
58856
|
-
d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
|
|
58857
|
-
n0 = n0.plus(d2.times(n1));
|
|
58858
|
-
d0 = d0.plus(d2.times(d1));
|
|
58859
|
-
n0.s = n1.s = x.s;
|
|
58860
|
-
r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
|
|
58861
|
-
Ctor.precision = pr;
|
|
58862
|
-
external = true;
|
|
58863
|
-
return r;
|
|
58864
|
-
};
|
|
58865
|
-
P.toHexadecimal = P.toHex = function(sd, rm) {
|
|
58866
|
-
return toStringBinary(this, 16, sd, rm);
|
|
58867
|
-
};
|
|
58868
|
-
P.toNearest = function(y, rm) {
|
|
58869
|
-
var x = this, Ctor = x.constructor;
|
|
58870
|
-
x = new Ctor(x);
|
|
58871
|
-
if (y == null) {
|
|
58872
|
-
if (!x.d) return x;
|
|
58873
|
-
y = new Ctor(1);
|
|
58874
|
-
rm = Ctor.rounding;
|
|
58875
|
-
} else {
|
|
58876
|
-
y = new Ctor(y);
|
|
58877
|
-
if (rm === void 0) {
|
|
58878
|
-
rm = Ctor.rounding;
|
|
58879
|
-
} else {
|
|
58880
|
-
checkInt32(rm, 0, 8);
|
|
58881
|
-
}
|
|
58882
|
-
if (!x.d) return y.s ? x : y;
|
|
58883
|
-
if (!y.d) {
|
|
58884
|
-
if (y.s) y.s = x.s;
|
|
58885
|
-
return y;
|
|
58886
|
-
}
|
|
58887
|
-
}
|
|
58888
|
-
if (y.d[0]) {
|
|
58889
|
-
external = false;
|
|
58890
|
-
x = divide(x, y, 0, rm, 1).times(y);
|
|
58891
|
-
external = true;
|
|
58892
|
-
finalise(x);
|
|
58893
|
-
} else {
|
|
58894
|
-
y.s = x.s;
|
|
58895
|
-
x = y;
|
|
58896
|
-
}
|
|
58897
|
-
return x;
|
|
58898
|
-
};
|
|
58899
|
-
P.toNumber = function() {
|
|
58900
|
-
return +this;
|
|
58901
|
-
};
|
|
58902
|
-
P.toOctal = function(sd, rm) {
|
|
58903
|
-
return toStringBinary(this, 8, sd, rm);
|
|
58904
|
-
};
|
|
58905
|
-
P.toPower = P.pow = function(y) {
|
|
58906
|
-
var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
|
|
58907
|
-
if (!x.d || !y.d || !x.d[0] || !y.d[0]) return new Ctor(mathpow(+x, yn));
|
|
58908
|
-
x = new Ctor(x);
|
|
58909
|
-
if (x.eq(1)) return x;
|
|
58910
|
-
pr = Ctor.precision;
|
|
58911
|
-
rm = Ctor.rounding;
|
|
58912
|
-
if (y.eq(1)) return finalise(x, pr, rm);
|
|
58913
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
58914
|
-
if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
|
|
58915
|
-
r = intPow(Ctor, x, k, pr);
|
|
58916
|
-
return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
|
|
58917
|
-
}
|
|
58918
|
-
s = x.s;
|
|
58919
|
-
if (s < 0) {
|
|
58920
|
-
if (e < y.d.length - 1) return new Ctor(NaN);
|
|
58921
|
-
if ((y.d[e] & 1) == 0) s = 1;
|
|
58922
|
-
if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
|
|
58923
|
-
x.s = s;
|
|
58924
|
-
return x;
|
|
58925
|
-
}
|
|
58926
|
-
}
|
|
58927
|
-
k = mathpow(+x, yn);
|
|
58928
|
-
e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
|
|
58929
|
-
if (e > Ctor.maxE + 1 || e < Ctor.minE - 1) return new Ctor(e > 0 ? s / 0 : 0);
|
|
58930
|
-
external = false;
|
|
58931
|
-
Ctor.rounding = x.s = 1;
|
|
58932
|
-
k = Math.min(12, (e + "").length);
|
|
58933
|
-
r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
|
|
58934
|
-
if (r.d) {
|
|
58935
|
-
r = finalise(r, pr + 5, 1);
|
|
58936
|
-
if (checkRoundingDigits(r.d, pr, rm)) {
|
|
58937
|
-
e = pr + 10;
|
|
58938
|
-
r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
|
|
58939
|
-
if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 1e14) {
|
|
58940
|
-
r = finalise(r, pr + 1, 0);
|
|
58941
|
-
}
|
|
58942
|
-
}
|
|
58943
|
-
}
|
|
58944
|
-
r.s = s;
|
|
58945
|
-
external = true;
|
|
58946
|
-
Ctor.rounding = rm;
|
|
58947
|
-
return finalise(r, pr, rm);
|
|
58948
|
-
};
|
|
58949
|
-
P.toPrecision = function(sd, rm) {
|
|
58950
|
-
var str, x = this, Ctor = x.constructor;
|
|
58951
|
-
if (sd === void 0) {
|
|
58952
|
-
str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
58953
|
-
} else {
|
|
58954
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
58955
|
-
if (rm === void 0) rm = Ctor.rounding;
|
|
58956
|
-
else checkInt32(rm, 0, 8);
|
|
58957
|
-
x = finalise(new Ctor(x), sd, rm);
|
|
58958
|
-
str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
|
|
58959
|
-
}
|
|
58960
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
58961
|
-
};
|
|
58962
|
-
P.toSignificantDigits = P.toSD = function(sd, rm) {
|
|
58963
|
-
var x = this, Ctor = x.constructor;
|
|
58964
|
-
if (sd === void 0) {
|
|
58965
|
-
sd = Ctor.precision;
|
|
58966
|
-
rm = Ctor.rounding;
|
|
58967
|
-
} else {
|
|
58968
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
58969
|
-
if (rm === void 0) rm = Ctor.rounding;
|
|
58970
|
-
else checkInt32(rm, 0, 8);
|
|
58971
|
-
}
|
|
58972
|
-
return finalise(new Ctor(x), sd, rm);
|
|
58973
|
-
};
|
|
58974
|
-
P.toString = function() {
|
|
58975
|
-
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
58976
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
58977
|
-
};
|
|
58978
|
-
P.truncated = P.trunc = function() {
|
|
58979
|
-
return finalise(new this.constructor(this), this.e + 1, 1);
|
|
58980
|
-
};
|
|
58981
|
-
P.valueOf = P.toJSON = function() {
|
|
58982
|
-
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
58983
|
-
return x.isNeg() ? "-" + str : str;
|
|
58984
|
-
};
|
|
58985
|
-
function digitsToString(d) {
|
|
58986
|
-
var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
|
|
58987
|
-
if (indexOfLastWord > 0) {
|
|
58988
|
-
str += w;
|
|
58989
|
-
for (i = 1; i < indexOfLastWord; i++) {
|
|
58990
|
-
ws = d[i] + "";
|
|
58991
|
-
k = LOG_BASE - ws.length;
|
|
58992
|
-
if (k) str += getZeroString(k);
|
|
58993
|
-
str += ws;
|
|
58994
|
-
}
|
|
58995
|
-
w = d[i];
|
|
58996
|
-
ws = w + "";
|
|
58997
|
-
k = LOG_BASE - ws.length;
|
|
58998
|
-
if (k) str += getZeroString(k);
|
|
58999
|
-
} else if (w === 0) {
|
|
59000
|
-
return "0";
|
|
59001
|
-
}
|
|
59002
|
-
for (; w % 10 === 0; ) w /= 10;
|
|
59003
|
-
return str + w;
|
|
59004
|
-
}
|
|
59005
|
-
function checkInt32(i, min2, max2) {
|
|
59006
|
-
if (i !== ~~i || i < min2 || i > max2) {
|
|
59007
|
-
throw Error(invalidArgument + i);
|
|
59008
|
-
}
|
|
59009
|
-
}
|
|
59010
|
-
function checkRoundingDigits(d, i, rm, repeating) {
|
|
59011
|
-
var di, k, r, rd;
|
|
59012
|
-
for (k = d[0]; k >= 10; k /= 10) --i;
|
|
59013
|
-
if (--i < 0) {
|
|
59014
|
-
i += LOG_BASE;
|
|
59015
|
-
di = 0;
|
|
59016
|
-
} else {
|
|
59017
|
-
di = Math.ceil((i + 1) / LOG_BASE);
|
|
59018
|
-
i %= LOG_BASE;
|
|
59019
|
-
}
|
|
59020
|
-
k = mathpow(10, LOG_BASE - i);
|
|
59021
|
-
rd = d[di] % k | 0;
|
|
59022
|
-
if (repeating == null) {
|
|
59023
|
-
if (i < 3) {
|
|
59024
|
-
if (i == 0) rd = rd / 100 | 0;
|
|
59025
|
-
else if (i == 1) rd = rd / 10 | 0;
|
|
59026
|
-
r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 5e4 || rd == 0;
|
|
59027
|
-
} else {
|
|
59028
|
-
r = (rm < 4 && rd + 1 == k || rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 100 | 0) == mathpow(10, i - 2) - 1 || (rd == k / 2 || rd == 0) && (d[di + 1] / k / 100 | 0) == 0;
|
|
59029
|
-
}
|
|
59030
|
-
} else {
|
|
59031
|
-
if (i < 4) {
|
|
59032
|
-
if (i == 0) rd = rd / 1e3 | 0;
|
|
59033
|
-
else if (i == 1) rd = rd / 100 | 0;
|
|
59034
|
-
else if (i == 2) rd = rd / 10 | 0;
|
|
59035
|
-
r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
|
|
59036
|
-
} else {
|
|
59037
|
-
r = ((repeating || rm < 4) && rd + 1 == k || !repeating && rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 1e3 | 0) == mathpow(10, i - 3) - 1;
|
|
59038
|
-
}
|
|
59039
|
-
}
|
|
59040
|
-
return r;
|
|
59041
|
-
}
|
|
59042
|
-
function convertBase(str, baseIn, baseOut) {
|
|
59043
|
-
var j, arr = [0], arrL, i = 0, strL = str.length;
|
|
59044
|
-
for (; i < strL; ) {
|
|
59045
|
-
for (arrL = arr.length; arrL--; ) arr[arrL] *= baseIn;
|
|
59046
|
-
arr[0] += NUMERALS.indexOf(str.charAt(i++));
|
|
59047
|
-
for (j = 0; j < arr.length; j++) {
|
|
59048
|
-
if (arr[j] > baseOut - 1) {
|
|
59049
|
-
if (arr[j + 1] === void 0) arr[j + 1] = 0;
|
|
59050
|
-
arr[j + 1] += arr[j] / baseOut | 0;
|
|
59051
|
-
arr[j] %= baseOut;
|
|
59052
|
-
}
|
|
59053
|
-
}
|
|
59054
|
-
}
|
|
59055
|
-
return arr.reverse();
|
|
59056
|
-
}
|
|
59057
|
-
function cosine(Ctor, x) {
|
|
59058
|
-
var k, len, y;
|
|
59059
|
-
if (x.isZero()) return x;
|
|
59060
|
-
len = x.d.length;
|
|
59061
|
-
if (len < 32) {
|
|
59062
|
-
k = Math.ceil(len / 3);
|
|
59063
|
-
y = (1 / tinyPow(4, k)).toString();
|
|
59064
|
-
} else {
|
|
59065
|
-
k = 16;
|
|
59066
|
-
y = "2.3283064365386962890625e-10";
|
|
59067
|
-
}
|
|
59068
|
-
Ctor.precision += k;
|
|
59069
|
-
x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
|
|
59070
|
-
for (var i = k; i--; ) {
|
|
59071
|
-
var cos2x = x.times(x);
|
|
59072
|
-
x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
|
|
59073
|
-
}
|
|
59074
|
-
Ctor.precision -= k;
|
|
59075
|
-
return x;
|
|
59076
|
-
}
|
|
59077
|
-
var divide = /* @__PURE__ */ (function() {
|
|
59078
|
-
function multiplyInteger(x, k, base) {
|
|
59079
|
-
var temp, carry = 0, i = x.length;
|
|
59080
|
-
for (x = x.slice(); i--; ) {
|
|
59081
|
-
temp = x[i] * k + carry;
|
|
59082
|
-
x[i] = temp % base | 0;
|
|
59083
|
-
carry = temp / base | 0;
|
|
59084
|
-
}
|
|
59085
|
-
if (carry) x.unshift(carry);
|
|
59086
|
-
return x;
|
|
59087
|
-
}
|
|
59088
|
-
function compare(a, b, aL, bL) {
|
|
59089
|
-
var i, r;
|
|
59090
|
-
if (aL != bL) {
|
|
59091
|
-
r = aL > bL ? 1 : -1;
|
|
59092
|
-
} else {
|
|
59093
|
-
for (i = r = 0; i < aL; i++) {
|
|
59094
|
-
if (a[i] != b[i]) {
|
|
59095
|
-
r = a[i] > b[i] ? 1 : -1;
|
|
59096
|
-
break;
|
|
59097
|
-
}
|
|
59098
|
-
}
|
|
59099
|
-
}
|
|
59100
|
-
return r;
|
|
59101
|
-
}
|
|
59102
|
-
function subtract(a, b, aL, base) {
|
|
59103
|
-
var i = 0;
|
|
59104
|
-
for (; aL--; ) {
|
|
59105
|
-
a[aL] -= i;
|
|
59106
|
-
i = a[aL] < b[aL] ? 1 : 0;
|
|
59107
|
-
a[aL] = i * base + a[aL] - b[aL];
|
|
59108
|
-
}
|
|
59109
|
-
for (; !a[0] && a.length > 1; ) a.shift();
|
|
59110
|
-
}
|
|
59111
|
-
return function(x, y, pr, rm, dp, base) {
|
|
59112
|
-
var cmp, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign2 = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
|
|
59113
|
-
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
59114
|
-
return new Ctor(
|
|
59115
|
-
// Return NaN if either NaN, or both Infinity or 0.
|
|
59116
|
-
!x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : (
|
|
59117
|
-
// Return ±0 if x is 0 or y is ±Infinity, or return ±Infinity as y is 0.
|
|
59118
|
-
xd && xd[0] == 0 || !yd ? sign2 * 0 : sign2 / 0
|
|
59119
|
-
)
|
|
59120
|
-
);
|
|
59121
|
-
}
|
|
59122
|
-
if (base) {
|
|
59123
|
-
logBase = 1;
|
|
59124
|
-
e = x.e - y.e;
|
|
59125
|
-
} else {
|
|
59126
|
-
base = BASE;
|
|
59127
|
-
logBase = LOG_BASE;
|
|
59128
|
-
e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
|
|
59129
|
-
}
|
|
59130
|
-
yL = yd.length;
|
|
59131
|
-
xL = xd.length;
|
|
59132
|
-
q = new Ctor(sign2);
|
|
59133
|
-
qd = q.d = [];
|
|
59134
|
-
for (i = 0; yd[i] == (xd[i] || 0); i++) ;
|
|
59135
|
-
if (yd[i] > (xd[i] || 0)) e--;
|
|
59136
|
-
if (pr == null) {
|
|
59137
|
-
sd = pr = Ctor.precision;
|
|
59138
|
-
rm = Ctor.rounding;
|
|
59139
|
-
} else if (dp) {
|
|
59140
|
-
sd = pr + (x.e - y.e) + 1;
|
|
59141
|
-
} else {
|
|
59142
|
-
sd = pr;
|
|
59143
|
-
}
|
|
59144
|
-
if (sd < 0) {
|
|
59145
|
-
qd.push(1);
|
|
59146
|
-
more = true;
|
|
59147
|
-
} else {
|
|
59148
|
-
sd = sd / logBase + 2 | 0;
|
|
59149
|
-
i = 0;
|
|
59150
|
-
if (yL == 1) {
|
|
59151
|
-
k = 0;
|
|
59152
|
-
yd = yd[0];
|
|
59153
|
-
sd++;
|
|
59154
|
-
for (; (i < xL || k) && sd--; i++) {
|
|
59155
|
-
t = k * base + (xd[i] || 0);
|
|
59156
|
-
qd[i] = t / yd | 0;
|
|
59157
|
-
k = t % yd | 0;
|
|
59158
|
-
}
|
|
59159
|
-
more = k || i < xL;
|
|
59160
|
-
} else {
|
|
59161
|
-
k = base / (yd[0] + 1) | 0;
|
|
59162
|
-
if (k > 1) {
|
|
59163
|
-
yd = multiplyInteger(yd, k, base);
|
|
59164
|
-
xd = multiplyInteger(xd, k, base);
|
|
59165
|
-
yL = yd.length;
|
|
59166
|
-
xL = xd.length;
|
|
59167
|
-
}
|
|
59168
|
-
xi = yL;
|
|
59169
|
-
rem = xd.slice(0, yL);
|
|
59170
|
-
remL = rem.length;
|
|
59171
|
-
for (; remL < yL; ) rem[remL++] = 0;
|
|
59172
|
-
yz = yd.slice();
|
|
59173
|
-
yz.unshift(0);
|
|
59174
|
-
yd0 = yd[0];
|
|
59175
|
-
if (yd[1] >= base / 2) ++yd0;
|
|
59176
|
-
do {
|
|
59177
|
-
k = 0;
|
|
59178
|
-
cmp = compare(yd, rem, yL, remL);
|
|
59179
|
-
if (cmp < 0) {
|
|
59180
|
-
rem0 = rem[0];
|
|
59181
|
-
if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
|
|
59182
|
-
k = rem0 / yd0 | 0;
|
|
59183
|
-
if (k > 1) {
|
|
59184
|
-
if (k >= base) k = base - 1;
|
|
59185
|
-
prod = multiplyInteger(yd, k, base);
|
|
59186
|
-
prodL = prod.length;
|
|
59187
|
-
remL = rem.length;
|
|
59188
|
-
cmp = compare(prod, rem, prodL, remL);
|
|
59189
|
-
if (cmp == 1) {
|
|
59190
|
-
k--;
|
|
59191
|
-
subtract(prod, yL < prodL ? yz : yd, prodL, base);
|
|
59192
|
-
}
|
|
59193
|
-
} else {
|
|
59194
|
-
if (k == 0) cmp = k = 1;
|
|
59195
|
-
prod = yd.slice();
|
|
59196
|
-
}
|
|
59197
|
-
prodL = prod.length;
|
|
59198
|
-
if (prodL < remL) prod.unshift(0);
|
|
59199
|
-
subtract(rem, prod, remL, base);
|
|
59200
|
-
if (cmp == -1) {
|
|
59201
|
-
remL = rem.length;
|
|
59202
|
-
cmp = compare(yd, rem, yL, remL);
|
|
59203
|
-
if (cmp < 1) {
|
|
59204
|
-
k++;
|
|
59205
|
-
subtract(rem, yL < remL ? yz : yd, remL, base);
|
|
59206
|
-
}
|
|
59207
|
-
}
|
|
59208
|
-
remL = rem.length;
|
|
59209
|
-
} else if (cmp === 0) {
|
|
59210
|
-
k++;
|
|
59211
|
-
rem = [0];
|
|
59212
|
-
}
|
|
59213
|
-
qd[i++] = k;
|
|
59214
|
-
if (cmp && rem[0]) {
|
|
59215
|
-
rem[remL++] = xd[xi] || 0;
|
|
59216
|
-
} else {
|
|
59217
|
-
rem = [xd[xi]];
|
|
59218
|
-
remL = 1;
|
|
59219
|
-
}
|
|
59220
|
-
} while ((xi++ < xL || rem[0] !== void 0) && sd--);
|
|
59221
|
-
more = rem[0] !== void 0;
|
|
59222
|
-
}
|
|
59223
|
-
if (!qd[0]) qd.shift();
|
|
59224
|
-
}
|
|
59225
|
-
if (logBase == 1) {
|
|
59226
|
-
q.e = e;
|
|
59227
|
-
inexact = more;
|
|
59228
|
-
} else {
|
|
59229
|
-
for (i = 1, k = qd[0]; k >= 10; k /= 10) i++;
|
|
59230
|
-
q.e = i + e * logBase - 1;
|
|
59231
|
-
finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
|
|
59232
|
-
}
|
|
59233
|
-
return q;
|
|
59234
|
-
};
|
|
59235
|
-
})();
|
|
59236
|
-
function finalise(x, sd, rm, isTruncated) {
|
|
59237
|
-
var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
|
|
59238
|
-
out: if (sd != null) {
|
|
59239
|
-
xd = x.d;
|
|
59240
|
-
if (!xd) return x;
|
|
59241
|
-
for (digits = 1, k = xd[0]; k >= 10; k /= 10) digits++;
|
|
59242
|
-
i = sd - digits;
|
|
59243
|
-
if (i < 0) {
|
|
59244
|
-
i += LOG_BASE;
|
|
59245
|
-
j = sd;
|
|
59246
|
-
w = xd[xdi = 0];
|
|
59247
|
-
rd = w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
59248
|
-
} else {
|
|
59249
|
-
xdi = Math.ceil((i + 1) / LOG_BASE);
|
|
59250
|
-
k = xd.length;
|
|
59251
|
-
if (xdi >= k) {
|
|
59252
|
-
if (isTruncated) {
|
|
59253
|
-
for (; k++ <= xdi; ) xd.push(0);
|
|
59254
|
-
w = rd = 0;
|
|
59255
|
-
digits = 1;
|
|
59256
|
-
i %= LOG_BASE;
|
|
59257
|
-
j = i - LOG_BASE + 1;
|
|
59258
|
-
} else {
|
|
59259
|
-
break out;
|
|
59260
|
-
}
|
|
59261
|
-
} else {
|
|
59262
|
-
w = k = xd[xdi];
|
|
59263
|
-
for (digits = 1; k >= 10; k /= 10) digits++;
|
|
59264
|
-
i %= LOG_BASE;
|
|
59265
|
-
j = i - LOG_BASE + digits;
|
|
59266
|
-
rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
59267
|
-
}
|
|
59268
|
-
}
|
|
59269
|
-
isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== void 0 || (j < 0 ? w : w % mathpow(10, digits - j - 1));
|
|
59270
|
-
roundUp = rm < 4 ? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
|
|
59271
|
-
(i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
59272
|
-
if (sd < 1 || !xd[0]) {
|
|
59273
|
-
xd.length = 0;
|
|
59274
|
-
if (roundUp) {
|
|
59275
|
-
sd -= x.e + 1;
|
|
59276
|
-
xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
|
|
59277
|
-
x.e = -sd || 0;
|
|
59278
|
-
} else {
|
|
59279
|
-
xd[0] = x.e = 0;
|
|
59280
|
-
}
|
|
59281
|
-
return x;
|
|
59282
|
-
}
|
|
59283
|
-
if (i == 0) {
|
|
59284
|
-
xd.length = xdi;
|
|
59285
|
-
k = 1;
|
|
59286
|
-
xdi--;
|
|
59287
|
-
} else {
|
|
59288
|
-
xd.length = xdi + 1;
|
|
59289
|
-
k = mathpow(10, LOG_BASE - i);
|
|
59290
|
-
xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
|
|
59291
|
-
}
|
|
59292
|
-
if (roundUp) {
|
|
59293
|
-
for (; ; ) {
|
|
59294
|
-
if (xdi == 0) {
|
|
59295
|
-
for (i = 1, j = xd[0]; j >= 10; j /= 10) i++;
|
|
59296
|
-
j = xd[0] += k;
|
|
59297
|
-
for (k = 1; j >= 10; j /= 10) k++;
|
|
59298
|
-
if (i != k) {
|
|
59299
|
-
x.e++;
|
|
59300
|
-
if (xd[0] == BASE) xd[0] = 1;
|
|
59301
|
-
}
|
|
59302
|
-
break;
|
|
59303
|
-
} else {
|
|
59304
|
-
xd[xdi] += k;
|
|
59305
|
-
if (xd[xdi] != BASE) break;
|
|
59306
|
-
xd[xdi--] = 0;
|
|
59307
|
-
k = 1;
|
|
59308
|
-
}
|
|
59309
|
-
}
|
|
59310
|
-
}
|
|
59311
|
-
for (i = xd.length; xd[--i] === 0; ) xd.pop();
|
|
59312
|
-
}
|
|
59313
|
-
if (external) {
|
|
59314
|
-
if (x.e > Ctor.maxE) {
|
|
59315
|
-
x.d = null;
|
|
59316
|
-
x.e = NaN;
|
|
59317
|
-
} else if (x.e < Ctor.minE) {
|
|
59318
|
-
x.e = 0;
|
|
59319
|
-
x.d = [0];
|
|
59320
|
-
}
|
|
59321
|
-
}
|
|
59322
|
-
return x;
|
|
59323
|
-
}
|
|
59324
|
-
function finiteToString(x, isExp, sd) {
|
|
59325
|
-
if (!x.isFinite()) return nonFiniteToString(x);
|
|
59326
|
-
var k, e = x.e, str = digitsToString(x.d), len = str.length;
|
|
59327
|
-
if (isExp) {
|
|
59328
|
-
if (sd && (k = sd - len) > 0) {
|
|
59329
|
-
str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
|
|
59330
|
-
} else if (len > 1) {
|
|
59331
|
-
str = str.charAt(0) + "." + str.slice(1);
|
|
59332
|
-
}
|
|
59333
|
-
str = str + (x.e < 0 ? "e" : "e+") + x.e;
|
|
59334
|
-
} else if (e < 0) {
|
|
59335
|
-
str = "0." + getZeroString(-e - 1) + str;
|
|
59336
|
-
if (sd && (k = sd - len) > 0) str += getZeroString(k);
|
|
59337
|
-
} else if (e >= len) {
|
|
59338
|
-
str += getZeroString(e + 1 - len);
|
|
59339
|
-
if (sd && (k = sd - e - 1) > 0) str = str + "." + getZeroString(k);
|
|
59340
|
-
} else {
|
|
59341
|
-
if ((k = e + 1) < len) str = str.slice(0, k) + "." + str.slice(k);
|
|
59342
|
-
if (sd && (k = sd - len) > 0) {
|
|
59343
|
-
if (e + 1 === len) str += ".";
|
|
59344
|
-
str += getZeroString(k);
|
|
59345
|
-
}
|
|
59346
|
-
}
|
|
59347
|
-
return str;
|
|
59348
|
-
}
|
|
59349
|
-
function getBase10Exponent(digits, e) {
|
|
59350
|
-
var w = digits[0];
|
|
59351
|
-
for (e *= LOG_BASE; w >= 10; w /= 10) e++;
|
|
59352
|
-
return e;
|
|
59353
|
-
}
|
|
59354
|
-
function getLn10(Ctor, sd, pr) {
|
|
59355
|
-
if (sd > LN10_PRECISION) {
|
|
59356
|
-
external = true;
|
|
59357
|
-
if (pr) Ctor.precision = pr;
|
|
59358
|
-
throw Error(precisionLimitExceeded);
|
|
59359
|
-
}
|
|
59360
|
-
return finalise(new Ctor(LN10), sd, 1, true);
|
|
59361
|
-
}
|
|
59362
|
-
function getPi(Ctor, sd, rm) {
|
|
59363
|
-
if (sd > PI_PRECISION) throw Error(precisionLimitExceeded);
|
|
59364
|
-
return finalise(new Ctor(PI), sd, rm, true);
|
|
59365
|
-
}
|
|
59366
|
-
function getPrecision(digits) {
|
|
59367
|
-
var w = digits.length - 1, len = w * LOG_BASE + 1;
|
|
59368
|
-
w = digits[w];
|
|
59369
|
-
if (w) {
|
|
59370
|
-
for (; w % 10 == 0; w /= 10) len--;
|
|
59371
|
-
for (w = digits[0]; w >= 10; w /= 10) len++;
|
|
59372
|
-
}
|
|
59373
|
-
return len;
|
|
59374
|
-
}
|
|
59375
|
-
function getZeroString(k) {
|
|
59376
|
-
var zs = "";
|
|
59377
|
-
for (; k--; ) zs += "0";
|
|
59378
|
-
return zs;
|
|
59379
|
-
}
|
|
59380
|
-
function intPow(Ctor, x, n, pr) {
|
|
59381
|
-
var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
|
|
59382
|
-
external = false;
|
|
59383
|
-
for (; ; ) {
|
|
59384
|
-
if (n % 2) {
|
|
59385
|
-
r = r.times(x);
|
|
59386
|
-
if (truncate(r.d, k)) isTruncated = true;
|
|
59387
|
-
}
|
|
59388
|
-
n = mathfloor(n / 2);
|
|
59389
|
-
if (n === 0) {
|
|
59390
|
-
n = r.d.length - 1;
|
|
59391
|
-
if (isTruncated && r.d[n] === 0) ++r.d[n];
|
|
59392
|
-
break;
|
|
59393
|
-
}
|
|
59394
|
-
x = x.times(x);
|
|
59395
|
-
truncate(x.d, k);
|
|
59396
|
-
}
|
|
59397
|
-
external = true;
|
|
59398
|
-
return r;
|
|
59399
|
-
}
|
|
59400
|
-
function isOdd(n) {
|
|
59401
|
-
return n.d[n.d.length - 1] & 1;
|
|
59402
|
-
}
|
|
59403
|
-
function maxOrMin(Ctor, args, n) {
|
|
59404
|
-
var k, y, x = new Ctor(args[0]), i = 0;
|
|
59405
|
-
for (; ++i < args.length; ) {
|
|
59406
|
-
y = new Ctor(args[i]);
|
|
59407
|
-
if (!y.s) {
|
|
59408
|
-
x = y;
|
|
59409
|
-
break;
|
|
59410
|
-
}
|
|
59411
|
-
k = x.cmp(y);
|
|
59412
|
-
if (k === n || k === 0 && x.s === n) {
|
|
59413
|
-
x = y;
|
|
59414
|
-
}
|
|
59415
|
-
}
|
|
59416
|
-
return x;
|
|
59417
|
-
}
|
|
59418
|
-
function naturalExponential(x, sd) {
|
|
59419
|
-
var denominator, guard, j, pow2, sum2, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
|
59420
|
-
if (!x.d || !x.d[0] || x.e > 17) {
|
|
59421
|
-
return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
|
|
59422
|
-
}
|
|
59423
|
-
if (sd == null) {
|
|
59424
|
-
external = false;
|
|
59425
|
-
wpr = pr;
|
|
59426
|
-
} else {
|
|
59427
|
-
wpr = sd;
|
|
59428
|
-
}
|
|
59429
|
-
t = new Ctor(0.03125);
|
|
59430
|
-
while (x.e > -2) {
|
|
59431
|
-
x = x.times(t);
|
|
59432
|
-
k += 5;
|
|
59433
|
-
}
|
|
59434
|
-
guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
|
|
59435
|
-
wpr += guard;
|
|
59436
|
-
denominator = pow2 = sum2 = new Ctor(1);
|
|
59437
|
-
Ctor.precision = wpr;
|
|
59438
|
-
for (; ; ) {
|
|
59439
|
-
pow2 = finalise(pow2.times(x), wpr, 1);
|
|
59440
|
-
denominator = denominator.times(++i);
|
|
59441
|
-
t = sum2.plus(divide(pow2, denominator, wpr, 1));
|
|
59442
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
|
59443
|
-
j = k;
|
|
59444
|
-
while (j--) sum2 = finalise(sum2.times(sum2), wpr, 1);
|
|
59445
|
-
if (sd == null) {
|
|
59446
|
-
if (rep < 3 && checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
|
59447
|
-
Ctor.precision = wpr += 10;
|
|
59448
|
-
denominator = pow2 = t = new Ctor(1);
|
|
59449
|
-
i = 0;
|
|
59450
|
-
rep++;
|
|
59451
|
-
} else {
|
|
59452
|
-
return finalise(sum2, Ctor.precision = pr, rm, external = true);
|
|
59453
|
-
}
|
|
59454
|
-
} else {
|
|
59455
|
-
Ctor.precision = pr;
|
|
59456
|
-
return sum2;
|
|
59457
|
-
}
|
|
59458
|
-
}
|
|
59459
|
-
sum2 = t;
|
|
59460
|
-
}
|
|
59461
|
-
}
|
|
59462
|
-
function naturalLogarithm(y, sd) {
|
|
59463
|
-
var c, c0, denominator, e, numerator, rep, sum2, t, wpr, x1, x2, n = 1, guard = 10, x = y, xd = x.d, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
|
59464
|
-
if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
|
|
59465
|
-
return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
|
|
59466
|
-
}
|
|
59467
|
-
if (sd == null) {
|
|
59468
|
-
external = false;
|
|
59469
|
-
wpr = pr;
|
|
59470
|
-
} else {
|
|
59471
|
-
wpr = sd;
|
|
59472
|
-
}
|
|
59473
|
-
Ctor.precision = wpr += guard;
|
|
59474
|
-
c = digitsToString(xd);
|
|
59475
|
-
c0 = c.charAt(0);
|
|
59476
|
-
if (Math.abs(e = x.e) < 15e14) {
|
|
59477
|
-
while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
|
|
59478
|
-
x = x.times(y);
|
|
59479
|
-
c = digitsToString(x.d);
|
|
59480
|
-
c0 = c.charAt(0);
|
|
59481
|
-
n++;
|
|
59482
|
-
}
|
|
59483
|
-
e = x.e;
|
|
59484
|
-
if (c0 > 1) {
|
|
59485
|
-
x = new Ctor("0." + c);
|
|
59486
|
-
e++;
|
|
59487
|
-
} else {
|
|
59488
|
-
x = new Ctor(c0 + "." + c.slice(1));
|
|
59489
|
-
}
|
|
59490
|
-
} else {
|
|
59491
|
-
t = getLn10(Ctor, wpr + 2, pr).times(e + "");
|
|
59492
|
-
x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
|
|
59493
|
-
Ctor.precision = pr;
|
|
59494
|
-
return sd == null ? finalise(x, pr, rm, external = true) : x;
|
|
59495
|
-
}
|
|
59496
|
-
x1 = x;
|
|
59497
|
-
sum2 = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
|
|
59498
|
-
x2 = finalise(x.times(x), wpr, 1);
|
|
59499
|
-
denominator = 3;
|
|
59500
|
-
for (; ; ) {
|
|
59501
|
-
numerator = finalise(numerator.times(x2), wpr, 1);
|
|
59502
|
-
t = sum2.plus(divide(numerator, new Ctor(denominator), wpr, 1));
|
|
59503
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
|
59504
|
-
sum2 = sum2.times(2);
|
|
59505
|
-
if (e !== 0) sum2 = sum2.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
|
|
59506
|
-
sum2 = divide(sum2, new Ctor(n), wpr, 1);
|
|
59507
|
-
if (sd == null) {
|
|
59508
|
-
if (checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
|
59509
|
-
Ctor.precision = wpr += guard;
|
|
59510
|
-
t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
|
|
59511
|
-
x2 = finalise(x.times(x), wpr, 1);
|
|
59512
|
-
denominator = rep = 1;
|
|
59513
|
-
} else {
|
|
59514
|
-
return finalise(sum2, Ctor.precision = pr, rm, external = true);
|
|
59515
|
-
}
|
|
59516
|
-
} else {
|
|
59517
|
-
Ctor.precision = pr;
|
|
59518
|
-
return sum2;
|
|
59519
|
-
}
|
|
59520
|
-
}
|
|
59521
|
-
sum2 = t;
|
|
59522
|
-
denominator += 2;
|
|
59523
|
-
}
|
|
59524
|
-
}
|
|
59525
|
-
function nonFiniteToString(x) {
|
|
59526
|
-
return String(x.s * x.s / 0);
|
|
59527
|
-
}
|
|
59528
|
-
function parseDecimal(x, str) {
|
|
59529
|
-
var e, i, len;
|
|
59530
|
-
if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
|
|
59531
|
-
if ((i = str.search(/e/i)) > 0) {
|
|
59532
|
-
if (e < 0) e = i;
|
|
59533
|
-
e += +str.slice(i + 1);
|
|
59534
|
-
str = str.substring(0, i);
|
|
59535
|
-
} else if (e < 0) {
|
|
59536
|
-
e = str.length;
|
|
59537
|
-
}
|
|
59538
|
-
for (i = 0; str.charCodeAt(i) === 48; i++) ;
|
|
59539
|
-
for (len = str.length; str.charCodeAt(len - 1) === 48; --len) ;
|
|
59540
|
-
str = str.slice(i, len);
|
|
59541
|
-
if (str) {
|
|
59542
|
-
len -= i;
|
|
59543
|
-
x.e = e = e - i - 1;
|
|
59544
|
-
x.d = [];
|
|
59545
|
-
i = (e + 1) % LOG_BASE;
|
|
59546
|
-
if (e < 0) i += LOG_BASE;
|
|
59547
|
-
if (i < len) {
|
|
59548
|
-
if (i) x.d.push(+str.slice(0, i));
|
|
59549
|
-
for (len -= LOG_BASE; i < len; ) x.d.push(+str.slice(i, i += LOG_BASE));
|
|
59550
|
-
str = str.slice(i);
|
|
59551
|
-
i = LOG_BASE - str.length;
|
|
59552
|
-
} else {
|
|
59553
|
-
i -= len;
|
|
59554
|
-
}
|
|
59555
|
-
for (; i--; ) str += "0";
|
|
59556
|
-
x.d.push(+str);
|
|
59557
|
-
if (external) {
|
|
59558
|
-
if (x.e > x.constructor.maxE) {
|
|
59559
|
-
x.d = null;
|
|
59560
|
-
x.e = NaN;
|
|
59561
|
-
} else if (x.e < x.constructor.minE) {
|
|
59562
|
-
x.e = 0;
|
|
59563
|
-
x.d = [0];
|
|
59564
|
-
}
|
|
59565
|
-
}
|
|
59566
|
-
} else {
|
|
59567
|
-
x.e = 0;
|
|
59568
|
-
x.d = [0];
|
|
59569
|
-
}
|
|
59570
|
-
return x;
|
|
59571
|
-
}
|
|
59572
|
-
function parseOther(x, str) {
|
|
59573
|
-
var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
|
|
59574
|
-
if (str.indexOf("_") > -1) {
|
|
59575
|
-
str = str.replace(/(\d)_(?=\d)/g, "$1");
|
|
59576
|
-
if (isDecimal.test(str)) return parseDecimal(x, str);
|
|
59577
|
-
} else if (str === "Infinity" || str === "NaN") {
|
|
59578
|
-
if (!+str) x.s = NaN;
|
|
59579
|
-
x.e = NaN;
|
|
59580
|
-
x.d = null;
|
|
59581
|
-
return x;
|
|
59582
|
-
}
|
|
59583
|
-
if (isHex.test(str)) {
|
|
59584
|
-
base = 16;
|
|
59585
|
-
str = str.toLowerCase();
|
|
59586
|
-
} else if (isBinary.test(str)) {
|
|
59587
|
-
base = 2;
|
|
59588
|
-
} else if (isOctal.test(str)) {
|
|
59589
|
-
base = 8;
|
|
59590
|
-
} else {
|
|
59591
|
-
throw Error(invalidArgument + str);
|
|
59592
|
-
}
|
|
59593
|
-
i = str.search(/p/i);
|
|
59594
|
-
if (i > 0) {
|
|
59595
|
-
p = +str.slice(i + 1);
|
|
59596
|
-
str = str.substring(2, i);
|
|
59597
|
-
} else {
|
|
59598
|
-
str = str.slice(2);
|
|
59599
|
-
}
|
|
59600
|
-
i = str.indexOf(".");
|
|
59601
|
-
isFloat = i >= 0;
|
|
59602
|
-
Ctor = x.constructor;
|
|
59603
|
-
if (isFloat) {
|
|
59604
|
-
str = str.replace(".", "");
|
|
59605
|
-
len = str.length;
|
|
59606
|
-
i = len - i;
|
|
59607
|
-
divisor = intPow(Ctor, new Ctor(base), i, i * 2);
|
|
59608
|
-
}
|
|
59609
|
-
xd = convertBase(str, base, BASE);
|
|
59610
|
-
xe = xd.length - 1;
|
|
59611
|
-
for (i = xe; xd[i] === 0; --i) xd.pop();
|
|
59612
|
-
if (i < 0) return new Ctor(x.s * 0);
|
|
59613
|
-
x.e = getBase10Exponent(xd, xe);
|
|
59614
|
-
x.d = xd;
|
|
59615
|
-
external = false;
|
|
59616
|
-
if (isFloat) x = divide(x, divisor, len * 4);
|
|
59617
|
-
if (p) x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
|
|
59618
|
-
external = true;
|
|
59619
|
-
return x;
|
|
59620
|
-
}
|
|
59621
|
-
function sine(Ctor, x) {
|
|
59622
|
-
var k, len = x.d.length;
|
|
59623
|
-
if (len < 3) {
|
|
59624
|
-
return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
|
|
59625
|
-
}
|
|
59626
|
-
k = 1.4 * Math.sqrt(len);
|
|
59627
|
-
k = k > 16 ? 16 : k | 0;
|
|
59628
|
-
x = x.times(1 / tinyPow(5, k));
|
|
59629
|
-
x = taylorSeries(Ctor, 2, x, x);
|
|
59630
|
-
var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
59631
|
-
for (; k--; ) {
|
|
59632
|
-
sin2_x = x.times(x);
|
|
59633
|
-
x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
|
|
59634
|
-
}
|
|
59635
|
-
return x;
|
|
59636
|
-
}
|
|
59637
|
-
function taylorSeries(Ctor, n, x, y, isHyperbolic) {
|
|
59638
|
-
var j, t, u, x2, i = 1, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
|
|
59639
|
-
external = false;
|
|
59640
|
-
x2 = x.times(x);
|
|
59641
|
-
u = new Ctor(y);
|
|
59642
|
-
for (; ; ) {
|
|
59643
|
-
t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
|
|
59644
|
-
u = isHyperbolic ? y.plus(t) : y.minus(t);
|
|
59645
|
-
y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
|
|
59646
|
-
t = u.plus(y);
|
|
59647
|
-
if (t.d[k] !== void 0) {
|
|
59648
|
-
for (j = k; t.d[j] === u.d[j] && j--; ) ;
|
|
59649
|
-
if (j == -1) break;
|
|
59650
|
-
}
|
|
59651
|
-
j = u;
|
|
59652
|
-
u = y;
|
|
59653
|
-
y = t;
|
|
59654
|
-
t = j;
|
|
59655
|
-
i++;
|
|
59656
|
-
}
|
|
59657
|
-
external = true;
|
|
59658
|
-
t.d.length = k + 1;
|
|
59659
|
-
return t;
|
|
59660
|
-
}
|
|
59661
|
-
function tinyPow(b, e) {
|
|
59662
|
-
var n = b;
|
|
59663
|
-
while (--e) n *= b;
|
|
59664
|
-
return n;
|
|
59665
|
-
}
|
|
59666
|
-
function toLessThanHalfPi(Ctor, x) {
|
|
59667
|
-
var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
|
|
59668
|
-
x = x.abs();
|
|
59669
|
-
if (x.lte(halfPi)) {
|
|
59670
|
-
quadrant = isNeg ? 4 : 1;
|
|
59671
|
-
return x;
|
|
59672
|
-
}
|
|
59673
|
-
t = x.divToInt(pi);
|
|
59674
|
-
if (t.isZero()) {
|
|
59675
|
-
quadrant = isNeg ? 3 : 2;
|
|
59676
|
-
} else {
|
|
59677
|
-
x = x.minus(t.times(pi));
|
|
59678
|
-
if (x.lte(halfPi)) {
|
|
59679
|
-
quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
|
|
59680
|
-
return x;
|
|
59681
|
-
}
|
|
59682
|
-
quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
|
|
59683
|
-
}
|
|
59684
|
-
return x.minus(pi).abs();
|
|
59685
|
-
}
|
|
59686
|
-
function toStringBinary(x, baseOut, sd, rm) {
|
|
59687
|
-
var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== void 0;
|
|
59688
|
-
if (isExp) {
|
|
59689
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
59690
|
-
if (rm === void 0) rm = Ctor.rounding;
|
|
59691
|
-
else checkInt32(rm, 0, 8);
|
|
59692
|
-
} else {
|
|
59693
|
-
sd = Ctor.precision;
|
|
59694
|
-
rm = Ctor.rounding;
|
|
59695
|
-
}
|
|
59696
|
-
if (!x.isFinite()) {
|
|
59697
|
-
str = nonFiniteToString(x);
|
|
59698
|
-
} else {
|
|
59699
|
-
str = finiteToString(x);
|
|
59700
|
-
i = str.indexOf(".");
|
|
59701
|
-
if (isExp) {
|
|
59702
|
-
base = 2;
|
|
59703
|
-
if (baseOut == 16) {
|
|
59704
|
-
sd = sd * 4 - 3;
|
|
59705
|
-
} else if (baseOut == 8) {
|
|
59706
|
-
sd = sd * 3 - 2;
|
|
59707
|
-
}
|
|
59708
|
-
} else {
|
|
59709
|
-
base = baseOut;
|
|
59710
|
-
}
|
|
59711
|
-
if (i >= 0) {
|
|
59712
|
-
str = str.replace(".", "");
|
|
59713
|
-
y = new Ctor(1);
|
|
59714
|
-
y.e = str.length - i;
|
|
59715
|
-
y.d = convertBase(finiteToString(y), 10, base);
|
|
59716
|
-
y.e = y.d.length;
|
|
59717
|
-
}
|
|
59718
|
-
xd = convertBase(str, 10, base);
|
|
59719
|
-
e = len = xd.length;
|
|
59720
|
-
for (; xd[--len] == 0; ) xd.pop();
|
|
59721
|
-
if (!xd[0]) {
|
|
59722
|
-
str = isExp ? "0p+0" : "0";
|
|
59723
|
-
} else {
|
|
59724
|
-
if (i < 0) {
|
|
59725
|
-
e--;
|
|
59726
|
-
} else {
|
|
59727
|
-
x = new Ctor(x);
|
|
59728
|
-
x.d = xd;
|
|
59729
|
-
x.e = e;
|
|
59730
|
-
x = divide(x, y, sd, rm, 0, base);
|
|
59731
|
-
xd = x.d;
|
|
59732
|
-
e = x.e;
|
|
59733
|
-
roundUp = inexact;
|
|
59734
|
-
}
|
|
59735
|
-
i = xd[sd];
|
|
59736
|
-
k = base / 2;
|
|
59737
|
-
roundUp = roundUp || xd[sd + 1] !== void 0;
|
|
59738
|
-
roundUp = rm < 4 ? (i !== void 0 || roundUp) && (rm === 0 || rm === (x.s < 0 ? 3 : 2)) : i > k || i === k && (rm === 4 || roundUp || rm === 6 && xd[sd - 1] & 1 || rm === (x.s < 0 ? 8 : 7));
|
|
59739
|
-
xd.length = sd;
|
|
59740
|
-
if (roundUp) {
|
|
59741
|
-
for (; ++xd[--sd] > base - 1; ) {
|
|
59742
|
-
xd[sd] = 0;
|
|
59743
|
-
if (!sd) {
|
|
59744
|
-
++e;
|
|
59745
|
-
xd.unshift(1);
|
|
59746
|
-
}
|
|
59747
|
-
}
|
|
59748
|
-
}
|
|
59749
|
-
for (len = xd.length; !xd[len - 1]; --len) ;
|
|
59750
|
-
for (i = 0, str = ""; i < len; i++) str += NUMERALS.charAt(xd[i]);
|
|
59751
|
-
if (isExp) {
|
|
59752
|
-
if (len > 1) {
|
|
59753
|
-
if (baseOut == 16 || baseOut == 8) {
|
|
59754
|
-
i = baseOut == 16 ? 4 : 3;
|
|
59755
|
-
for (--len; len % i; len++) str += "0";
|
|
59756
|
-
xd = convertBase(str, base, baseOut);
|
|
59757
|
-
for (len = xd.length; !xd[len - 1]; --len) ;
|
|
59758
|
-
for (i = 1, str = "1."; i < len; i++) str += NUMERALS.charAt(xd[i]);
|
|
59759
|
-
} else {
|
|
59760
|
-
str = str.charAt(0) + "." + str.slice(1);
|
|
59761
|
-
}
|
|
59762
|
-
}
|
|
59763
|
-
str = str + (e < 0 ? "p" : "p+") + e;
|
|
59764
|
-
} else if (e < 0) {
|
|
59765
|
-
for (; ++e; ) str = "0" + str;
|
|
59766
|
-
str = "0." + str;
|
|
59767
|
-
} else {
|
|
59768
|
-
if (++e > len) for (e -= len; e--; ) str += "0";
|
|
59769
|
-
else if (e < len) str = str.slice(0, e) + "." + str.slice(e);
|
|
59770
|
-
}
|
|
59771
|
-
}
|
|
59772
|
-
str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
|
|
59773
|
-
}
|
|
59774
|
-
return x.s < 0 ? "-" + str : str;
|
|
59775
|
-
}
|
|
59776
|
-
function truncate(arr, len) {
|
|
59777
|
-
if (arr.length > len) {
|
|
59778
|
-
arr.length = len;
|
|
59779
|
-
return true;
|
|
59780
|
-
}
|
|
59781
|
-
}
|
|
59782
|
-
function abs(x) {
|
|
59783
|
-
return new this(x).abs();
|
|
59784
|
-
}
|
|
59785
|
-
function acos(x) {
|
|
59786
|
-
return new this(x).acos();
|
|
59787
|
-
}
|
|
59788
|
-
function acosh(x) {
|
|
59789
|
-
return new this(x).acosh();
|
|
59790
|
-
}
|
|
59791
|
-
function add(x, y) {
|
|
59792
|
-
return new this(x).plus(y);
|
|
59793
|
-
}
|
|
59794
|
-
function asin(x) {
|
|
59795
|
-
return new this(x).asin();
|
|
59796
|
-
}
|
|
59797
|
-
function asinh(x) {
|
|
59798
|
-
return new this(x).asinh();
|
|
59799
|
-
}
|
|
59800
|
-
function atan(x) {
|
|
59801
|
-
return new this(x).atan();
|
|
59802
|
-
}
|
|
59803
|
-
function atanh(x) {
|
|
59804
|
-
return new this(x).atanh();
|
|
59805
|
-
}
|
|
59806
|
-
function atan2(y, x) {
|
|
59807
|
-
y = new this(y);
|
|
59808
|
-
x = new this(x);
|
|
59809
|
-
var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
|
|
59810
|
-
if (!y.s || !x.s) {
|
|
59811
|
-
r = new this(NaN);
|
|
59812
|
-
} else if (!y.d && !x.d) {
|
|
59813
|
-
r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
|
|
59814
|
-
r.s = y.s;
|
|
59815
|
-
} else if (!x.d || y.isZero()) {
|
|
59816
|
-
r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
|
|
59817
|
-
r.s = y.s;
|
|
59818
|
-
} else if (!y.d || x.isZero()) {
|
|
59819
|
-
r = getPi(this, wpr, 1).times(0.5);
|
|
59820
|
-
r.s = y.s;
|
|
59821
|
-
} else if (x.s < 0) {
|
|
59822
|
-
this.precision = wpr;
|
|
59823
|
-
this.rounding = 1;
|
|
59824
|
-
r = this.atan(divide(y, x, wpr, 1));
|
|
59825
|
-
x = getPi(this, wpr, 1);
|
|
59826
|
-
this.precision = pr;
|
|
59827
|
-
this.rounding = rm;
|
|
59828
|
-
r = y.s < 0 ? r.minus(x) : r.plus(x);
|
|
59829
|
-
} else {
|
|
59830
|
-
r = this.atan(divide(y, x, wpr, 1));
|
|
59831
|
-
}
|
|
59832
|
-
return r;
|
|
59833
|
-
}
|
|
59834
|
-
function cbrt(x) {
|
|
59835
|
-
return new this(x).cbrt();
|
|
59836
|
-
}
|
|
59837
|
-
function ceil(x) {
|
|
59838
|
-
return finalise(x = new this(x), x.e + 1, 2);
|
|
59839
|
-
}
|
|
59840
|
-
function clamp(x, min2, max2) {
|
|
59841
|
-
return new this(x).clamp(min2, max2);
|
|
59842
|
-
}
|
|
59843
|
-
function config3(obj) {
|
|
59844
|
-
if (!obj || typeof obj !== "object") throw Error(decimalError + "Object expected");
|
|
59845
|
-
var i, p, v, useDefaults = obj.defaults === true, ps = [
|
|
59846
|
-
"precision",
|
|
59847
|
-
1,
|
|
59848
|
-
MAX_DIGITS,
|
|
59849
|
-
"rounding",
|
|
59850
|
-
0,
|
|
59851
|
-
8,
|
|
59852
|
-
"toExpNeg",
|
|
59853
|
-
-EXP_LIMIT,
|
|
59854
|
-
0,
|
|
59855
|
-
"toExpPos",
|
|
59856
|
-
0,
|
|
59857
|
-
EXP_LIMIT,
|
|
59858
|
-
"maxE",
|
|
59859
|
-
0,
|
|
59860
|
-
EXP_LIMIT,
|
|
59861
|
-
"minE",
|
|
59862
|
-
-EXP_LIMIT,
|
|
59863
|
-
0,
|
|
59864
|
-
"modulo",
|
|
59865
|
-
0,
|
|
59866
|
-
9
|
|
59867
|
-
];
|
|
59868
|
-
for (i = 0; i < ps.length; i += 3) {
|
|
59869
|
-
if (p = ps[i], useDefaults) this[p] = DEFAULTS[p];
|
|
59870
|
-
if ((v = obj[p]) !== void 0) {
|
|
59871
|
-
if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2]) this[p] = v;
|
|
59872
|
-
else throw Error(invalidArgument + p + ": " + v);
|
|
59873
|
-
}
|
|
59874
|
-
}
|
|
59875
|
-
if (p = "crypto", useDefaults) this[p] = DEFAULTS[p];
|
|
59876
|
-
if ((v = obj[p]) !== void 0) {
|
|
59877
|
-
if (v === true || v === false || v === 0 || v === 1) {
|
|
59878
|
-
if (v) {
|
|
59879
|
-
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
|
59880
|
-
this[p] = true;
|
|
59881
|
-
} else {
|
|
59882
|
-
throw Error(cryptoUnavailable);
|
|
59883
|
-
}
|
|
59884
|
-
} else {
|
|
59885
|
-
this[p] = false;
|
|
59886
|
-
}
|
|
59887
|
-
} else {
|
|
59888
|
-
throw Error(invalidArgument + p + ": " + v);
|
|
59889
|
-
}
|
|
59890
|
-
}
|
|
59891
|
-
return this;
|
|
59892
|
-
}
|
|
59893
|
-
function cos(x) {
|
|
59894
|
-
return new this(x).cos();
|
|
59895
|
-
}
|
|
59896
|
-
function cosh(x) {
|
|
59897
|
-
return new this(x).cosh();
|
|
59898
|
-
}
|
|
59899
|
-
function clone2(obj) {
|
|
59900
|
-
var i, p, ps;
|
|
59901
|
-
function Decimal2(v) {
|
|
59902
|
-
var e, i2, t, x = this;
|
|
59903
|
-
if (!(x instanceof Decimal2)) return new Decimal2(v);
|
|
59904
|
-
x.constructor = Decimal2;
|
|
59905
|
-
if (isDecimalInstance(v)) {
|
|
59906
|
-
x.s = v.s;
|
|
59907
|
-
if (external) {
|
|
59908
|
-
if (!v.d || v.e > Decimal2.maxE) {
|
|
59909
|
-
x.e = NaN;
|
|
59910
|
-
x.d = null;
|
|
59911
|
-
} else if (v.e < Decimal2.minE) {
|
|
59912
|
-
x.e = 0;
|
|
59913
|
-
x.d = [0];
|
|
59914
|
-
} else {
|
|
59915
|
-
x.e = v.e;
|
|
59916
|
-
x.d = v.d.slice();
|
|
59917
|
-
}
|
|
59918
|
-
} else {
|
|
59919
|
-
x.e = v.e;
|
|
59920
|
-
x.d = v.d ? v.d.slice() : v.d;
|
|
59921
|
-
}
|
|
59922
|
-
return;
|
|
59923
|
-
}
|
|
59924
|
-
t = typeof v;
|
|
59925
|
-
if (t === "number") {
|
|
59926
|
-
if (v === 0) {
|
|
59927
|
-
x.s = 1 / v < 0 ? -1 : 1;
|
|
59928
|
-
x.e = 0;
|
|
59929
|
-
x.d = [0];
|
|
59930
|
-
return;
|
|
59931
|
-
}
|
|
59932
|
-
if (v < 0) {
|
|
59933
|
-
v = -v;
|
|
59934
|
-
x.s = -1;
|
|
59935
|
-
} else {
|
|
59936
|
-
x.s = 1;
|
|
59937
|
-
}
|
|
59938
|
-
if (v === ~~v && v < 1e7) {
|
|
59939
|
-
for (e = 0, i2 = v; i2 >= 10; i2 /= 10) e++;
|
|
59940
|
-
if (external) {
|
|
59941
|
-
if (e > Decimal2.maxE) {
|
|
59942
|
-
x.e = NaN;
|
|
59943
|
-
x.d = null;
|
|
59944
|
-
} else if (e < Decimal2.minE) {
|
|
59945
|
-
x.e = 0;
|
|
59946
|
-
x.d = [0];
|
|
59947
|
-
} else {
|
|
59948
|
-
x.e = e;
|
|
59949
|
-
x.d = [v];
|
|
59950
|
-
}
|
|
59951
|
-
} else {
|
|
59952
|
-
x.e = e;
|
|
59953
|
-
x.d = [v];
|
|
59954
|
-
}
|
|
59955
|
-
return;
|
|
59956
|
-
}
|
|
59957
|
-
if (v * 0 !== 0) {
|
|
59958
|
-
if (!v) x.s = NaN;
|
|
59959
|
-
x.e = NaN;
|
|
59960
|
-
x.d = null;
|
|
59961
|
-
return;
|
|
59962
|
-
}
|
|
59963
|
-
return parseDecimal(x, v.toString());
|
|
59964
|
-
}
|
|
59965
|
-
if (t === "string") {
|
|
59966
|
-
if ((i2 = v.charCodeAt(0)) === 45) {
|
|
59967
|
-
v = v.slice(1);
|
|
59968
|
-
x.s = -1;
|
|
59969
|
-
} else {
|
|
59970
|
-
if (i2 === 43) v = v.slice(1);
|
|
59971
|
-
x.s = 1;
|
|
59972
|
-
}
|
|
59973
|
-
return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
|
|
59974
|
-
}
|
|
59975
|
-
if (t === "bigint") {
|
|
59976
|
-
if (v < 0) {
|
|
59977
|
-
v = -v;
|
|
59978
|
-
x.s = -1;
|
|
59979
|
-
} else {
|
|
59980
|
-
x.s = 1;
|
|
59981
|
-
}
|
|
59982
|
-
return parseDecimal(x, v.toString());
|
|
59983
|
-
}
|
|
59984
|
-
throw Error(invalidArgument + v);
|
|
59985
|
-
}
|
|
59986
|
-
Decimal2.prototype = P;
|
|
59987
|
-
Decimal2.ROUND_UP = 0;
|
|
59988
|
-
Decimal2.ROUND_DOWN = 1;
|
|
59989
|
-
Decimal2.ROUND_CEIL = 2;
|
|
59990
|
-
Decimal2.ROUND_FLOOR = 3;
|
|
59991
|
-
Decimal2.ROUND_HALF_UP = 4;
|
|
59992
|
-
Decimal2.ROUND_HALF_DOWN = 5;
|
|
59993
|
-
Decimal2.ROUND_HALF_EVEN = 6;
|
|
59994
|
-
Decimal2.ROUND_HALF_CEIL = 7;
|
|
59995
|
-
Decimal2.ROUND_HALF_FLOOR = 8;
|
|
59996
|
-
Decimal2.EUCLID = 9;
|
|
59997
|
-
Decimal2.config = Decimal2.set = config3;
|
|
59998
|
-
Decimal2.clone = clone2;
|
|
59999
|
-
Decimal2.isDecimal = isDecimalInstance;
|
|
60000
|
-
Decimal2.abs = abs;
|
|
60001
|
-
Decimal2.acos = acos;
|
|
60002
|
-
Decimal2.acosh = acosh;
|
|
60003
|
-
Decimal2.add = add;
|
|
60004
|
-
Decimal2.asin = asin;
|
|
60005
|
-
Decimal2.asinh = asinh;
|
|
60006
|
-
Decimal2.atan = atan;
|
|
60007
|
-
Decimal2.atanh = atanh;
|
|
60008
|
-
Decimal2.atan2 = atan2;
|
|
60009
|
-
Decimal2.cbrt = cbrt;
|
|
60010
|
-
Decimal2.ceil = ceil;
|
|
60011
|
-
Decimal2.clamp = clamp;
|
|
60012
|
-
Decimal2.cos = cos;
|
|
60013
|
-
Decimal2.cosh = cosh;
|
|
60014
|
-
Decimal2.div = div;
|
|
60015
|
-
Decimal2.exp = exp;
|
|
60016
|
-
Decimal2.floor = floor;
|
|
60017
|
-
Decimal2.hypot = hypot;
|
|
60018
|
-
Decimal2.ln = ln;
|
|
60019
|
-
Decimal2.log = log;
|
|
60020
|
-
Decimal2.log10 = log10;
|
|
60021
|
-
Decimal2.log2 = log2;
|
|
60022
|
-
Decimal2.max = max;
|
|
60023
|
-
Decimal2.min = min;
|
|
60024
|
-
Decimal2.mod = mod;
|
|
60025
|
-
Decimal2.mul = mul;
|
|
60026
|
-
Decimal2.pow = pow;
|
|
60027
|
-
Decimal2.random = random;
|
|
60028
|
-
Decimal2.round = round;
|
|
60029
|
-
Decimal2.sign = sign;
|
|
60030
|
-
Decimal2.sin = sin;
|
|
60031
|
-
Decimal2.sinh = sinh;
|
|
60032
|
-
Decimal2.sqrt = sqrt;
|
|
60033
|
-
Decimal2.sub = sub;
|
|
60034
|
-
Decimal2.sum = sum;
|
|
60035
|
-
Decimal2.tan = tan;
|
|
60036
|
-
Decimal2.tanh = tanh;
|
|
60037
|
-
Decimal2.trunc = trunc;
|
|
60038
|
-
if (obj === void 0) obj = {};
|
|
60039
|
-
if (obj) {
|
|
60040
|
-
if (obj.defaults !== true) {
|
|
60041
|
-
ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
|
|
60042
|
-
for (i = 0; i < ps.length; ) if (!obj.hasOwnProperty(p = ps[i++])) obj[p] = this[p];
|
|
60043
|
-
}
|
|
60044
|
-
}
|
|
60045
|
-
Decimal2.config(obj);
|
|
60046
|
-
return Decimal2;
|
|
60047
|
-
}
|
|
60048
|
-
function div(x, y) {
|
|
60049
|
-
return new this(x).div(y);
|
|
60050
|
-
}
|
|
60051
|
-
function exp(x) {
|
|
60052
|
-
return new this(x).exp();
|
|
60053
|
-
}
|
|
60054
|
-
function floor(x) {
|
|
60055
|
-
return finalise(x = new this(x), x.e + 1, 3);
|
|
60056
|
-
}
|
|
60057
|
-
function hypot() {
|
|
60058
|
-
var i, n, t = new this(0);
|
|
60059
|
-
external = false;
|
|
60060
|
-
for (i = 0; i < arguments.length; ) {
|
|
60061
|
-
n = new this(arguments[i++]);
|
|
60062
|
-
if (!n.d) {
|
|
60063
|
-
if (n.s) {
|
|
60064
|
-
external = true;
|
|
60065
|
-
return new this(1 / 0);
|
|
60066
|
-
}
|
|
60067
|
-
t = n;
|
|
60068
|
-
} else if (t.d) {
|
|
60069
|
-
t = t.plus(n.times(n));
|
|
60070
|
-
}
|
|
60071
|
-
}
|
|
60072
|
-
external = true;
|
|
60073
|
-
return t.sqrt();
|
|
60074
|
-
}
|
|
60075
|
-
function isDecimalInstance(obj) {
|
|
60076
|
-
return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
|
|
60077
|
-
}
|
|
60078
|
-
function ln(x) {
|
|
60079
|
-
return new this(x).ln();
|
|
60080
|
-
}
|
|
60081
|
-
function log(x, y) {
|
|
60082
|
-
return new this(x).log(y);
|
|
60083
|
-
}
|
|
60084
|
-
function log2(x) {
|
|
60085
|
-
return new this(x).log(2);
|
|
60086
|
-
}
|
|
60087
|
-
function log10(x) {
|
|
60088
|
-
return new this(x).log(10);
|
|
60089
|
-
}
|
|
60090
|
-
function max() {
|
|
60091
|
-
return maxOrMin(this, arguments, -1);
|
|
60092
|
-
}
|
|
60093
|
-
function min() {
|
|
60094
|
-
return maxOrMin(this, arguments, 1);
|
|
60095
|
-
}
|
|
60096
|
-
function mod(x, y) {
|
|
60097
|
-
return new this(x).mod(y);
|
|
60098
|
-
}
|
|
60099
|
-
function mul(x, y) {
|
|
60100
|
-
return new this(x).mul(y);
|
|
60101
|
-
}
|
|
60102
|
-
function pow(x, y) {
|
|
60103
|
-
return new this(x).pow(y);
|
|
60104
|
-
}
|
|
60105
|
-
function random(sd) {
|
|
60106
|
-
var d, e, k, n, i = 0, r = new this(1), rd = [];
|
|
60107
|
-
if (sd === void 0) sd = this.precision;
|
|
60108
|
-
else checkInt32(sd, 1, MAX_DIGITS);
|
|
60109
|
-
k = Math.ceil(sd / LOG_BASE);
|
|
60110
|
-
if (!this.crypto) {
|
|
60111
|
-
for (; i < k; ) rd[i++] = Math.random() * 1e7 | 0;
|
|
60112
|
-
} else if (crypto.getRandomValues) {
|
|
60113
|
-
d = crypto.getRandomValues(new Uint32Array(k));
|
|
60114
|
-
for (; i < k; ) {
|
|
60115
|
-
n = d[i];
|
|
60116
|
-
if (n >= 429e7) {
|
|
60117
|
-
d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
|
|
60118
|
-
} else {
|
|
60119
|
-
rd[i++] = n % 1e7;
|
|
60120
|
-
}
|
|
60121
|
-
}
|
|
60122
|
-
} else if (crypto.randomBytes) {
|
|
60123
|
-
d = crypto.randomBytes(k *= 4);
|
|
60124
|
-
for (; i < k; ) {
|
|
60125
|
-
n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
|
|
60126
|
-
if (n >= 214e7) {
|
|
60127
|
-
crypto.randomBytes(4).copy(d, i);
|
|
60128
|
-
} else {
|
|
60129
|
-
rd.push(n % 1e7);
|
|
60130
|
-
i += 4;
|
|
60131
|
-
}
|
|
60132
|
-
}
|
|
60133
|
-
i = k / 4;
|
|
60134
|
-
} else {
|
|
60135
|
-
throw Error(cryptoUnavailable);
|
|
60136
|
-
}
|
|
60137
|
-
k = rd[--i];
|
|
60138
|
-
sd %= LOG_BASE;
|
|
60139
|
-
if (k && sd) {
|
|
60140
|
-
n = mathpow(10, LOG_BASE - sd);
|
|
60141
|
-
rd[i] = (k / n | 0) * n;
|
|
60142
|
-
}
|
|
60143
|
-
for (; rd[i] === 0; i--) rd.pop();
|
|
60144
|
-
if (i < 0) {
|
|
60145
|
-
e = 0;
|
|
60146
|
-
rd = [0];
|
|
60147
|
-
} else {
|
|
60148
|
-
e = -1;
|
|
60149
|
-
for (; rd[0] === 0; e -= LOG_BASE) rd.shift();
|
|
60150
|
-
for (k = 1, n = rd[0]; n >= 10; n /= 10) k++;
|
|
60151
|
-
if (k < LOG_BASE) e -= LOG_BASE - k;
|
|
60152
|
-
}
|
|
60153
|
-
r.e = e;
|
|
60154
|
-
r.d = rd;
|
|
60155
|
-
return r;
|
|
60156
|
-
}
|
|
60157
|
-
function round(x) {
|
|
60158
|
-
return finalise(x = new this(x), x.e + 1, this.rounding);
|
|
60159
|
-
}
|
|
60160
|
-
function sign(x) {
|
|
60161
|
-
x = new this(x);
|
|
60162
|
-
return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
|
|
60163
|
-
}
|
|
60164
|
-
function sin(x) {
|
|
60165
|
-
return new this(x).sin();
|
|
60166
|
-
}
|
|
60167
|
-
function sinh(x) {
|
|
60168
|
-
return new this(x).sinh();
|
|
60169
|
-
}
|
|
60170
|
-
function sqrt(x) {
|
|
60171
|
-
return new this(x).sqrt();
|
|
60172
|
-
}
|
|
60173
|
-
function sub(x, y) {
|
|
60174
|
-
return new this(x).sub(y);
|
|
60175
|
-
}
|
|
60176
|
-
function sum() {
|
|
60177
|
-
var i = 0, args = arguments, x = new this(args[i]);
|
|
60178
|
-
external = false;
|
|
60179
|
-
for (; x.s && ++i < args.length; ) x = x.plus(args[i]);
|
|
60180
|
-
external = true;
|
|
60181
|
-
return finalise(x, this.precision, this.rounding);
|
|
60182
|
-
}
|
|
60183
|
-
function tan(x) {
|
|
60184
|
-
return new this(x).tan();
|
|
60185
|
-
}
|
|
60186
|
-
function tanh(x) {
|
|
60187
|
-
return new this(x).tanh();
|
|
60188
|
-
}
|
|
60189
|
-
function trunc(x) {
|
|
60190
|
-
return finalise(x = new this(x), x.e + 1, 1);
|
|
60191
|
-
}
|
|
60192
|
-
P[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = P.toString;
|
|
60193
|
-
P[Symbol.toStringTag] = "Decimal";
|
|
60194
|
-
var Decimal = P.constructor = clone2(DEFAULTS);
|
|
60195
|
-
LN10 = new Decimal(LN10);
|
|
60196
|
-
PI = new Decimal(PI);
|
|
60197
|
-
|
|
60198
58022
|
// ../hyperline-lib/build/utils/config/countries.js
|
|
60199
58023
|
var countriesAndCurrencies = (
|
|
60200
58024
|
// 20221115164054
|
|
@@ -62224,8 +60048,2184 @@ var countriesAndCurrencies = (
|
|
|
62224
60048
|
capital: "Harare",
|
|
62225
60049
|
continentName: "Africa"
|
|
62226
60050
|
}
|
|
62227
|
-
]
|
|
62228
|
-
);
|
|
60051
|
+
]
|
|
60052
|
+
);
|
|
60053
|
+
|
|
60054
|
+
// ../../node_modules/decimal.js/decimal.mjs
|
|
60055
|
+
var EXP_LIMIT = 9e15;
|
|
60056
|
+
var MAX_DIGITS = 1e9;
|
|
60057
|
+
var NUMERALS = "0123456789abcdef";
|
|
60058
|
+
var LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";
|
|
60059
|
+
var PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789";
|
|
60060
|
+
var DEFAULTS = {
|
|
60061
|
+
// These values must be integers within the stated ranges (inclusive).
|
|
60062
|
+
// Most of these values can be changed at run-time using the `Decimal.config` method.
|
|
60063
|
+
// The maximum number of significant digits of the result of a calculation or base conversion.
|
|
60064
|
+
// E.g. `Decimal.config({ precision: 20 });`
|
|
60065
|
+
precision: 20,
|
|
60066
|
+
// 1 to MAX_DIGITS
|
|
60067
|
+
// The rounding mode used when rounding to `precision`.
|
|
60068
|
+
//
|
|
60069
|
+
// ROUND_UP 0 Away from zero.
|
|
60070
|
+
// ROUND_DOWN 1 Towards zero.
|
|
60071
|
+
// ROUND_CEIL 2 Towards +Infinity.
|
|
60072
|
+
// ROUND_FLOOR 3 Towards -Infinity.
|
|
60073
|
+
// ROUND_HALF_UP 4 Towards nearest neighbour. If equidistant, up.
|
|
60074
|
+
// ROUND_HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
|
|
60075
|
+
// ROUND_HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
|
|
60076
|
+
// ROUND_HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
|
|
60077
|
+
// ROUND_HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
|
|
60078
|
+
//
|
|
60079
|
+
// E.g.
|
|
60080
|
+
// `Decimal.rounding = 4;`
|
|
60081
|
+
// `Decimal.rounding = Decimal.ROUND_HALF_UP;`
|
|
60082
|
+
rounding: 4,
|
|
60083
|
+
// 0 to 8
|
|
60084
|
+
// The modulo mode used when calculating the modulus: a mod n.
|
|
60085
|
+
// The quotient (q = a / n) is calculated according to the corresponding rounding mode.
|
|
60086
|
+
// The remainder (r) is calculated as: r = a - n * q.
|
|
60087
|
+
//
|
|
60088
|
+
// UP 0 The remainder is positive if the dividend is negative, else is negative.
|
|
60089
|
+
// DOWN 1 The remainder has the same sign as the dividend (JavaScript %).
|
|
60090
|
+
// FLOOR 3 The remainder has the same sign as the divisor (Python %).
|
|
60091
|
+
// HALF_EVEN 6 The IEEE 754 remainder function.
|
|
60092
|
+
// EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)). Always positive.
|
|
60093
|
+
//
|
|
60094
|
+
// Truncated division (1), floored division (3), the IEEE 754 remainder (6), and Euclidian
|
|
60095
|
+
// division (9) are commonly used for the modulus operation. The other rounding modes can also
|
|
60096
|
+
// be used, but they may not give useful results.
|
|
60097
|
+
modulo: 1,
|
|
60098
|
+
// 0 to 9
|
|
60099
|
+
// The exponent value at and beneath which `toString` returns exponential notation.
|
|
60100
|
+
// JavaScript numbers: -7
|
|
60101
|
+
toExpNeg: -7,
|
|
60102
|
+
// 0 to -EXP_LIMIT
|
|
60103
|
+
// The exponent value at and above which `toString` returns exponential notation.
|
|
60104
|
+
// JavaScript numbers: 21
|
|
60105
|
+
toExpPos: 21,
|
|
60106
|
+
// 0 to EXP_LIMIT
|
|
60107
|
+
// The minimum exponent value, beneath which underflow to zero occurs.
|
|
60108
|
+
// JavaScript numbers: -324 (5e-324)
|
|
60109
|
+
minE: -EXP_LIMIT,
|
|
60110
|
+
// -1 to -EXP_LIMIT
|
|
60111
|
+
// The maximum exponent value, above which overflow to Infinity occurs.
|
|
60112
|
+
// JavaScript numbers: 308 (1.7976931348623157e+308)
|
|
60113
|
+
maxE: EXP_LIMIT,
|
|
60114
|
+
// 1 to EXP_LIMIT
|
|
60115
|
+
// Whether to use cryptographically-secure random number generation, if available.
|
|
60116
|
+
crypto: false
|
|
60117
|
+
// true/false
|
|
60118
|
+
};
|
|
60119
|
+
var inexact;
|
|
60120
|
+
var quadrant;
|
|
60121
|
+
var external = true;
|
|
60122
|
+
var decimalError = "[DecimalError] ";
|
|
60123
|
+
var invalidArgument = decimalError + "Invalid argument: ";
|
|
60124
|
+
var precisionLimitExceeded = decimalError + "Precision limit exceeded";
|
|
60125
|
+
var cryptoUnavailable = decimalError + "crypto unavailable";
|
|
60126
|
+
var tag = "[object Decimal]";
|
|
60127
|
+
var mathfloor = Math.floor;
|
|
60128
|
+
var mathpow = Math.pow;
|
|
60129
|
+
var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
|
|
60130
|
+
var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
|
|
60131
|
+
var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
|
|
60132
|
+
var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
|
|
60133
|
+
var BASE = 1e7;
|
|
60134
|
+
var LOG_BASE = 7;
|
|
60135
|
+
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
60136
|
+
var LN10_PRECISION = LN10.length - 1;
|
|
60137
|
+
var PI_PRECISION = PI.length - 1;
|
|
60138
|
+
var P = { toStringTag: tag };
|
|
60139
|
+
P.absoluteValue = P.abs = function() {
|
|
60140
|
+
var x = new this.constructor(this);
|
|
60141
|
+
if (x.s < 0) x.s = 1;
|
|
60142
|
+
return finalise(x);
|
|
60143
|
+
};
|
|
60144
|
+
P.ceil = function() {
|
|
60145
|
+
return finalise(new this.constructor(this), this.e + 1, 2);
|
|
60146
|
+
};
|
|
60147
|
+
P.clampedTo = P.clamp = function(min2, max2) {
|
|
60148
|
+
var k, x = this, Ctor = x.constructor;
|
|
60149
|
+
min2 = new Ctor(min2);
|
|
60150
|
+
max2 = new Ctor(max2);
|
|
60151
|
+
if (!min2.s || !max2.s) return new Ctor(NaN);
|
|
60152
|
+
if (min2.gt(max2)) throw Error(invalidArgument + max2);
|
|
60153
|
+
k = x.cmp(min2);
|
|
60154
|
+
return k < 0 ? min2 : x.cmp(max2) > 0 ? max2 : new Ctor(x);
|
|
60155
|
+
};
|
|
60156
|
+
P.comparedTo = P.cmp = function(y) {
|
|
60157
|
+
var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
|
|
60158
|
+
if (!xd || !yd) {
|
|
60159
|
+
return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
|
|
60160
|
+
}
|
|
60161
|
+
if (!xd[0] || !yd[0]) return xd[0] ? xs : yd[0] ? -ys : 0;
|
|
60162
|
+
if (xs !== ys) return xs;
|
|
60163
|
+
if (x.e !== y.e) return x.e > y.e ^ xs < 0 ? 1 : -1;
|
|
60164
|
+
xdL = xd.length;
|
|
60165
|
+
ydL = yd.length;
|
|
60166
|
+
for (i = 0, j = xdL < ydL ? xdL : ydL; i < j; ++i) {
|
|
60167
|
+
if (xd[i] !== yd[i]) return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
|
|
60168
|
+
}
|
|
60169
|
+
return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
|
|
60170
|
+
};
|
|
60171
|
+
P.cosine = P.cos = function() {
|
|
60172
|
+
var pr, rm, x = this, Ctor = x.constructor;
|
|
60173
|
+
if (!x.d) return new Ctor(NaN);
|
|
60174
|
+
if (!x.d[0]) return new Ctor(1);
|
|
60175
|
+
pr = Ctor.precision;
|
|
60176
|
+
rm = Ctor.rounding;
|
|
60177
|
+
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
|
60178
|
+
Ctor.rounding = 1;
|
|
60179
|
+
x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
|
|
60180
|
+
Ctor.precision = pr;
|
|
60181
|
+
Ctor.rounding = rm;
|
|
60182
|
+
return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
|
|
60183
|
+
};
|
|
60184
|
+
P.cubeRoot = P.cbrt = function() {
|
|
60185
|
+
var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
|
|
60186
|
+
if (!x.isFinite() || x.isZero()) return new Ctor(x);
|
|
60187
|
+
external = false;
|
|
60188
|
+
s = x.s * mathpow(x.s * x, 1 / 3);
|
|
60189
|
+
if (!s || Math.abs(s) == 1 / 0) {
|
|
60190
|
+
n = digitsToString(x.d);
|
|
60191
|
+
e = x.e;
|
|
60192
|
+
if (s = (e - n.length + 1) % 3) n += s == 1 || s == -2 ? "0" : "00";
|
|
60193
|
+
s = mathpow(n, 1 / 3);
|
|
60194
|
+
e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
|
|
60195
|
+
if (s == 1 / 0) {
|
|
60196
|
+
n = "5e" + e;
|
|
60197
|
+
} else {
|
|
60198
|
+
n = s.toExponential();
|
|
60199
|
+
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
60200
|
+
}
|
|
60201
|
+
r = new Ctor(n);
|
|
60202
|
+
r.s = x.s;
|
|
60203
|
+
} else {
|
|
60204
|
+
r = new Ctor(s.toString());
|
|
60205
|
+
}
|
|
60206
|
+
sd = (e = Ctor.precision) + 3;
|
|
60207
|
+
for (; ; ) {
|
|
60208
|
+
t = r;
|
|
60209
|
+
t3 = t.times(t).times(t);
|
|
60210
|
+
t3plusx = t3.plus(x);
|
|
60211
|
+
r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
|
|
60212
|
+
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
60213
|
+
n = n.slice(sd - 3, sd + 1);
|
|
60214
|
+
if (n == "9999" || !rep && n == "4999") {
|
|
60215
|
+
if (!rep) {
|
|
60216
|
+
finalise(t, e + 1, 0);
|
|
60217
|
+
if (t.times(t).times(t).eq(x)) {
|
|
60218
|
+
r = t;
|
|
60219
|
+
break;
|
|
60220
|
+
}
|
|
60221
|
+
}
|
|
60222
|
+
sd += 4;
|
|
60223
|
+
rep = 1;
|
|
60224
|
+
} else {
|
|
60225
|
+
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
60226
|
+
finalise(r, e + 1, 1);
|
|
60227
|
+
m = !r.times(r).times(r).eq(x);
|
|
60228
|
+
}
|
|
60229
|
+
break;
|
|
60230
|
+
}
|
|
60231
|
+
}
|
|
60232
|
+
}
|
|
60233
|
+
external = true;
|
|
60234
|
+
return finalise(r, e, Ctor.rounding, m);
|
|
60235
|
+
};
|
|
60236
|
+
P.decimalPlaces = P.dp = function() {
|
|
60237
|
+
var w, d = this.d, n = NaN;
|
|
60238
|
+
if (d) {
|
|
60239
|
+
w = d.length - 1;
|
|
60240
|
+
n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
60241
|
+
w = d[w];
|
|
60242
|
+
if (w) for (; w % 10 == 0; w /= 10) n--;
|
|
60243
|
+
if (n < 0) n = 0;
|
|
60244
|
+
}
|
|
60245
|
+
return n;
|
|
60246
|
+
};
|
|
60247
|
+
P.dividedBy = P.div = function(y) {
|
|
60248
|
+
return divide(this, new this.constructor(y));
|
|
60249
|
+
};
|
|
60250
|
+
P.dividedToIntegerBy = P.divToInt = function(y) {
|
|
60251
|
+
var x = this, Ctor = x.constructor;
|
|
60252
|
+
return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
|
|
60253
|
+
};
|
|
60254
|
+
P.equals = P.eq = function(y) {
|
|
60255
|
+
return this.cmp(y) === 0;
|
|
60256
|
+
};
|
|
60257
|
+
P.floor = function() {
|
|
60258
|
+
return finalise(new this.constructor(this), this.e + 1, 3);
|
|
60259
|
+
};
|
|
60260
|
+
P.greaterThan = P.gt = function(y) {
|
|
60261
|
+
return this.cmp(y) > 0;
|
|
60262
|
+
};
|
|
60263
|
+
P.greaterThanOrEqualTo = P.gte = function(y) {
|
|
60264
|
+
var k = this.cmp(y);
|
|
60265
|
+
return k == 1 || k === 0;
|
|
60266
|
+
};
|
|
60267
|
+
P.hyperbolicCosine = P.cosh = function() {
|
|
60268
|
+
var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
|
|
60269
|
+
if (!x.isFinite()) return new Ctor(x.s ? 1 / 0 : NaN);
|
|
60270
|
+
if (x.isZero()) return one;
|
|
60271
|
+
pr = Ctor.precision;
|
|
60272
|
+
rm = Ctor.rounding;
|
|
60273
|
+
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
|
60274
|
+
Ctor.rounding = 1;
|
|
60275
|
+
len = x.d.length;
|
|
60276
|
+
if (len < 32) {
|
|
60277
|
+
k = Math.ceil(len / 3);
|
|
60278
|
+
n = (1 / tinyPow(4, k)).toString();
|
|
60279
|
+
} else {
|
|
60280
|
+
k = 16;
|
|
60281
|
+
n = "2.3283064365386962890625e-10";
|
|
60282
|
+
}
|
|
60283
|
+
x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
|
|
60284
|
+
var cosh2_x, i = k, d8 = new Ctor(8);
|
|
60285
|
+
for (; i--; ) {
|
|
60286
|
+
cosh2_x = x.times(x);
|
|
60287
|
+
x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
|
|
60288
|
+
}
|
|
60289
|
+
return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
|
|
60290
|
+
};
|
|
60291
|
+
P.hyperbolicSine = P.sinh = function() {
|
|
60292
|
+
var k, pr, rm, len, x = this, Ctor = x.constructor;
|
|
60293
|
+
if (!x.isFinite() || x.isZero()) return new Ctor(x);
|
|
60294
|
+
pr = Ctor.precision;
|
|
60295
|
+
rm = Ctor.rounding;
|
|
60296
|
+
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
|
60297
|
+
Ctor.rounding = 1;
|
|
60298
|
+
len = x.d.length;
|
|
60299
|
+
if (len < 3) {
|
|
60300
|
+
x = taylorSeries(Ctor, 2, x, x, true);
|
|
60301
|
+
} else {
|
|
60302
|
+
k = 1.4 * Math.sqrt(len);
|
|
60303
|
+
k = k > 16 ? 16 : k | 0;
|
|
60304
|
+
x = x.times(1 / tinyPow(5, k));
|
|
60305
|
+
x = taylorSeries(Ctor, 2, x, x, true);
|
|
60306
|
+
var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
60307
|
+
for (; k--; ) {
|
|
60308
|
+
sinh2_x = x.times(x);
|
|
60309
|
+
x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
|
|
60310
|
+
}
|
|
60311
|
+
}
|
|
60312
|
+
Ctor.precision = pr;
|
|
60313
|
+
Ctor.rounding = rm;
|
|
60314
|
+
return finalise(x, pr, rm, true);
|
|
60315
|
+
};
|
|
60316
|
+
P.hyperbolicTangent = P.tanh = function() {
|
|
60317
|
+
var pr, rm, x = this, Ctor = x.constructor;
|
|
60318
|
+
if (!x.isFinite()) return new Ctor(x.s);
|
|
60319
|
+
if (x.isZero()) return new Ctor(x);
|
|
60320
|
+
pr = Ctor.precision;
|
|
60321
|
+
rm = Ctor.rounding;
|
|
60322
|
+
Ctor.precision = pr + 7;
|
|
60323
|
+
Ctor.rounding = 1;
|
|
60324
|
+
return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
|
|
60325
|
+
};
|
|
60326
|
+
P.inverseCosine = P.acos = function() {
|
|
60327
|
+
var x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
|
|
60328
|
+
if (k !== -1) {
|
|
60329
|
+
return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
|
|
60330
|
+
}
|
|
60331
|
+
if (x.isZero()) return getPi(Ctor, pr + 4, rm).times(0.5);
|
|
60332
|
+
Ctor.precision = pr + 6;
|
|
60333
|
+
Ctor.rounding = 1;
|
|
60334
|
+
x = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
|
|
60335
|
+
Ctor.precision = pr;
|
|
60336
|
+
Ctor.rounding = rm;
|
|
60337
|
+
return x.times(2);
|
|
60338
|
+
};
|
|
60339
|
+
P.inverseHyperbolicCosine = P.acosh = function() {
|
|
60340
|
+
var pr, rm, x = this, Ctor = x.constructor;
|
|
60341
|
+
if (x.lte(1)) return new Ctor(x.eq(1) ? 0 : NaN);
|
|
60342
|
+
if (!x.isFinite()) return new Ctor(x);
|
|
60343
|
+
pr = Ctor.precision;
|
|
60344
|
+
rm = Ctor.rounding;
|
|
60345
|
+
Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
|
|
60346
|
+
Ctor.rounding = 1;
|
|
60347
|
+
external = false;
|
|
60348
|
+
x = x.times(x).minus(1).sqrt().plus(x);
|
|
60349
|
+
external = true;
|
|
60350
|
+
Ctor.precision = pr;
|
|
60351
|
+
Ctor.rounding = rm;
|
|
60352
|
+
return x.ln();
|
|
60353
|
+
};
|
|
60354
|
+
P.inverseHyperbolicSine = P.asinh = function() {
|
|
60355
|
+
var pr, rm, x = this, Ctor = x.constructor;
|
|
60356
|
+
if (!x.isFinite() || x.isZero()) return new Ctor(x);
|
|
60357
|
+
pr = Ctor.precision;
|
|
60358
|
+
rm = Ctor.rounding;
|
|
60359
|
+
Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
|
|
60360
|
+
Ctor.rounding = 1;
|
|
60361
|
+
external = false;
|
|
60362
|
+
x = x.times(x).plus(1).sqrt().plus(x);
|
|
60363
|
+
external = true;
|
|
60364
|
+
Ctor.precision = pr;
|
|
60365
|
+
Ctor.rounding = rm;
|
|
60366
|
+
return x.ln();
|
|
60367
|
+
};
|
|
60368
|
+
P.inverseHyperbolicTangent = P.atanh = function() {
|
|
60369
|
+
var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
|
|
60370
|
+
if (!x.isFinite()) return new Ctor(NaN);
|
|
60371
|
+
if (x.e >= 0) return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
|
|
60372
|
+
pr = Ctor.precision;
|
|
60373
|
+
rm = Ctor.rounding;
|
|
60374
|
+
xsd = x.sd();
|
|
60375
|
+
if (Math.max(xsd, pr) < 2 * -x.e - 1) return finalise(new Ctor(x), pr, rm, true);
|
|
60376
|
+
Ctor.precision = wpr = xsd - x.e;
|
|
60377
|
+
x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
|
|
60378
|
+
Ctor.precision = pr + 4;
|
|
60379
|
+
Ctor.rounding = 1;
|
|
60380
|
+
x = x.ln();
|
|
60381
|
+
Ctor.precision = pr;
|
|
60382
|
+
Ctor.rounding = rm;
|
|
60383
|
+
return x.times(0.5);
|
|
60384
|
+
};
|
|
60385
|
+
P.inverseSine = P.asin = function() {
|
|
60386
|
+
var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
|
|
60387
|
+
if (x.isZero()) return new Ctor(x);
|
|
60388
|
+
k = x.abs().cmp(1);
|
|
60389
|
+
pr = Ctor.precision;
|
|
60390
|
+
rm = Ctor.rounding;
|
|
60391
|
+
if (k !== -1) {
|
|
60392
|
+
if (k === 0) {
|
|
60393
|
+
halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
60394
|
+
halfPi.s = x.s;
|
|
60395
|
+
return halfPi;
|
|
60396
|
+
}
|
|
60397
|
+
return new Ctor(NaN);
|
|
60398
|
+
}
|
|
60399
|
+
Ctor.precision = pr + 6;
|
|
60400
|
+
Ctor.rounding = 1;
|
|
60401
|
+
x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
|
|
60402
|
+
Ctor.precision = pr;
|
|
60403
|
+
Ctor.rounding = rm;
|
|
60404
|
+
return x.times(2);
|
|
60405
|
+
};
|
|
60406
|
+
P.inverseTangent = P.atan = function() {
|
|
60407
|
+
var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
|
|
60408
|
+
if (!x.isFinite()) {
|
|
60409
|
+
if (!x.s) return new Ctor(NaN);
|
|
60410
|
+
if (pr + 4 <= PI_PRECISION) {
|
|
60411
|
+
r = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
60412
|
+
r.s = x.s;
|
|
60413
|
+
return r;
|
|
60414
|
+
}
|
|
60415
|
+
} else if (x.isZero()) {
|
|
60416
|
+
return new Ctor(x);
|
|
60417
|
+
} else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
|
|
60418
|
+
r = getPi(Ctor, pr + 4, rm).times(0.25);
|
|
60419
|
+
r.s = x.s;
|
|
60420
|
+
return r;
|
|
60421
|
+
}
|
|
60422
|
+
Ctor.precision = wpr = pr + 10;
|
|
60423
|
+
Ctor.rounding = 1;
|
|
60424
|
+
k = Math.min(28, wpr / LOG_BASE + 2 | 0);
|
|
60425
|
+
for (i = k; i; --i) x = x.div(x.times(x).plus(1).sqrt().plus(1));
|
|
60426
|
+
external = false;
|
|
60427
|
+
j = Math.ceil(wpr / LOG_BASE);
|
|
60428
|
+
n = 1;
|
|
60429
|
+
x2 = x.times(x);
|
|
60430
|
+
r = new Ctor(x);
|
|
60431
|
+
px = x;
|
|
60432
|
+
for (; i !== -1; ) {
|
|
60433
|
+
px = px.times(x2);
|
|
60434
|
+
t = r.minus(px.div(n += 2));
|
|
60435
|
+
px = px.times(x2);
|
|
60436
|
+
r = t.plus(px.div(n += 2));
|
|
60437
|
+
if (r.d[j] !== void 0) for (i = j; r.d[i] === t.d[i] && i--; ) ;
|
|
60438
|
+
}
|
|
60439
|
+
if (k) r = r.times(2 << k - 1);
|
|
60440
|
+
external = true;
|
|
60441
|
+
return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
|
|
60442
|
+
};
|
|
60443
|
+
P.isFinite = function() {
|
|
60444
|
+
return !!this.d;
|
|
60445
|
+
};
|
|
60446
|
+
P.isInteger = P.isInt = function() {
|
|
60447
|
+
return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
|
|
60448
|
+
};
|
|
60449
|
+
P.isNaN = function() {
|
|
60450
|
+
return !this.s;
|
|
60451
|
+
};
|
|
60452
|
+
P.isNegative = P.isNeg = function() {
|
|
60453
|
+
return this.s < 0;
|
|
60454
|
+
};
|
|
60455
|
+
P.isPositive = P.isPos = function() {
|
|
60456
|
+
return this.s > 0;
|
|
60457
|
+
};
|
|
60458
|
+
P.isZero = function() {
|
|
60459
|
+
return !!this.d && this.d[0] === 0;
|
|
60460
|
+
};
|
|
60461
|
+
P.lessThan = P.lt = function(y) {
|
|
60462
|
+
return this.cmp(y) < 0;
|
|
60463
|
+
};
|
|
60464
|
+
P.lessThanOrEqualTo = P.lte = function(y) {
|
|
60465
|
+
return this.cmp(y) < 1;
|
|
60466
|
+
};
|
|
60467
|
+
P.logarithm = P.log = function(base) {
|
|
60468
|
+
var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
|
|
60469
|
+
if (base == null) {
|
|
60470
|
+
base = new Ctor(10);
|
|
60471
|
+
isBase10 = true;
|
|
60472
|
+
} else {
|
|
60473
|
+
base = new Ctor(base);
|
|
60474
|
+
d = base.d;
|
|
60475
|
+
if (base.s < 0 || !d || !d[0] || base.eq(1)) return new Ctor(NaN);
|
|
60476
|
+
isBase10 = base.eq(10);
|
|
60477
|
+
}
|
|
60478
|
+
d = arg.d;
|
|
60479
|
+
if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
|
|
60480
|
+
return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
|
|
60481
|
+
}
|
|
60482
|
+
if (isBase10) {
|
|
60483
|
+
if (d.length > 1) {
|
|
60484
|
+
inf = true;
|
|
60485
|
+
} else {
|
|
60486
|
+
for (k = d[0]; k % 10 === 0; ) k /= 10;
|
|
60487
|
+
inf = k !== 1;
|
|
60488
|
+
}
|
|
60489
|
+
}
|
|
60490
|
+
external = false;
|
|
60491
|
+
sd = pr + guard;
|
|
60492
|
+
num = naturalLogarithm(arg, sd);
|
|
60493
|
+
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
60494
|
+
r = divide(num, denominator, sd, 1);
|
|
60495
|
+
if (checkRoundingDigits(r.d, k = pr, rm)) {
|
|
60496
|
+
do {
|
|
60497
|
+
sd += 10;
|
|
60498
|
+
num = naturalLogarithm(arg, sd);
|
|
60499
|
+
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
60500
|
+
r = divide(num, denominator, sd, 1);
|
|
60501
|
+
if (!inf) {
|
|
60502
|
+
if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 1e14) {
|
|
60503
|
+
r = finalise(r, pr + 1, 0);
|
|
60504
|
+
}
|
|
60505
|
+
break;
|
|
60506
|
+
}
|
|
60507
|
+
} while (checkRoundingDigits(r.d, k += 10, rm));
|
|
60508
|
+
}
|
|
60509
|
+
external = true;
|
|
60510
|
+
return finalise(r, pr, rm);
|
|
60511
|
+
};
|
|
60512
|
+
P.minus = P.sub = function(y) {
|
|
60513
|
+
var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
|
|
60514
|
+
y = new Ctor(y);
|
|
60515
|
+
if (!x.d || !y.d) {
|
|
60516
|
+
if (!x.s || !y.s) y = new Ctor(NaN);
|
|
60517
|
+
else if (x.d) y.s = -y.s;
|
|
60518
|
+
else y = new Ctor(y.d || x.s !== y.s ? x : NaN);
|
|
60519
|
+
return y;
|
|
60520
|
+
}
|
|
60521
|
+
if (x.s != y.s) {
|
|
60522
|
+
y.s = -y.s;
|
|
60523
|
+
return x.plus(y);
|
|
60524
|
+
}
|
|
60525
|
+
xd = x.d;
|
|
60526
|
+
yd = y.d;
|
|
60527
|
+
pr = Ctor.precision;
|
|
60528
|
+
rm = Ctor.rounding;
|
|
60529
|
+
if (!xd[0] || !yd[0]) {
|
|
60530
|
+
if (yd[0]) y.s = -y.s;
|
|
60531
|
+
else if (xd[0]) y = new Ctor(x);
|
|
60532
|
+
else return new Ctor(rm === 3 ? -0 : 0);
|
|
60533
|
+
return external ? finalise(y, pr, rm) : y;
|
|
60534
|
+
}
|
|
60535
|
+
e = mathfloor(y.e / LOG_BASE);
|
|
60536
|
+
xe = mathfloor(x.e / LOG_BASE);
|
|
60537
|
+
xd = xd.slice();
|
|
60538
|
+
k = xe - e;
|
|
60539
|
+
if (k) {
|
|
60540
|
+
xLTy = k < 0;
|
|
60541
|
+
if (xLTy) {
|
|
60542
|
+
d = xd;
|
|
60543
|
+
k = -k;
|
|
60544
|
+
len = yd.length;
|
|
60545
|
+
} else {
|
|
60546
|
+
d = yd;
|
|
60547
|
+
e = xe;
|
|
60548
|
+
len = xd.length;
|
|
60549
|
+
}
|
|
60550
|
+
i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
|
|
60551
|
+
if (k > i) {
|
|
60552
|
+
k = i;
|
|
60553
|
+
d.length = 1;
|
|
60554
|
+
}
|
|
60555
|
+
d.reverse();
|
|
60556
|
+
for (i = k; i--; ) d.push(0);
|
|
60557
|
+
d.reverse();
|
|
60558
|
+
} else {
|
|
60559
|
+
i = xd.length;
|
|
60560
|
+
len = yd.length;
|
|
60561
|
+
xLTy = i < len;
|
|
60562
|
+
if (xLTy) len = i;
|
|
60563
|
+
for (i = 0; i < len; i++) {
|
|
60564
|
+
if (xd[i] != yd[i]) {
|
|
60565
|
+
xLTy = xd[i] < yd[i];
|
|
60566
|
+
break;
|
|
60567
|
+
}
|
|
60568
|
+
}
|
|
60569
|
+
k = 0;
|
|
60570
|
+
}
|
|
60571
|
+
if (xLTy) {
|
|
60572
|
+
d = xd;
|
|
60573
|
+
xd = yd;
|
|
60574
|
+
yd = d;
|
|
60575
|
+
y.s = -y.s;
|
|
60576
|
+
}
|
|
60577
|
+
len = xd.length;
|
|
60578
|
+
for (i = yd.length - len; i > 0; --i) xd[len++] = 0;
|
|
60579
|
+
for (i = yd.length; i > k; ) {
|
|
60580
|
+
if (xd[--i] < yd[i]) {
|
|
60581
|
+
for (j = i; j && xd[--j] === 0; ) xd[j] = BASE - 1;
|
|
60582
|
+
--xd[j];
|
|
60583
|
+
xd[i] += BASE;
|
|
60584
|
+
}
|
|
60585
|
+
xd[i] -= yd[i];
|
|
60586
|
+
}
|
|
60587
|
+
for (; xd[--len] === 0; ) xd.pop();
|
|
60588
|
+
for (; xd[0] === 0; xd.shift()) --e;
|
|
60589
|
+
if (!xd[0]) return new Ctor(rm === 3 ? -0 : 0);
|
|
60590
|
+
y.d = xd;
|
|
60591
|
+
y.e = getBase10Exponent(xd, e);
|
|
60592
|
+
return external ? finalise(y, pr, rm) : y;
|
|
60593
|
+
};
|
|
60594
|
+
P.modulo = P.mod = function(y) {
|
|
60595
|
+
var q, x = this, Ctor = x.constructor;
|
|
60596
|
+
y = new Ctor(y);
|
|
60597
|
+
if (!x.d || !y.s || y.d && !y.d[0]) return new Ctor(NaN);
|
|
60598
|
+
if (!y.d || x.d && !x.d[0]) {
|
|
60599
|
+
return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
|
|
60600
|
+
}
|
|
60601
|
+
external = false;
|
|
60602
|
+
if (Ctor.modulo == 9) {
|
|
60603
|
+
q = divide(x, y.abs(), 0, 3, 1);
|
|
60604
|
+
q.s *= y.s;
|
|
60605
|
+
} else {
|
|
60606
|
+
q = divide(x, y, 0, Ctor.modulo, 1);
|
|
60607
|
+
}
|
|
60608
|
+
q = q.times(y);
|
|
60609
|
+
external = true;
|
|
60610
|
+
return x.minus(q);
|
|
60611
|
+
};
|
|
60612
|
+
P.naturalExponential = P.exp = function() {
|
|
60613
|
+
return naturalExponential(this);
|
|
60614
|
+
};
|
|
60615
|
+
P.naturalLogarithm = P.ln = function() {
|
|
60616
|
+
return naturalLogarithm(this);
|
|
60617
|
+
};
|
|
60618
|
+
P.negated = P.neg = function() {
|
|
60619
|
+
var x = new this.constructor(this);
|
|
60620
|
+
x.s = -x.s;
|
|
60621
|
+
return finalise(x);
|
|
60622
|
+
};
|
|
60623
|
+
P.plus = P.add = function(y) {
|
|
60624
|
+
var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
|
|
60625
|
+
y = new Ctor(y);
|
|
60626
|
+
if (!x.d || !y.d) {
|
|
60627
|
+
if (!x.s || !y.s) y = new Ctor(NaN);
|
|
60628
|
+
else if (!x.d) y = new Ctor(y.d || x.s === y.s ? x : NaN);
|
|
60629
|
+
return y;
|
|
60630
|
+
}
|
|
60631
|
+
if (x.s != y.s) {
|
|
60632
|
+
y.s = -y.s;
|
|
60633
|
+
return x.minus(y);
|
|
60634
|
+
}
|
|
60635
|
+
xd = x.d;
|
|
60636
|
+
yd = y.d;
|
|
60637
|
+
pr = Ctor.precision;
|
|
60638
|
+
rm = Ctor.rounding;
|
|
60639
|
+
if (!xd[0] || !yd[0]) {
|
|
60640
|
+
if (!yd[0]) y = new Ctor(x);
|
|
60641
|
+
return external ? finalise(y, pr, rm) : y;
|
|
60642
|
+
}
|
|
60643
|
+
k = mathfloor(x.e / LOG_BASE);
|
|
60644
|
+
e = mathfloor(y.e / LOG_BASE);
|
|
60645
|
+
xd = xd.slice();
|
|
60646
|
+
i = k - e;
|
|
60647
|
+
if (i) {
|
|
60648
|
+
if (i < 0) {
|
|
60649
|
+
d = xd;
|
|
60650
|
+
i = -i;
|
|
60651
|
+
len = yd.length;
|
|
60652
|
+
} else {
|
|
60653
|
+
d = yd;
|
|
60654
|
+
e = k;
|
|
60655
|
+
len = xd.length;
|
|
60656
|
+
}
|
|
60657
|
+
k = Math.ceil(pr / LOG_BASE);
|
|
60658
|
+
len = k > len ? k + 1 : len + 1;
|
|
60659
|
+
if (i > len) {
|
|
60660
|
+
i = len;
|
|
60661
|
+
d.length = 1;
|
|
60662
|
+
}
|
|
60663
|
+
d.reverse();
|
|
60664
|
+
for (; i--; ) d.push(0);
|
|
60665
|
+
d.reverse();
|
|
60666
|
+
}
|
|
60667
|
+
len = xd.length;
|
|
60668
|
+
i = yd.length;
|
|
60669
|
+
if (len - i < 0) {
|
|
60670
|
+
i = len;
|
|
60671
|
+
d = yd;
|
|
60672
|
+
yd = xd;
|
|
60673
|
+
xd = d;
|
|
60674
|
+
}
|
|
60675
|
+
for (carry = 0; i; ) {
|
|
60676
|
+
carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
|
|
60677
|
+
xd[i] %= BASE;
|
|
60678
|
+
}
|
|
60679
|
+
if (carry) {
|
|
60680
|
+
xd.unshift(carry);
|
|
60681
|
+
++e;
|
|
60682
|
+
}
|
|
60683
|
+
for (len = xd.length; xd[--len] == 0; ) xd.pop();
|
|
60684
|
+
y.d = xd;
|
|
60685
|
+
y.e = getBase10Exponent(xd, e);
|
|
60686
|
+
return external ? finalise(y, pr, rm) : y;
|
|
60687
|
+
};
|
|
60688
|
+
P.precision = P.sd = function(z2) {
|
|
60689
|
+
var k, x = this;
|
|
60690
|
+
if (z2 !== void 0 && z2 !== !!z2 && z2 !== 1 && z2 !== 0) throw Error(invalidArgument + z2);
|
|
60691
|
+
if (x.d) {
|
|
60692
|
+
k = getPrecision(x.d);
|
|
60693
|
+
if (z2 && x.e + 1 > k) k = x.e + 1;
|
|
60694
|
+
} else {
|
|
60695
|
+
k = NaN;
|
|
60696
|
+
}
|
|
60697
|
+
return k;
|
|
60698
|
+
};
|
|
60699
|
+
P.round = function() {
|
|
60700
|
+
var x = this, Ctor = x.constructor;
|
|
60701
|
+
return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
|
|
60702
|
+
};
|
|
60703
|
+
P.sine = P.sin = function() {
|
|
60704
|
+
var pr, rm, x = this, Ctor = x.constructor;
|
|
60705
|
+
if (!x.isFinite()) return new Ctor(NaN);
|
|
60706
|
+
if (x.isZero()) return new Ctor(x);
|
|
60707
|
+
pr = Ctor.precision;
|
|
60708
|
+
rm = Ctor.rounding;
|
|
60709
|
+
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
|
60710
|
+
Ctor.rounding = 1;
|
|
60711
|
+
x = sine(Ctor, toLessThanHalfPi(Ctor, x));
|
|
60712
|
+
Ctor.precision = pr;
|
|
60713
|
+
Ctor.rounding = rm;
|
|
60714
|
+
return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
|
|
60715
|
+
};
|
|
60716
|
+
P.squareRoot = P.sqrt = function() {
|
|
60717
|
+
var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
|
|
60718
|
+
if (s !== 1 || !d || !d[0]) {
|
|
60719
|
+
return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
|
|
60720
|
+
}
|
|
60721
|
+
external = false;
|
|
60722
|
+
s = Math.sqrt(+x);
|
|
60723
|
+
if (s == 0 || s == 1 / 0) {
|
|
60724
|
+
n = digitsToString(d);
|
|
60725
|
+
if ((n.length + e) % 2 == 0) n += "0";
|
|
60726
|
+
s = Math.sqrt(n);
|
|
60727
|
+
e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
60728
|
+
if (s == 1 / 0) {
|
|
60729
|
+
n = "5e" + e;
|
|
60730
|
+
} else {
|
|
60731
|
+
n = s.toExponential();
|
|
60732
|
+
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
60733
|
+
}
|
|
60734
|
+
r = new Ctor(n);
|
|
60735
|
+
} else {
|
|
60736
|
+
r = new Ctor(s.toString());
|
|
60737
|
+
}
|
|
60738
|
+
sd = (e = Ctor.precision) + 3;
|
|
60739
|
+
for (; ; ) {
|
|
60740
|
+
t = r;
|
|
60741
|
+
r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
|
|
60742
|
+
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
60743
|
+
n = n.slice(sd - 3, sd + 1);
|
|
60744
|
+
if (n == "9999" || !rep && n == "4999") {
|
|
60745
|
+
if (!rep) {
|
|
60746
|
+
finalise(t, e + 1, 0);
|
|
60747
|
+
if (t.times(t).eq(x)) {
|
|
60748
|
+
r = t;
|
|
60749
|
+
break;
|
|
60750
|
+
}
|
|
60751
|
+
}
|
|
60752
|
+
sd += 4;
|
|
60753
|
+
rep = 1;
|
|
60754
|
+
} else {
|
|
60755
|
+
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
60756
|
+
finalise(r, e + 1, 1);
|
|
60757
|
+
m = !r.times(r).eq(x);
|
|
60758
|
+
}
|
|
60759
|
+
break;
|
|
60760
|
+
}
|
|
60761
|
+
}
|
|
60762
|
+
}
|
|
60763
|
+
external = true;
|
|
60764
|
+
return finalise(r, e, Ctor.rounding, m);
|
|
60765
|
+
};
|
|
60766
|
+
P.tangent = P.tan = function() {
|
|
60767
|
+
var pr, rm, x = this, Ctor = x.constructor;
|
|
60768
|
+
if (!x.isFinite()) return new Ctor(NaN);
|
|
60769
|
+
if (x.isZero()) return new Ctor(x);
|
|
60770
|
+
pr = Ctor.precision;
|
|
60771
|
+
rm = Ctor.rounding;
|
|
60772
|
+
Ctor.precision = pr + 10;
|
|
60773
|
+
Ctor.rounding = 1;
|
|
60774
|
+
x = x.sin();
|
|
60775
|
+
x.s = 1;
|
|
60776
|
+
x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
|
|
60777
|
+
Ctor.precision = pr;
|
|
60778
|
+
Ctor.rounding = rm;
|
|
60779
|
+
return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
|
|
60780
|
+
};
|
|
60781
|
+
P.times = P.mul = function(y) {
|
|
60782
|
+
var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
|
|
60783
|
+
y.s *= x.s;
|
|
60784
|
+
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
60785
|
+
return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
|
|
60786
|
+
}
|
|
60787
|
+
e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
|
|
60788
|
+
xdL = xd.length;
|
|
60789
|
+
ydL = yd.length;
|
|
60790
|
+
if (xdL < ydL) {
|
|
60791
|
+
r = xd;
|
|
60792
|
+
xd = yd;
|
|
60793
|
+
yd = r;
|
|
60794
|
+
rL = xdL;
|
|
60795
|
+
xdL = ydL;
|
|
60796
|
+
ydL = rL;
|
|
60797
|
+
}
|
|
60798
|
+
r = [];
|
|
60799
|
+
rL = xdL + ydL;
|
|
60800
|
+
for (i = rL; i--; ) r.push(0);
|
|
60801
|
+
for (i = ydL; --i >= 0; ) {
|
|
60802
|
+
carry = 0;
|
|
60803
|
+
for (k = xdL + i; k > i; ) {
|
|
60804
|
+
t = r[k] + yd[i] * xd[k - i - 1] + carry;
|
|
60805
|
+
r[k--] = t % BASE | 0;
|
|
60806
|
+
carry = t / BASE | 0;
|
|
60807
|
+
}
|
|
60808
|
+
r[k] = (r[k] + carry) % BASE | 0;
|
|
60809
|
+
}
|
|
60810
|
+
for (; !r[--rL]; ) r.pop();
|
|
60811
|
+
if (carry) ++e;
|
|
60812
|
+
else r.shift();
|
|
60813
|
+
y.d = r;
|
|
60814
|
+
y.e = getBase10Exponent(r, e);
|
|
60815
|
+
return external ? finalise(y, Ctor.precision, Ctor.rounding) : y;
|
|
60816
|
+
};
|
|
60817
|
+
P.toBinary = function(sd, rm) {
|
|
60818
|
+
return toStringBinary(this, 2, sd, rm);
|
|
60819
|
+
};
|
|
60820
|
+
P.toDecimalPlaces = P.toDP = function(dp, rm) {
|
|
60821
|
+
var x = this, Ctor = x.constructor;
|
|
60822
|
+
x = new Ctor(x);
|
|
60823
|
+
if (dp === void 0) return x;
|
|
60824
|
+
checkInt32(dp, 0, MAX_DIGITS);
|
|
60825
|
+
if (rm === void 0) rm = Ctor.rounding;
|
|
60826
|
+
else checkInt32(rm, 0, 8);
|
|
60827
|
+
return finalise(x, dp + x.e + 1, rm);
|
|
60828
|
+
};
|
|
60829
|
+
P.toExponential = function(dp, rm) {
|
|
60830
|
+
var str, x = this, Ctor = x.constructor;
|
|
60831
|
+
if (dp === void 0) {
|
|
60832
|
+
str = finiteToString(x, true);
|
|
60833
|
+
} else {
|
|
60834
|
+
checkInt32(dp, 0, MAX_DIGITS);
|
|
60835
|
+
if (rm === void 0) rm = Ctor.rounding;
|
|
60836
|
+
else checkInt32(rm, 0, 8);
|
|
60837
|
+
x = finalise(new Ctor(x), dp + 1, rm);
|
|
60838
|
+
str = finiteToString(x, true, dp + 1);
|
|
60839
|
+
}
|
|
60840
|
+
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
60841
|
+
};
|
|
60842
|
+
P.toFixed = function(dp, rm) {
|
|
60843
|
+
var str, y, x = this, Ctor = x.constructor;
|
|
60844
|
+
if (dp === void 0) {
|
|
60845
|
+
str = finiteToString(x);
|
|
60846
|
+
} else {
|
|
60847
|
+
checkInt32(dp, 0, MAX_DIGITS);
|
|
60848
|
+
if (rm === void 0) rm = Ctor.rounding;
|
|
60849
|
+
else checkInt32(rm, 0, 8);
|
|
60850
|
+
y = finalise(new Ctor(x), dp + x.e + 1, rm);
|
|
60851
|
+
str = finiteToString(y, false, dp + y.e + 1);
|
|
60852
|
+
}
|
|
60853
|
+
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
60854
|
+
};
|
|
60855
|
+
P.toFraction = function(maxD) {
|
|
60856
|
+
var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
|
|
60857
|
+
if (!xd) return new Ctor(x);
|
|
60858
|
+
n1 = d0 = new Ctor(1);
|
|
60859
|
+
d1 = n0 = new Ctor(0);
|
|
60860
|
+
d = new Ctor(d1);
|
|
60861
|
+
e = d.e = getPrecision(xd) - x.e - 1;
|
|
60862
|
+
k = e % LOG_BASE;
|
|
60863
|
+
d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
|
|
60864
|
+
if (maxD == null) {
|
|
60865
|
+
maxD = e > 0 ? d : n1;
|
|
60866
|
+
} else {
|
|
60867
|
+
n = new Ctor(maxD);
|
|
60868
|
+
if (!n.isInt() || n.lt(n1)) throw Error(invalidArgument + n);
|
|
60869
|
+
maxD = n.gt(d) ? e > 0 ? d : n1 : n;
|
|
60870
|
+
}
|
|
60871
|
+
external = false;
|
|
60872
|
+
n = new Ctor(digitsToString(xd));
|
|
60873
|
+
pr = Ctor.precision;
|
|
60874
|
+
Ctor.precision = e = xd.length * LOG_BASE * 2;
|
|
60875
|
+
for (; ; ) {
|
|
60876
|
+
q = divide(n, d, 0, 1, 1);
|
|
60877
|
+
d2 = d0.plus(q.times(d1));
|
|
60878
|
+
if (d2.cmp(maxD) == 1) break;
|
|
60879
|
+
d0 = d1;
|
|
60880
|
+
d1 = d2;
|
|
60881
|
+
d2 = n1;
|
|
60882
|
+
n1 = n0.plus(q.times(d2));
|
|
60883
|
+
n0 = d2;
|
|
60884
|
+
d2 = d;
|
|
60885
|
+
d = n.minus(q.times(d2));
|
|
60886
|
+
n = d2;
|
|
60887
|
+
}
|
|
60888
|
+
d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
|
|
60889
|
+
n0 = n0.plus(d2.times(n1));
|
|
60890
|
+
d0 = d0.plus(d2.times(d1));
|
|
60891
|
+
n0.s = n1.s = x.s;
|
|
60892
|
+
r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
|
|
60893
|
+
Ctor.precision = pr;
|
|
60894
|
+
external = true;
|
|
60895
|
+
return r;
|
|
60896
|
+
};
|
|
60897
|
+
P.toHexadecimal = P.toHex = function(sd, rm) {
|
|
60898
|
+
return toStringBinary(this, 16, sd, rm);
|
|
60899
|
+
};
|
|
60900
|
+
P.toNearest = function(y, rm) {
|
|
60901
|
+
var x = this, Ctor = x.constructor;
|
|
60902
|
+
x = new Ctor(x);
|
|
60903
|
+
if (y == null) {
|
|
60904
|
+
if (!x.d) return x;
|
|
60905
|
+
y = new Ctor(1);
|
|
60906
|
+
rm = Ctor.rounding;
|
|
60907
|
+
} else {
|
|
60908
|
+
y = new Ctor(y);
|
|
60909
|
+
if (rm === void 0) {
|
|
60910
|
+
rm = Ctor.rounding;
|
|
60911
|
+
} else {
|
|
60912
|
+
checkInt32(rm, 0, 8);
|
|
60913
|
+
}
|
|
60914
|
+
if (!x.d) return y.s ? x : y;
|
|
60915
|
+
if (!y.d) {
|
|
60916
|
+
if (y.s) y.s = x.s;
|
|
60917
|
+
return y;
|
|
60918
|
+
}
|
|
60919
|
+
}
|
|
60920
|
+
if (y.d[0]) {
|
|
60921
|
+
external = false;
|
|
60922
|
+
x = divide(x, y, 0, rm, 1).times(y);
|
|
60923
|
+
external = true;
|
|
60924
|
+
finalise(x);
|
|
60925
|
+
} else {
|
|
60926
|
+
y.s = x.s;
|
|
60927
|
+
x = y;
|
|
60928
|
+
}
|
|
60929
|
+
return x;
|
|
60930
|
+
};
|
|
60931
|
+
P.toNumber = function() {
|
|
60932
|
+
return +this;
|
|
60933
|
+
};
|
|
60934
|
+
P.toOctal = function(sd, rm) {
|
|
60935
|
+
return toStringBinary(this, 8, sd, rm);
|
|
60936
|
+
};
|
|
60937
|
+
P.toPower = P.pow = function(y) {
|
|
60938
|
+
var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
|
|
60939
|
+
if (!x.d || !y.d || !x.d[0] || !y.d[0]) return new Ctor(mathpow(+x, yn));
|
|
60940
|
+
x = new Ctor(x);
|
|
60941
|
+
if (x.eq(1)) return x;
|
|
60942
|
+
pr = Ctor.precision;
|
|
60943
|
+
rm = Ctor.rounding;
|
|
60944
|
+
if (y.eq(1)) return finalise(x, pr, rm);
|
|
60945
|
+
e = mathfloor(y.e / LOG_BASE);
|
|
60946
|
+
if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
|
|
60947
|
+
r = intPow(Ctor, x, k, pr);
|
|
60948
|
+
return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
|
|
60949
|
+
}
|
|
60950
|
+
s = x.s;
|
|
60951
|
+
if (s < 0) {
|
|
60952
|
+
if (e < y.d.length - 1) return new Ctor(NaN);
|
|
60953
|
+
if ((y.d[e] & 1) == 0) s = 1;
|
|
60954
|
+
if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
|
|
60955
|
+
x.s = s;
|
|
60956
|
+
return x;
|
|
60957
|
+
}
|
|
60958
|
+
}
|
|
60959
|
+
k = mathpow(+x, yn);
|
|
60960
|
+
e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
|
|
60961
|
+
if (e > Ctor.maxE + 1 || e < Ctor.minE - 1) return new Ctor(e > 0 ? s / 0 : 0);
|
|
60962
|
+
external = false;
|
|
60963
|
+
Ctor.rounding = x.s = 1;
|
|
60964
|
+
k = Math.min(12, (e + "").length);
|
|
60965
|
+
r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
|
|
60966
|
+
if (r.d) {
|
|
60967
|
+
r = finalise(r, pr + 5, 1);
|
|
60968
|
+
if (checkRoundingDigits(r.d, pr, rm)) {
|
|
60969
|
+
e = pr + 10;
|
|
60970
|
+
r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
|
|
60971
|
+
if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 1e14) {
|
|
60972
|
+
r = finalise(r, pr + 1, 0);
|
|
60973
|
+
}
|
|
60974
|
+
}
|
|
60975
|
+
}
|
|
60976
|
+
r.s = s;
|
|
60977
|
+
external = true;
|
|
60978
|
+
Ctor.rounding = rm;
|
|
60979
|
+
return finalise(r, pr, rm);
|
|
60980
|
+
};
|
|
60981
|
+
P.toPrecision = function(sd, rm) {
|
|
60982
|
+
var str, x = this, Ctor = x.constructor;
|
|
60983
|
+
if (sd === void 0) {
|
|
60984
|
+
str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
60985
|
+
} else {
|
|
60986
|
+
checkInt32(sd, 1, MAX_DIGITS);
|
|
60987
|
+
if (rm === void 0) rm = Ctor.rounding;
|
|
60988
|
+
else checkInt32(rm, 0, 8);
|
|
60989
|
+
x = finalise(new Ctor(x), sd, rm);
|
|
60990
|
+
str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
|
|
60991
|
+
}
|
|
60992
|
+
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
60993
|
+
};
|
|
60994
|
+
P.toSignificantDigits = P.toSD = function(sd, rm) {
|
|
60995
|
+
var x = this, Ctor = x.constructor;
|
|
60996
|
+
if (sd === void 0) {
|
|
60997
|
+
sd = Ctor.precision;
|
|
60998
|
+
rm = Ctor.rounding;
|
|
60999
|
+
} else {
|
|
61000
|
+
checkInt32(sd, 1, MAX_DIGITS);
|
|
61001
|
+
if (rm === void 0) rm = Ctor.rounding;
|
|
61002
|
+
else checkInt32(rm, 0, 8);
|
|
61003
|
+
}
|
|
61004
|
+
return finalise(new Ctor(x), sd, rm);
|
|
61005
|
+
};
|
|
61006
|
+
P.toString = function() {
|
|
61007
|
+
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
61008
|
+
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
61009
|
+
};
|
|
61010
|
+
P.truncated = P.trunc = function() {
|
|
61011
|
+
return finalise(new this.constructor(this), this.e + 1, 1);
|
|
61012
|
+
};
|
|
61013
|
+
P.valueOf = P.toJSON = function() {
|
|
61014
|
+
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
61015
|
+
return x.isNeg() ? "-" + str : str;
|
|
61016
|
+
};
|
|
61017
|
+
function digitsToString(d) {
|
|
61018
|
+
var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
|
|
61019
|
+
if (indexOfLastWord > 0) {
|
|
61020
|
+
str += w;
|
|
61021
|
+
for (i = 1; i < indexOfLastWord; i++) {
|
|
61022
|
+
ws = d[i] + "";
|
|
61023
|
+
k = LOG_BASE - ws.length;
|
|
61024
|
+
if (k) str += getZeroString(k);
|
|
61025
|
+
str += ws;
|
|
61026
|
+
}
|
|
61027
|
+
w = d[i];
|
|
61028
|
+
ws = w + "";
|
|
61029
|
+
k = LOG_BASE - ws.length;
|
|
61030
|
+
if (k) str += getZeroString(k);
|
|
61031
|
+
} else if (w === 0) {
|
|
61032
|
+
return "0";
|
|
61033
|
+
}
|
|
61034
|
+
for (; w % 10 === 0; ) w /= 10;
|
|
61035
|
+
return str + w;
|
|
61036
|
+
}
|
|
61037
|
+
function checkInt32(i, min2, max2) {
|
|
61038
|
+
if (i !== ~~i || i < min2 || i > max2) {
|
|
61039
|
+
throw Error(invalidArgument + i);
|
|
61040
|
+
}
|
|
61041
|
+
}
|
|
61042
|
+
function checkRoundingDigits(d, i, rm, repeating) {
|
|
61043
|
+
var di, k, r, rd;
|
|
61044
|
+
for (k = d[0]; k >= 10; k /= 10) --i;
|
|
61045
|
+
if (--i < 0) {
|
|
61046
|
+
i += LOG_BASE;
|
|
61047
|
+
di = 0;
|
|
61048
|
+
} else {
|
|
61049
|
+
di = Math.ceil((i + 1) / LOG_BASE);
|
|
61050
|
+
i %= LOG_BASE;
|
|
61051
|
+
}
|
|
61052
|
+
k = mathpow(10, LOG_BASE - i);
|
|
61053
|
+
rd = d[di] % k | 0;
|
|
61054
|
+
if (repeating == null) {
|
|
61055
|
+
if (i < 3) {
|
|
61056
|
+
if (i == 0) rd = rd / 100 | 0;
|
|
61057
|
+
else if (i == 1) rd = rd / 10 | 0;
|
|
61058
|
+
r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 5e4 || rd == 0;
|
|
61059
|
+
} else {
|
|
61060
|
+
r = (rm < 4 && rd + 1 == k || rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 100 | 0) == mathpow(10, i - 2) - 1 || (rd == k / 2 || rd == 0) && (d[di + 1] / k / 100 | 0) == 0;
|
|
61061
|
+
}
|
|
61062
|
+
} else {
|
|
61063
|
+
if (i < 4) {
|
|
61064
|
+
if (i == 0) rd = rd / 1e3 | 0;
|
|
61065
|
+
else if (i == 1) rd = rd / 100 | 0;
|
|
61066
|
+
else if (i == 2) rd = rd / 10 | 0;
|
|
61067
|
+
r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
|
|
61068
|
+
} else {
|
|
61069
|
+
r = ((repeating || rm < 4) && rd + 1 == k || !repeating && rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 1e3 | 0) == mathpow(10, i - 3) - 1;
|
|
61070
|
+
}
|
|
61071
|
+
}
|
|
61072
|
+
return r;
|
|
61073
|
+
}
|
|
61074
|
+
function convertBase(str, baseIn, baseOut) {
|
|
61075
|
+
var j, arr = [0], arrL, i = 0, strL = str.length;
|
|
61076
|
+
for (; i < strL; ) {
|
|
61077
|
+
for (arrL = arr.length; arrL--; ) arr[arrL] *= baseIn;
|
|
61078
|
+
arr[0] += NUMERALS.indexOf(str.charAt(i++));
|
|
61079
|
+
for (j = 0; j < arr.length; j++) {
|
|
61080
|
+
if (arr[j] > baseOut - 1) {
|
|
61081
|
+
if (arr[j + 1] === void 0) arr[j + 1] = 0;
|
|
61082
|
+
arr[j + 1] += arr[j] / baseOut | 0;
|
|
61083
|
+
arr[j] %= baseOut;
|
|
61084
|
+
}
|
|
61085
|
+
}
|
|
61086
|
+
}
|
|
61087
|
+
return arr.reverse();
|
|
61088
|
+
}
|
|
61089
|
+
function cosine(Ctor, x) {
|
|
61090
|
+
var k, len, y;
|
|
61091
|
+
if (x.isZero()) return x;
|
|
61092
|
+
len = x.d.length;
|
|
61093
|
+
if (len < 32) {
|
|
61094
|
+
k = Math.ceil(len / 3);
|
|
61095
|
+
y = (1 / tinyPow(4, k)).toString();
|
|
61096
|
+
} else {
|
|
61097
|
+
k = 16;
|
|
61098
|
+
y = "2.3283064365386962890625e-10";
|
|
61099
|
+
}
|
|
61100
|
+
Ctor.precision += k;
|
|
61101
|
+
x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
|
|
61102
|
+
for (var i = k; i--; ) {
|
|
61103
|
+
var cos2x = x.times(x);
|
|
61104
|
+
x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
|
|
61105
|
+
}
|
|
61106
|
+
Ctor.precision -= k;
|
|
61107
|
+
return x;
|
|
61108
|
+
}
|
|
61109
|
+
var divide = /* @__PURE__ */ (function() {
|
|
61110
|
+
function multiplyInteger(x, k, base) {
|
|
61111
|
+
var temp, carry = 0, i = x.length;
|
|
61112
|
+
for (x = x.slice(); i--; ) {
|
|
61113
|
+
temp = x[i] * k + carry;
|
|
61114
|
+
x[i] = temp % base | 0;
|
|
61115
|
+
carry = temp / base | 0;
|
|
61116
|
+
}
|
|
61117
|
+
if (carry) x.unshift(carry);
|
|
61118
|
+
return x;
|
|
61119
|
+
}
|
|
61120
|
+
function compare(a, b, aL, bL) {
|
|
61121
|
+
var i, r;
|
|
61122
|
+
if (aL != bL) {
|
|
61123
|
+
r = aL > bL ? 1 : -1;
|
|
61124
|
+
} else {
|
|
61125
|
+
for (i = r = 0; i < aL; i++) {
|
|
61126
|
+
if (a[i] != b[i]) {
|
|
61127
|
+
r = a[i] > b[i] ? 1 : -1;
|
|
61128
|
+
break;
|
|
61129
|
+
}
|
|
61130
|
+
}
|
|
61131
|
+
}
|
|
61132
|
+
return r;
|
|
61133
|
+
}
|
|
61134
|
+
function subtract(a, b, aL, base) {
|
|
61135
|
+
var i = 0;
|
|
61136
|
+
for (; aL--; ) {
|
|
61137
|
+
a[aL] -= i;
|
|
61138
|
+
i = a[aL] < b[aL] ? 1 : 0;
|
|
61139
|
+
a[aL] = i * base + a[aL] - b[aL];
|
|
61140
|
+
}
|
|
61141
|
+
for (; !a[0] && a.length > 1; ) a.shift();
|
|
61142
|
+
}
|
|
61143
|
+
return function(x, y, pr, rm, dp, base) {
|
|
61144
|
+
var cmp, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign2 = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
|
|
61145
|
+
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
61146
|
+
return new Ctor(
|
|
61147
|
+
// Return NaN if either NaN, or both Infinity or 0.
|
|
61148
|
+
!x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : (
|
|
61149
|
+
// Return ±0 if x is 0 or y is ±Infinity, or return ±Infinity as y is 0.
|
|
61150
|
+
xd && xd[0] == 0 || !yd ? sign2 * 0 : sign2 / 0
|
|
61151
|
+
)
|
|
61152
|
+
);
|
|
61153
|
+
}
|
|
61154
|
+
if (base) {
|
|
61155
|
+
logBase = 1;
|
|
61156
|
+
e = x.e - y.e;
|
|
61157
|
+
} else {
|
|
61158
|
+
base = BASE;
|
|
61159
|
+
logBase = LOG_BASE;
|
|
61160
|
+
e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
|
|
61161
|
+
}
|
|
61162
|
+
yL = yd.length;
|
|
61163
|
+
xL = xd.length;
|
|
61164
|
+
q = new Ctor(sign2);
|
|
61165
|
+
qd = q.d = [];
|
|
61166
|
+
for (i = 0; yd[i] == (xd[i] || 0); i++) ;
|
|
61167
|
+
if (yd[i] > (xd[i] || 0)) e--;
|
|
61168
|
+
if (pr == null) {
|
|
61169
|
+
sd = pr = Ctor.precision;
|
|
61170
|
+
rm = Ctor.rounding;
|
|
61171
|
+
} else if (dp) {
|
|
61172
|
+
sd = pr + (x.e - y.e) + 1;
|
|
61173
|
+
} else {
|
|
61174
|
+
sd = pr;
|
|
61175
|
+
}
|
|
61176
|
+
if (sd < 0) {
|
|
61177
|
+
qd.push(1);
|
|
61178
|
+
more = true;
|
|
61179
|
+
} else {
|
|
61180
|
+
sd = sd / logBase + 2 | 0;
|
|
61181
|
+
i = 0;
|
|
61182
|
+
if (yL == 1) {
|
|
61183
|
+
k = 0;
|
|
61184
|
+
yd = yd[0];
|
|
61185
|
+
sd++;
|
|
61186
|
+
for (; (i < xL || k) && sd--; i++) {
|
|
61187
|
+
t = k * base + (xd[i] || 0);
|
|
61188
|
+
qd[i] = t / yd | 0;
|
|
61189
|
+
k = t % yd | 0;
|
|
61190
|
+
}
|
|
61191
|
+
more = k || i < xL;
|
|
61192
|
+
} else {
|
|
61193
|
+
k = base / (yd[0] + 1) | 0;
|
|
61194
|
+
if (k > 1) {
|
|
61195
|
+
yd = multiplyInteger(yd, k, base);
|
|
61196
|
+
xd = multiplyInteger(xd, k, base);
|
|
61197
|
+
yL = yd.length;
|
|
61198
|
+
xL = xd.length;
|
|
61199
|
+
}
|
|
61200
|
+
xi = yL;
|
|
61201
|
+
rem = xd.slice(0, yL);
|
|
61202
|
+
remL = rem.length;
|
|
61203
|
+
for (; remL < yL; ) rem[remL++] = 0;
|
|
61204
|
+
yz = yd.slice();
|
|
61205
|
+
yz.unshift(0);
|
|
61206
|
+
yd0 = yd[0];
|
|
61207
|
+
if (yd[1] >= base / 2) ++yd0;
|
|
61208
|
+
do {
|
|
61209
|
+
k = 0;
|
|
61210
|
+
cmp = compare(yd, rem, yL, remL);
|
|
61211
|
+
if (cmp < 0) {
|
|
61212
|
+
rem0 = rem[0];
|
|
61213
|
+
if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
|
|
61214
|
+
k = rem0 / yd0 | 0;
|
|
61215
|
+
if (k > 1) {
|
|
61216
|
+
if (k >= base) k = base - 1;
|
|
61217
|
+
prod = multiplyInteger(yd, k, base);
|
|
61218
|
+
prodL = prod.length;
|
|
61219
|
+
remL = rem.length;
|
|
61220
|
+
cmp = compare(prod, rem, prodL, remL);
|
|
61221
|
+
if (cmp == 1) {
|
|
61222
|
+
k--;
|
|
61223
|
+
subtract(prod, yL < prodL ? yz : yd, prodL, base);
|
|
61224
|
+
}
|
|
61225
|
+
} else {
|
|
61226
|
+
if (k == 0) cmp = k = 1;
|
|
61227
|
+
prod = yd.slice();
|
|
61228
|
+
}
|
|
61229
|
+
prodL = prod.length;
|
|
61230
|
+
if (prodL < remL) prod.unshift(0);
|
|
61231
|
+
subtract(rem, prod, remL, base);
|
|
61232
|
+
if (cmp == -1) {
|
|
61233
|
+
remL = rem.length;
|
|
61234
|
+
cmp = compare(yd, rem, yL, remL);
|
|
61235
|
+
if (cmp < 1) {
|
|
61236
|
+
k++;
|
|
61237
|
+
subtract(rem, yL < remL ? yz : yd, remL, base);
|
|
61238
|
+
}
|
|
61239
|
+
}
|
|
61240
|
+
remL = rem.length;
|
|
61241
|
+
} else if (cmp === 0) {
|
|
61242
|
+
k++;
|
|
61243
|
+
rem = [0];
|
|
61244
|
+
}
|
|
61245
|
+
qd[i++] = k;
|
|
61246
|
+
if (cmp && rem[0]) {
|
|
61247
|
+
rem[remL++] = xd[xi] || 0;
|
|
61248
|
+
} else {
|
|
61249
|
+
rem = [xd[xi]];
|
|
61250
|
+
remL = 1;
|
|
61251
|
+
}
|
|
61252
|
+
} while ((xi++ < xL || rem[0] !== void 0) && sd--);
|
|
61253
|
+
more = rem[0] !== void 0;
|
|
61254
|
+
}
|
|
61255
|
+
if (!qd[0]) qd.shift();
|
|
61256
|
+
}
|
|
61257
|
+
if (logBase == 1) {
|
|
61258
|
+
q.e = e;
|
|
61259
|
+
inexact = more;
|
|
61260
|
+
} else {
|
|
61261
|
+
for (i = 1, k = qd[0]; k >= 10; k /= 10) i++;
|
|
61262
|
+
q.e = i + e * logBase - 1;
|
|
61263
|
+
finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
|
|
61264
|
+
}
|
|
61265
|
+
return q;
|
|
61266
|
+
};
|
|
61267
|
+
})();
|
|
61268
|
+
function finalise(x, sd, rm, isTruncated) {
|
|
61269
|
+
var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
|
|
61270
|
+
out: if (sd != null) {
|
|
61271
|
+
xd = x.d;
|
|
61272
|
+
if (!xd) return x;
|
|
61273
|
+
for (digits = 1, k = xd[0]; k >= 10; k /= 10) digits++;
|
|
61274
|
+
i = sd - digits;
|
|
61275
|
+
if (i < 0) {
|
|
61276
|
+
i += LOG_BASE;
|
|
61277
|
+
j = sd;
|
|
61278
|
+
w = xd[xdi = 0];
|
|
61279
|
+
rd = w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
61280
|
+
} else {
|
|
61281
|
+
xdi = Math.ceil((i + 1) / LOG_BASE);
|
|
61282
|
+
k = xd.length;
|
|
61283
|
+
if (xdi >= k) {
|
|
61284
|
+
if (isTruncated) {
|
|
61285
|
+
for (; k++ <= xdi; ) xd.push(0);
|
|
61286
|
+
w = rd = 0;
|
|
61287
|
+
digits = 1;
|
|
61288
|
+
i %= LOG_BASE;
|
|
61289
|
+
j = i - LOG_BASE + 1;
|
|
61290
|
+
} else {
|
|
61291
|
+
break out;
|
|
61292
|
+
}
|
|
61293
|
+
} else {
|
|
61294
|
+
w = k = xd[xdi];
|
|
61295
|
+
for (digits = 1; k >= 10; k /= 10) digits++;
|
|
61296
|
+
i %= LOG_BASE;
|
|
61297
|
+
j = i - LOG_BASE + digits;
|
|
61298
|
+
rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
61299
|
+
}
|
|
61300
|
+
}
|
|
61301
|
+
isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== void 0 || (j < 0 ? w : w % mathpow(10, digits - j - 1));
|
|
61302
|
+
roundUp = rm < 4 ? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
|
|
61303
|
+
(i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
61304
|
+
if (sd < 1 || !xd[0]) {
|
|
61305
|
+
xd.length = 0;
|
|
61306
|
+
if (roundUp) {
|
|
61307
|
+
sd -= x.e + 1;
|
|
61308
|
+
xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
|
|
61309
|
+
x.e = -sd || 0;
|
|
61310
|
+
} else {
|
|
61311
|
+
xd[0] = x.e = 0;
|
|
61312
|
+
}
|
|
61313
|
+
return x;
|
|
61314
|
+
}
|
|
61315
|
+
if (i == 0) {
|
|
61316
|
+
xd.length = xdi;
|
|
61317
|
+
k = 1;
|
|
61318
|
+
xdi--;
|
|
61319
|
+
} else {
|
|
61320
|
+
xd.length = xdi + 1;
|
|
61321
|
+
k = mathpow(10, LOG_BASE - i);
|
|
61322
|
+
xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
|
|
61323
|
+
}
|
|
61324
|
+
if (roundUp) {
|
|
61325
|
+
for (; ; ) {
|
|
61326
|
+
if (xdi == 0) {
|
|
61327
|
+
for (i = 1, j = xd[0]; j >= 10; j /= 10) i++;
|
|
61328
|
+
j = xd[0] += k;
|
|
61329
|
+
for (k = 1; j >= 10; j /= 10) k++;
|
|
61330
|
+
if (i != k) {
|
|
61331
|
+
x.e++;
|
|
61332
|
+
if (xd[0] == BASE) xd[0] = 1;
|
|
61333
|
+
}
|
|
61334
|
+
break;
|
|
61335
|
+
} else {
|
|
61336
|
+
xd[xdi] += k;
|
|
61337
|
+
if (xd[xdi] != BASE) break;
|
|
61338
|
+
xd[xdi--] = 0;
|
|
61339
|
+
k = 1;
|
|
61340
|
+
}
|
|
61341
|
+
}
|
|
61342
|
+
}
|
|
61343
|
+
for (i = xd.length; xd[--i] === 0; ) xd.pop();
|
|
61344
|
+
}
|
|
61345
|
+
if (external) {
|
|
61346
|
+
if (x.e > Ctor.maxE) {
|
|
61347
|
+
x.d = null;
|
|
61348
|
+
x.e = NaN;
|
|
61349
|
+
} else if (x.e < Ctor.minE) {
|
|
61350
|
+
x.e = 0;
|
|
61351
|
+
x.d = [0];
|
|
61352
|
+
}
|
|
61353
|
+
}
|
|
61354
|
+
return x;
|
|
61355
|
+
}
|
|
61356
|
+
function finiteToString(x, isExp, sd) {
|
|
61357
|
+
if (!x.isFinite()) return nonFiniteToString(x);
|
|
61358
|
+
var k, e = x.e, str = digitsToString(x.d), len = str.length;
|
|
61359
|
+
if (isExp) {
|
|
61360
|
+
if (sd && (k = sd - len) > 0) {
|
|
61361
|
+
str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
|
|
61362
|
+
} else if (len > 1) {
|
|
61363
|
+
str = str.charAt(0) + "." + str.slice(1);
|
|
61364
|
+
}
|
|
61365
|
+
str = str + (x.e < 0 ? "e" : "e+") + x.e;
|
|
61366
|
+
} else if (e < 0) {
|
|
61367
|
+
str = "0." + getZeroString(-e - 1) + str;
|
|
61368
|
+
if (sd && (k = sd - len) > 0) str += getZeroString(k);
|
|
61369
|
+
} else if (e >= len) {
|
|
61370
|
+
str += getZeroString(e + 1 - len);
|
|
61371
|
+
if (sd && (k = sd - e - 1) > 0) str = str + "." + getZeroString(k);
|
|
61372
|
+
} else {
|
|
61373
|
+
if ((k = e + 1) < len) str = str.slice(0, k) + "." + str.slice(k);
|
|
61374
|
+
if (sd && (k = sd - len) > 0) {
|
|
61375
|
+
if (e + 1 === len) str += ".";
|
|
61376
|
+
str += getZeroString(k);
|
|
61377
|
+
}
|
|
61378
|
+
}
|
|
61379
|
+
return str;
|
|
61380
|
+
}
|
|
61381
|
+
function getBase10Exponent(digits, e) {
|
|
61382
|
+
var w = digits[0];
|
|
61383
|
+
for (e *= LOG_BASE; w >= 10; w /= 10) e++;
|
|
61384
|
+
return e;
|
|
61385
|
+
}
|
|
61386
|
+
function getLn10(Ctor, sd, pr) {
|
|
61387
|
+
if (sd > LN10_PRECISION) {
|
|
61388
|
+
external = true;
|
|
61389
|
+
if (pr) Ctor.precision = pr;
|
|
61390
|
+
throw Error(precisionLimitExceeded);
|
|
61391
|
+
}
|
|
61392
|
+
return finalise(new Ctor(LN10), sd, 1, true);
|
|
61393
|
+
}
|
|
61394
|
+
function getPi(Ctor, sd, rm) {
|
|
61395
|
+
if (sd > PI_PRECISION) throw Error(precisionLimitExceeded);
|
|
61396
|
+
return finalise(new Ctor(PI), sd, rm, true);
|
|
61397
|
+
}
|
|
61398
|
+
function getPrecision(digits) {
|
|
61399
|
+
var w = digits.length - 1, len = w * LOG_BASE + 1;
|
|
61400
|
+
w = digits[w];
|
|
61401
|
+
if (w) {
|
|
61402
|
+
for (; w % 10 == 0; w /= 10) len--;
|
|
61403
|
+
for (w = digits[0]; w >= 10; w /= 10) len++;
|
|
61404
|
+
}
|
|
61405
|
+
return len;
|
|
61406
|
+
}
|
|
61407
|
+
function getZeroString(k) {
|
|
61408
|
+
var zs = "";
|
|
61409
|
+
for (; k--; ) zs += "0";
|
|
61410
|
+
return zs;
|
|
61411
|
+
}
|
|
61412
|
+
function intPow(Ctor, x, n, pr) {
|
|
61413
|
+
var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
|
|
61414
|
+
external = false;
|
|
61415
|
+
for (; ; ) {
|
|
61416
|
+
if (n % 2) {
|
|
61417
|
+
r = r.times(x);
|
|
61418
|
+
if (truncate(r.d, k)) isTruncated = true;
|
|
61419
|
+
}
|
|
61420
|
+
n = mathfloor(n / 2);
|
|
61421
|
+
if (n === 0) {
|
|
61422
|
+
n = r.d.length - 1;
|
|
61423
|
+
if (isTruncated && r.d[n] === 0) ++r.d[n];
|
|
61424
|
+
break;
|
|
61425
|
+
}
|
|
61426
|
+
x = x.times(x);
|
|
61427
|
+
truncate(x.d, k);
|
|
61428
|
+
}
|
|
61429
|
+
external = true;
|
|
61430
|
+
return r;
|
|
61431
|
+
}
|
|
61432
|
+
function isOdd(n) {
|
|
61433
|
+
return n.d[n.d.length - 1] & 1;
|
|
61434
|
+
}
|
|
61435
|
+
function maxOrMin(Ctor, args, n) {
|
|
61436
|
+
var k, y, x = new Ctor(args[0]), i = 0;
|
|
61437
|
+
for (; ++i < args.length; ) {
|
|
61438
|
+
y = new Ctor(args[i]);
|
|
61439
|
+
if (!y.s) {
|
|
61440
|
+
x = y;
|
|
61441
|
+
break;
|
|
61442
|
+
}
|
|
61443
|
+
k = x.cmp(y);
|
|
61444
|
+
if (k === n || k === 0 && x.s === n) {
|
|
61445
|
+
x = y;
|
|
61446
|
+
}
|
|
61447
|
+
}
|
|
61448
|
+
return x;
|
|
61449
|
+
}
|
|
61450
|
+
function naturalExponential(x, sd) {
|
|
61451
|
+
var denominator, guard, j, pow2, sum2, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
|
61452
|
+
if (!x.d || !x.d[0] || x.e > 17) {
|
|
61453
|
+
return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
|
|
61454
|
+
}
|
|
61455
|
+
if (sd == null) {
|
|
61456
|
+
external = false;
|
|
61457
|
+
wpr = pr;
|
|
61458
|
+
} else {
|
|
61459
|
+
wpr = sd;
|
|
61460
|
+
}
|
|
61461
|
+
t = new Ctor(0.03125);
|
|
61462
|
+
while (x.e > -2) {
|
|
61463
|
+
x = x.times(t);
|
|
61464
|
+
k += 5;
|
|
61465
|
+
}
|
|
61466
|
+
guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
|
|
61467
|
+
wpr += guard;
|
|
61468
|
+
denominator = pow2 = sum2 = new Ctor(1);
|
|
61469
|
+
Ctor.precision = wpr;
|
|
61470
|
+
for (; ; ) {
|
|
61471
|
+
pow2 = finalise(pow2.times(x), wpr, 1);
|
|
61472
|
+
denominator = denominator.times(++i);
|
|
61473
|
+
t = sum2.plus(divide(pow2, denominator, wpr, 1));
|
|
61474
|
+
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
|
61475
|
+
j = k;
|
|
61476
|
+
while (j--) sum2 = finalise(sum2.times(sum2), wpr, 1);
|
|
61477
|
+
if (sd == null) {
|
|
61478
|
+
if (rep < 3 && checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
|
61479
|
+
Ctor.precision = wpr += 10;
|
|
61480
|
+
denominator = pow2 = t = new Ctor(1);
|
|
61481
|
+
i = 0;
|
|
61482
|
+
rep++;
|
|
61483
|
+
} else {
|
|
61484
|
+
return finalise(sum2, Ctor.precision = pr, rm, external = true);
|
|
61485
|
+
}
|
|
61486
|
+
} else {
|
|
61487
|
+
Ctor.precision = pr;
|
|
61488
|
+
return sum2;
|
|
61489
|
+
}
|
|
61490
|
+
}
|
|
61491
|
+
sum2 = t;
|
|
61492
|
+
}
|
|
61493
|
+
}
|
|
61494
|
+
function naturalLogarithm(y, sd) {
|
|
61495
|
+
var c, c0, denominator, e, numerator, rep, sum2, t, wpr, x1, x2, n = 1, guard = 10, x = y, xd = x.d, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
|
61496
|
+
if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
|
|
61497
|
+
return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
|
|
61498
|
+
}
|
|
61499
|
+
if (sd == null) {
|
|
61500
|
+
external = false;
|
|
61501
|
+
wpr = pr;
|
|
61502
|
+
} else {
|
|
61503
|
+
wpr = sd;
|
|
61504
|
+
}
|
|
61505
|
+
Ctor.precision = wpr += guard;
|
|
61506
|
+
c = digitsToString(xd);
|
|
61507
|
+
c0 = c.charAt(0);
|
|
61508
|
+
if (Math.abs(e = x.e) < 15e14) {
|
|
61509
|
+
while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
|
|
61510
|
+
x = x.times(y);
|
|
61511
|
+
c = digitsToString(x.d);
|
|
61512
|
+
c0 = c.charAt(0);
|
|
61513
|
+
n++;
|
|
61514
|
+
}
|
|
61515
|
+
e = x.e;
|
|
61516
|
+
if (c0 > 1) {
|
|
61517
|
+
x = new Ctor("0." + c);
|
|
61518
|
+
e++;
|
|
61519
|
+
} else {
|
|
61520
|
+
x = new Ctor(c0 + "." + c.slice(1));
|
|
61521
|
+
}
|
|
61522
|
+
} else {
|
|
61523
|
+
t = getLn10(Ctor, wpr + 2, pr).times(e + "");
|
|
61524
|
+
x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
|
|
61525
|
+
Ctor.precision = pr;
|
|
61526
|
+
return sd == null ? finalise(x, pr, rm, external = true) : x;
|
|
61527
|
+
}
|
|
61528
|
+
x1 = x;
|
|
61529
|
+
sum2 = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
|
|
61530
|
+
x2 = finalise(x.times(x), wpr, 1);
|
|
61531
|
+
denominator = 3;
|
|
61532
|
+
for (; ; ) {
|
|
61533
|
+
numerator = finalise(numerator.times(x2), wpr, 1);
|
|
61534
|
+
t = sum2.plus(divide(numerator, new Ctor(denominator), wpr, 1));
|
|
61535
|
+
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
|
61536
|
+
sum2 = sum2.times(2);
|
|
61537
|
+
if (e !== 0) sum2 = sum2.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
|
|
61538
|
+
sum2 = divide(sum2, new Ctor(n), wpr, 1);
|
|
61539
|
+
if (sd == null) {
|
|
61540
|
+
if (checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
|
61541
|
+
Ctor.precision = wpr += guard;
|
|
61542
|
+
t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
|
|
61543
|
+
x2 = finalise(x.times(x), wpr, 1);
|
|
61544
|
+
denominator = rep = 1;
|
|
61545
|
+
} else {
|
|
61546
|
+
return finalise(sum2, Ctor.precision = pr, rm, external = true);
|
|
61547
|
+
}
|
|
61548
|
+
} else {
|
|
61549
|
+
Ctor.precision = pr;
|
|
61550
|
+
return sum2;
|
|
61551
|
+
}
|
|
61552
|
+
}
|
|
61553
|
+
sum2 = t;
|
|
61554
|
+
denominator += 2;
|
|
61555
|
+
}
|
|
61556
|
+
}
|
|
61557
|
+
function nonFiniteToString(x) {
|
|
61558
|
+
return String(x.s * x.s / 0);
|
|
61559
|
+
}
|
|
61560
|
+
function parseDecimal(x, str) {
|
|
61561
|
+
var e, i, len;
|
|
61562
|
+
if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
|
|
61563
|
+
if ((i = str.search(/e/i)) > 0) {
|
|
61564
|
+
if (e < 0) e = i;
|
|
61565
|
+
e += +str.slice(i + 1);
|
|
61566
|
+
str = str.substring(0, i);
|
|
61567
|
+
} else if (e < 0) {
|
|
61568
|
+
e = str.length;
|
|
61569
|
+
}
|
|
61570
|
+
for (i = 0; str.charCodeAt(i) === 48; i++) ;
|
|
61571
|
+
for (len = str.length; str.charCodeAt(len - 1) === 48; --len) ;
|
|
61572
|
+
str = str.slice(i, len);
|
|
61573
|
+
if (str) {
|
|
61574
|
+
len -= i;
|
|
61575
|
+
x.e = e = e - i - 1;
|
|
61576
|
+
x.d = [];
|
|
61577
|
+
i = (e + 1) % LOG_BASE;
|
|
61578
|
+
if (e < 0) i += LOG_BASE;
|
|
61579
|
+
if (i < len) {
|
|
61580
|
+
if (i) x.d.push(+str.slice(0, i));
|
|
61581
|
+
for (len -= LOG_BASE; i < len; ) x.d.push(+str.slice(i, i += LOG_BASE));
|
|
61582
|
+
str = str.slice(i);
|
|
61583
|
+
i = LOG_BASE - str.length;
|
|
61584
|
+
} else {
|
|
61585
|
+
i -= len;
|
|
61586
|
+
}
|
|
61587
|
+
for (; i--; ) str += "0";
|
|
61588
|
+
x.d.push(+str);
|
|
61589
|
+
if (external) {
|
|
61590
|
+
if (x.e > x.constructor.maxE) {
|
|
61591
|
+
x.d = null;
|
|
61592
|
+
x.e = NaN;
|
|
61593
|
+
} else if (x.e < x.constructor.minE) {
|
|
61594
|
+
x.e = 0;
|
|
61595
|
+
x.d = [0];
|
|
61596
|
+
}
|
|
61597
|
+
}
|
|
61598
|
+
} else {
|
|
61599
|
+
x.e = 0;
|
|
61600
|
+
x.d = [0];
|
|
61601
|
+
}
|
|
61602
|
+
return x;
|
|
61603
|
+
}
|
|
61604
|
+
function parseOther(x, str) {
|
|
61605
|
+
var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
|
|
61606
|
+
if (str.indexOf("_") > -1) {
|
|
61607
|
+
str = str.replace(/(\d)_(?=\d)/g, "$1");
|
|
61608
|
+
if (isDecimal.test(str)) return parseDecimal(x, str);
|
|
61609
|
+
} else if (str === "Infinity" || str === "NaN") {
|
|
61610
|
+
if (!+str) x.s = NaN;
|
|
61611
|
+
x.e = NaN;
|
|
61612
|
+
x.d = null;
|
|
61613
|
+
return x;
|
|
61614
|
+
}
|
|
61615
|
+
if (isHex.test(str)) {
|
|
61616
|
+
base = 16;
|
|
61617
|
+
str = str.toLowerCase();
|
|
61618
|
+
} else if (isBinary.test(str)) {
|
|
61619
|
+
base = 2;
|
|
61620
|
+
} else if (isOctal.test(str)) {
|
|
61621
|
+
base = 8;
|
|
61622
|
+
} else {
|
|
61623
|
+
throw Error(invalidArgument + str);
|
|
61624
|
+
}
|
|
61625
|
+
i = str.search(/p/i);
|
|
61626
|
+
if (i > 0) {
|
|
61627
|
+
p = +str.slice(i + 1);
|
|
61628
|
+
str = str.substring(2, i);
|
|
61629
|
+
} else {
|
|
61630
|
+
str = str.slice(2);
|
|
61631
|
+
}
|
|
61632
|
+
i = str.indexOf(".");
|
|
61633
|
+
isFloat = i >= 0;
|
|
61634
|
+
Ctor = x.constructor;
|
|
61635
|
+
if (isFloat) {
|
|
61636
|
+
str = str.replace(".", "");
|
|
61637
|
+
len = str.length;
|
|
61638
|
+
i = len - i;
|
|
61639
|
+
divisor = intPow(Ctor, new Ctor(base), i, i * 2);
|
|
61640
|
+
}
|
|
61641
|
+
xd = convertBase(str, base, BASE);
|
|
61642
|
+
xe = xd.length - 1;
|
|
61643
|
+
for (i = xe; xd[i] === 0; --i) xd.pop();
|
|
61644
|
+
if (i < 0) return new Ctor(x.s * 0);
|
|
61645
|
+
x.e = getBase10Exponent(xd, xe);
|
|
61646
|
+
x.d = xd;
|
|
61647
|
+
external = false;
|
|
61648
|
+
if (isFloat) x = divide(x, divisor, len * 4);
|
|
61649
|
+
if (p) x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
|
|
61650
|
+
external = true;
|
|
61651
|
+
return x;
|
|
61652
|
+
}
|
|
61653
|
+
function sine(Ctor, x) {
|
|
61654
|
+
var k, len = x.d.length;
|
|
61655
|
+
if (len < 3) {
|
|
61656
|
+
return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
|
|
61657
|
+
}
|
|
61658
|
+
k = 1.4 * Math.sqrt(len);
|
|
61659
|
+
k = k > 16 ? 16 : k | 0;
|
|
61660
|
+
x = x.times(1 / tinyPow(5, k));
|
|
61661
|
+
x = taylorSeries(Ctor, 2, x, x);
|
|
61662
|
+
var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
61663
|
+
for (; k--; ) {
|
|
61664
|
+
sin2_x = x.times(x);
|
|
61665
|
+
x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
|
|
61666
|
+
}
|
|
61667
|
+
return x;
|
|
61668
|
+
}
|
|
61669
|
+
function taylorSeries(Ctor, n, x, y, isHyperbolic) {
|
|
61670
|
+
var j, t, u, x2, i = 1, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
|
|
61671
|
+
external = false;
|
|
61672
|
+
x2 = x.times(x);
|
|
61673
|
+
u = new Ctor(y);
|
|
61674
|
+
for (; ; ) {
|
|
61675
|
+
t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
|
|
61676
|
+
u = isHyperbolic ? y.plus(t) : y.minus(t);
|
|
61677
|
+
y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
|
|
61678
|
+
t = u.plus(y);
|
|
61679
|
+
if (t.d[k] !== void 0) {
|
|
61680
|
+
for (j = k; t.d[j] === u.d[j] && j--; ) ;
|
|
61681
|
+
if (j == -1) break;
|
|
61682
|
+
}
|
|
61683
|
+
j = u;
|
|
61684
|
+
u = y;
|
|
61685
|
+
y = t;
|
|
61686
|
+
t = j;
|
|
61687
|
+
i++;
|
|
61688
|
+
}
|
|
61689
|
+
external = true;
|
|
61690
|
+
t.d.length = k + 1;
|
|
61691
|
+
return t;
|
|
61692
|
+
}
|
|
61693
|
+
function tinyPow(b, e) {
|
|
61694
|
+
var n = b;
|
|
61695
|
+
while (--e) n *= b;
|
|
61696
|
+
return n;
|
|
61697
|
+
}
|
|
61698
|
+
function toLessThanHalfPi(Ctor, x) {
|
|
61699
|
+
var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
|
|
61700
|
+
x = x.abs();
|
|
61701
|
+
if (x.lte(halfPi)) {
|
|
61702
|
+
quadrant = isNeg ? 4 : 1;
|
|
61703
|
+
return x;
|
|
61704
|
+
}
|
|
61705
|
+
t = x.divToInt(pi);
|
|
61706
|
+
if (t.isZero()) {
|
|
61707
|
+
quadrant = isNeg ? 3 : 2;
|
|
61708
|
+
} else {
|
|
61709
|
+
x = x.minus(t.times(pi));
|
|
61710
|
+
if (x.lte(halfPi)) {
|
|
61711
|
+
quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
|
|
61712
|
+
return x;
|
|
61713
|
+
}
|
|
61714
|
+
quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
|
|
61715
|
+
}
|
|
61716
|
+
return x.minus(pi).abs();
|
|
61717
|
+
}
|
|
61718
|
+
function toStringBinary(x, baseOut, sd, rm) {
|
|
61719
|
+
var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== void 0;
|
|
61720
|
+
if (isExp) {
|
|
61721
|
+
checkInt32(sd, 1, MAX_DIGITS);
|
|
61722
|
+
if (rm === void 0) rm = Ctor.rounding;
|
|
61723
|
+
else checkInt32(rm, 0, 8);
|
|
61724
|
+
} else {
|
|
61725
|
+
sd = Ctor.precision;
|
|
61726
|
+
rm = Ctor.rounding;
|
|
61727
|
+
}
|
|
61728
|
+
if (!x.isFinite()) {
|
|
61729
|
+
str = nonFiniteToString(x);
|
|
61730
|
+
} else {
|
|
61731
|
+
str = finiteToString(x);
|
|
61732
|
+
i = str.indexOf(".");
|
|
61733
|
+
if (isExp) {
|
|
61734
|
+
base = 2;
|
|
61735
|
+
if (baseOut == 16) {
|
|
61736
|
+
sd = sd * 4 - 3;
|
|
61737
|
+
} else if (baseOut == 8) {
|
|
61738
|
+
sd = sd * 3 - 2;
|
|
61739
|
+
}
|
|
61740
|
+
} else {
|
|
61741
|
+
base = baseOut;
|
|
61742
|
+
}
|
|
61743
|
+
if (i >= 0) {
|
|
61744
|
+
str = str.replace(".", "");
|
|
61745
|
+
y = new Ctor(1);
|
|
61746
|
+
y.e = str.length - i;
|
|
61747
|
+
y.d = convertBase(finiteToString(y), 10, base);
|
|
61748
|
+
y.e = y.d.length;
|
|
61749
|
+
}
|
|
61750
|
+
xd = convertBase(str, 10, base);
|
|
61751
|
+
e = len = xd.length;
|
|
61752
|
+
for (; xd[--len] == 0; ) xd.pop();
|
|
61753
|
+
if (!xd[0]) {
|
|
61754
|
+
str = isExp ? "0p+0" : "0";
|
|
61755
|
+
} else {
|
|
61756
|
+
if (i < 0) {
|
|
61757
|
+
e--;
|
|
61758
|
+
} else {
|
|
61759
|
+
x = new Ctor(x);
|
|
61760
|
+
x.d = xd;
|
|
61761
|
+
x.e = e;
|
|
61762
|
+
x = divide(x, y, sd, rm, 0, base);
|
|
61763
|
+
xd = x.d;
|
|
61764
|
+
e = x.e;
|
|
61765
|
+
roundUp = inexact;
|
|
61766
|
+
}
|
|
61767
|
+
i = xd[sd];
|
|
61768
|
+
k = base / 2;
|
|
61769
|
+
roundUp = roundUp || xd[sd + 1] !== void 0;
|
|
61770
|
+
roundUp = rm < 4 ? (i !== void 0 || roundUp) && (rm === 0 || rm === (x.s < 0 ? 3 : 2)) : i > k || i === k && (rm === 4 || roundUp || rm === 6 && xd[sd - 1] & 1 || rm === (x.s < 0 ? 8 : 7));
|
|
61771
|
+
xd.length = sd;
|
|
61772
|
+
if (roundUp) {
|
|
61773
|
+
for (; ++xd[--sd] > base - 1; ) {
|
|
61774
|
+
xd[sd] = 0;
|
|
61775
|
+
if (!sd) {
|
|
61776
|
+
++e;
|
|
61777
|
+
xd.unshift(1);
|
|
61778
|
+
}
|
|
61779
|
+
}
|
|
61780
|
+
}
|
|
61781
|
+
for (len = xd.length; !xd[len - 1]; --len) ;
|
|
61782
|
+
for (i = 0, str = ""; i < len; i++) str += NUMERALS.charAt(xd[i]);
|
|
61783
|
+
if (isExp) {
|
|
61784
|
+
if (len > 1) {
|
|
61785
|
+
if (baseOut == 16 || baseOut == 8) {
|
|
61786
|
+
i = baseOut == 16 ? 4 : 3;
|
|
61787
|
+
for (--len; len % i; len++) str += "0";
|
|
61788
|
+
xd = convertBase(str, base, baseOut);
|
|
61789
|
+
for (len = xd.length; !xd[len - 1]; --len) ;
|
|
61790
|
+
for (i = 1, str = "1."; i < len; i++) str += NUMERALS.charAt(xd[i]);
|
|
61791
|
+
} else {
|
|
61792
|
+
str = str.charAt(0) + "." + str.slice(1);
|
|
61793
|
+
}
|
|
61794
|
+
}
|
|
61795
|
+
str = str + (e < 0 ? "p" : "p+") + e;
|
|
61796
|
+
} else if (e < 0) {
|
|
61797
|
+
for (; ++e; ) str = "0" + str;
|
|
61798
|
+
str = "0." + str;
|
|
61799
|
+
} else {
|
|
61800
|
+
if (++e > len) for (e -= len; e--; ) str += "0";
|
|
61801
|
+
else if (e < len) str = str.slice(0, e) + "." + str.slice(e);
|
|
61802
|
+
}
|
|
61803
|
+
}
|
|
61804
|
+
str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
|
|
61805
|
+
}
|
|
61806
|
+
return x.s < 0 ? "-" + str : str;
|
|
61807
|
+
}
|
|
61808
|
+
function truncate(arr, len) {
|
|
61809
|
+
if (arr.length > len) {
|
|
61810
|
+
arr.length = len;
|
|
61811
|
+
return true;
|
|
61812
|
+
}
|
|
61813
|
+
}
|
|
61814
|
+
function abs(x) {
|
|
61815
|
+
return new this(x).abs();
|
|
61816
|
+
}
|
|
61817
|
+
function acos(x) {
|
|
61818
|
+
return new this(x).acos();
|
|
61819
|
+
}
|
|
61820
|
+
function acosh(x) {
|
|
61821
|
+
return new this(x).acosh();
|
|
61822
|
+
}
|
|
61823
|
+
function add(x, y) {
|
|
61824
|
+
return new this(x).plus(y);
|
|
61825
|
+
}
|
|
61826
|
+
function asin(x) {
|
|
61827
|
+
return new this(x).asin();
|
|
61828
|
+
}
|
|
61829
|
+
function asinh(x) {
|
|
61830
|
+
return new this(x).asinh();
|
|
61831
|
+
}
|
|
61832
|
+
function atan(x) {
|
|
61833
|
+
return new this(x).atan();
|
|
61834
|
+
}
|
|
61835
|
+
function atanh(x) {
|
|
61836
|
+
return new this(x).atanh();
|
|
61837
|
+
}
|
|
61838
|
+
function atan2(y, x) {
|
|
61839
|
+
y = new this(y);
|
|
61840
|
+
x = new this(x);
|
|
61841
|
+
var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
|
|
61842
|
+
if (!y.s || !x.s) {
|
|
61843
|
+
r = new this(NaN);
|
|
61844
|
+
} else if (!y.d && !x.d) {
|
|
61845
|
+
r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
|
|
61846
|
+
r.s = y.s;
|
|
61847
|
+
} else if (!x.d || y.isZero()) {
|
|
61848
|
+
r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
|
|
61849
|
+
r.s = y.s;
|
|
61850
|
+
} else if (!y.d || x.isZero()) {
|
|
61851
|
+
r = getPi(this, wpr, 1).times(0.5);
|
|
61852
|
+
r.s = y.s;
|
|
61853
|
+
} else if (x.s < 0) {
|
|
61854
|
+
this.precision = wpr;
|
|
61855
|
+
this.rounding = 1;
|
|
61856
|
+
r = this.atan(divide(y, x, wpr, 1));
|
|
61857
|
+
x = getPi(this, wpr, 1);
|
|
61858
|
+
this.precision = pr;
|
|
61859
|
+
this.rounding = rm;
|
|
61860
|
+
r = y.s < 0 ? r.minus(x) : r.plus(x);
|
|
61861
|
+
} else {
|
|
61862
|
+
r = this.atan(divide(y, x, wpr, 1));
|
|
61863
|
+
}
|
|
61864
|
+
return r;
|
|
61865
|
+
}
|
|
61866
|
+
function cbrt(x) {
|
|
61867
|
+
return new this(x).cbrt();
|
|
61868
|
+
}
|
|
61869
|
+
function ceil(x) {
|
|
61870
|
+
return finalise(x = new this(x), x.e + 1, 2);
|
|
61871
|
+
}
|
|
61872
|
+
function clamp(x, min2, max2) {
|
|
61873
|
+
return new this(x).clamp(min2, max2);
|
|
61874
|
+
}
|
|
61875
|
+
function config3(obj) {
|
|
61876
|
+
if (!obj || typeof obj !== "object") throw Error(decimalError + "Object expected");
|
|
61877
|
+
var i, p, v, useDefaults = obj.defaults === true, ps = [
|
|
61878
|
+
"precision",
|
|
61879
|
+
1,
|
|
61880
|
+
MAX_DIGITS,
|
|
61881
|
+
"rounding",
|
|
61882
|
+
0,
|
|
61883
|
+
8,
|
|
61884
|
+
"toExpNeg",
|
|
61885
|
+
-EXP_LIMIT,
|
|
61886
|
+
0,
|
|
61887
|
+
"toExpPos",
|
|
61888
|
+
0,
|
|
61889
|
+
EXP_LIMIT,
|
|
61890
|
+
"maxE",
|
|
61891
|
+
0,
|
|
61892
|
+
EXP_LIMIT,
|
|
61893
|
+
"minE",
|
|
61894
|
+
-EXP_LIMIT,
|
|
61895
|
+
0,
|
|
61896
|
+
"modulo",
|
|
61897
|
+
0,
|
|
61898
|
+
9
|
|
61899
|
+
];
|
|
61900
|
+
for (i = 0; i < ps.length; i += 3) {
|
|
61901
|
+
if (p = ps[i], useDefaults) this[p] = DEFAULTS[p];
|
|
61902
|
+
if ((v = obj[p]) !== void 0) {
|
|
61903
|
+
if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2]) this[p] = v;
|
|
61904
|
+
else throw Error(invalidArgument + p + ": " + v);
|
|
61905
|
+
}
|
|
61906
|
+
}
|
|
61907
|
+
if (p = "crypto", useDefaults) this[p] = DEFAULTS[p];
|
|
61908
|
+
if ((v = obj[p]) !== void 0) {
|
|
61909
|
+
if (v === true || v === false || v === 0 || v === 1) {
|
|
61910
|
+
if (v) {
|
|
61911
|
+
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
|
61912
|
+
this[p] = true;
|
|
61913
|
+
} else {
|
|
61914
|
+
throw Error(cryptoUnavailable);
|
|
61915
|
+
}
|
|
61916
|
+
} else {
|
|
61917
|
+
this[p] = false;
|
|
61918
|
+
}
|
|
61919
|
+
} else {
|
|
61920
|
+
throw Error(invalidArgument + p + ": " + v);
|
|
61921
|
+
}
|
|
61922
|
+
}
|
|
61923
|
+
return this;
|
|
61924
|
+
}
|
|
61925
|
+
function cos(x) {
|
|
61926
|
+
return new this(x).cos();
|
|
61927
|
+
}
|
|
61928
|
+
function cosh(x) {
|
|
61929
|
+
return new this(x).cosh();
|
|
61930
|
+
}
|
|
61931
|
+
function clone2(obj) {
|
|
61932
|
+
var i, p, ps;
|
|
61933
|
+
function Decimal2(v) {
|
|
61934
|
+
var e, i2, t, x = this;
|
|
61935
|
+
if (!(x instanceof Decimal2)) return new Decimal2(v);
|
|
61936
|
+
x.constructor = Decimal2;
|
|
61937
|
+
if (isDecimalInstance(v)) {
|
|
61938
|
+
x.s = v.s;
|
|
61939
|
+
if (external) {
|
|
61940
|
+
if (!v.d || v.e > Decimal2.maxE) {
|
|
61941
|
+
x.e = NaN;
|
|
61942
|
+
x.d = null;
|
|
61943
|
+
} else if (v.e < Decimal2.minE) {
|
|
61944
|
+
x.e = 0;
|
|
61945
|
+
x.d = [0];
|
|
61946
|
+
} else {
|
|
61947
|
+
x.e = v.e;
|
|
61948
|
+
x.d = v.d.slice();
|
|
61949
|
+
}
|
|
61950
|
+
} else {
|
|
61951
|
+
x.e = v.e;
|
|
61952
|
+
x.d = v.d ? v.d.slice() : v.d;
|
|
61953
|
+
}
|
|
61954
|
+
return;
|
|
61955
|
+
}
|
|
61956
|
+
t = typeof v;
|
|
61957
|
+
if (t === "number") {
|
|
61958
|
+
if (v === 0) {
|
|
61959
|
+
x.s = 1 / v < 0 ? -1 : 1;
|
|
61960
|
+
x.e = 0;
|
|
61961
|
+
x.d = [0];
|
|
61962
|
+
return;
|
|
61963
|
+
}
|
|
61964
|
+
if (v < 0) {
|
|
61965
|
+
v = -v;
|
|
61966
|
+
x.s = -1;
|
|
61967
|
+
} else {
|
|
61968
|
+
x.s = 1;
|
|
61969
|
+
}
|
|
61970
|
+
if (v === ~~v && v < 1e7) {
|
|
61971
|
+
for (e = 0, i2 = v; i2 >= 10; i2 /= 10) e++;
|
|
61972
|
+
if (external) {
|
|
61973
|
+
if (e > Decimal2.maxE) {
|
|
61974
|
+
x.e = NaN;
|
|
61975
|
+
x.d = null;
|
|
61976
|
+
} else if (e < Decimal2.minE) {
|
|
61977
|
+
x.e = 0;
|
|
61978
|
+
x.d = [0];
|
|
61979
|
+
} else {
|
|
61980
|
+
x.e = e;
|
|
61981
|
+
x.d = [v];
|
|
61982
|
+
}
|
|
61983
|
+
} else {
|
|
61984
|
+
x.e = e;
|
|
61985
|
+
x.d = [v];
|
|
61986
|
+
}
|
|
61987
|
+
return;
|
|
61988
|
+
}
|
|
61989
|
+
if (v * 0 !== 0) {
|
|
61990
|
+
if (!v) x.s = NaN;
|
|
61991
|
+
x.e = NaN;
|
|
61992
|
+
x.d = null;
|
|
61993
|
+
return;
|
|
61994
|
+
}
|
|
61995
|
+
return parseDecimal(x, v.toString());
|
|
61996
|
+
}
|
|
61997
|
+
if (t === "string") {
|
|
61998
|
+
if ((i2 = v.charCodeAt(0)) === 45) {
|
|
61999
|
+
v = v.slice(1);
|
|
62000
|
+
x.s = -1;
|
|
62001
|
+
} else {
|
|
62002
|
+
if (i2 === 43) v = v.slice(1);
|
|
62003
|
+
x.s = 1;
|
|
62004
|
+
}
|
|
62005
|
+
return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
|
|
62006
|
+
}
|
|
62007
|
+
if (t === "bigint") {
|
|
62008
|
+
if (v < 0) {
|
|
62009
|
+
v = -v;
|
|
62010
|
+
x.s = -1;
|
|
62011
|
+
} else {
|
|
62012
|
+
x.s = 1;
|
|
62013
|
+
}
|
|
62014
|
+
return parseDecimal(x, v.toString());
|
|
62015
|
+
}
|
|
62016
|
+
throw Error(invalidArgument + v);
|
|
62017
|
+
}
|
|
62018
|
+
Decimal2.prototype = P;
|
|
62019
|
+
Decimal2.ROUND_UP = 0;
|
|
62020
|
+
Decimal2.ROUND_DOWN = 1;
|
|
62021
|
+
Decimal2.ROUND_CEIL = 2;
|
|
62022
|
+
Decimal2.ROUND_FLOOR = 3;
|
|
62023
|
+
Decimal2.ROUND_HALF_UP = 4;
|
|
62024
|
+
Decimal2.ROUND_HALF_DOWN = 5;
|
|
62025
|
+
Decimal2.ROUND_HALF_EVEN = 6;
|
|
62026
|
+
Decimal2.ROUND_HALF_CEIL = 7;
|
|
62027
|
+
Decimal2.ROUND_HALF_FLOOR = 8;
|
|
62028
|
+
Decimal2.EUCLID = 9;
|
|
62029
|
+
Decimal2.config = Decimal2.set = config3;
|
|
62030
|
+
Decimal2.clone = clone2;
|
|
62031
|
+
Decimal2.isDecimal = isDecimalInstance;
|
|
62032
|
+
Decimal2.abs = abs;
|
|
62033
|
+
Decimal2.acos = acos;
|
|
62034
|
+
Decimal2.acosh = acosh;
|
|
62035
|
+
Decimal2.add = add;
|
|
62036
|
+
Decimal2.asin = asin;
|
|
62037
|
+
Decimal2.asinh = asinh;
|
|
62038
|
+
Decimal2.atan = atan;
|
|
62039
|
+
Decimal2.atanh = atanh;
|
|
62040
|
+
Decimal2.atan2 = atan2;
|
|
62041
|
+
Decimal2.cbrt = cbrt;
|
|
62042
|
+
Decimal2.ceil = ceil;
|
|
62043
|
+
Decimal2.clamp = clamp;
|
|
62044
|
+
Decimal2.cos = cos;
|
|
62045
|
+
Decimal2.cosh = cosh;
|
|
62046
|
+
Decimal2.div = div;
|
|
62047
|
+
Decimal2.exp = exp;
|
|
62048
|
+
Decimal2.floor = floor;
|
|
62049
|
+
Decimal2.hypot = hypot;
|
|
62050
|
+
Decimal2.ln = ln;
|
|
62051
|
+
Decimal2.log = log;
|
|
62052
|
+
Decimal2.log10 = log10;
|
|
62053
|
+
Decimal2.log2 = log2;
|
|
62054
|
+
Decimal2.max = max;
|
|
62055
|
+
Decimal2.min = min;
|
|
62056
|
+
Decimal2.mod = mod;
|
|
62057
|
+
Decimal2.mul = mul;
|
|
62058
|
+
Decimal2.pow = pow;
|
|
62059
|
+
Decimal2.random = random;
|
|
62060
|
+
Decimal2.round = round;
|
|
62061
|
+
Decimal2.sign = sign;
|
|
62062
|
+
Decimal2.sin = sin;
|
|
62063
|
+
Decimal2.sinh = sinh;
|
|
62064
|
+
Decimal2.sqrt = sqrt;
|
|
62065
|
+
Decimal2.sub = sub;
|
|
62066
|
+
Decimal2.sum = sum;
|
|
62067
|
+
Decimal2.tan = tan;
|
|
62068
|
+
Decimal2.tanh = tanh;
|
|
62069
|
+
Decimal2.trunc = trunc;
|
|
62070
|
+
if (obj === void 0) obj = {};
|
|
62071
|
+
if (obj) {
|
|
62072
|
+
if (obj.defaults !== true) {
|
|
62073
|
+
ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
|
|
62074
|
+
for (i = 0; i < ps.length; ) if (!obj.hasOwnProperty(p = ps[i++])) obj[p] = this[p];
|
|
62075
|
+
}
|
|
62076
|
+
}
|
|
62077
|
+
Decimal2.config(obj);
|
|
62078
|
+
return Decimal2;
|
|
62079
|
+
}
|
|
62080
|
+
function div(x, y) {
|
|
62081
|
+
return new this(x).div(y);
|
|
62082
|
+
}
|
|
62083
|
+
function exp(x) {
|
|
62084
|
+
return new this(x).exp();
|
|
62085
|
+
}
|
|
62086
|
+
function floor(x) {
|
|
62087
|
+
return finalise(x = new this(x), x.e + 1, 3);
|
|
62088
|
+
}
|
|
62089
|
+
function hypot() {
|
|
62090
|
+
var i, n, t = new this(0);
|
|
62091
|
+
external = false;
|
|
62092
|
+
for (i = 0; i < arguments.length; ) {
|
|
62093
|
+
n = new this(arguments[i++]);
|
|
62094
|
+
if (!n.d) {
|
|
62095
|
+
if (n.s) {
|
|
62096
|
+
external = true;
|
|
62097
|
+
return new this(1 / 0);
|
|
62098
|
+
}
|
|
62099
|
+
t = n;
|
|
62100
|
+
} else if (t.d) {
|
|
62101
|
+
t = t.plus(n.times(n));
|
|
62102
|
+
}
|
|
62103
|
+
}
|
|
62104
|
+
external = true;
|
|
62105
|
+
return t.sqrt();
|
|
62106
|
+
}
|
|
62107
|
+
function isDecimalInstance(obj) {
|
|
62108
|
+
return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
|
|
62109
|
+
}
|
|
62110
|
+
function ln(x) {
|
|
62111
|
+
return new this(x).ln();
|
|
62112
|
+
}
|
|
62113
|
+
function log(x, y) {
|
|
62114
|
+
return new this(x).log(y);
|
|
62115
|
+
}
|
|
62116
|
+
function log2(x) {
|
|
62117
|
+
return new this(x).log(2);
|
|
62118
|
+
}
|
|
62119
|
+
function log10(x) {
|
|
62120
|
+
return new this(x).log(10);
|
|
62121
|
+
}
|
|
62122
|
+
function max() {
|
|
62123
|
+
return maxOrMin(this, arguments, -1);
|
|
62124
|
+
}
|
|
62125
|
+
function min() {
|
|
62126
|
+
return maxOrMin(this, arguments, 1);
|
|
62127
|
+
}
|
|
62128
|
+
function mod(x, y) {
|
|
62129
|
+
return new this(x).mod(y);
|
|
62130
|
+
}
|
|
62131
|
+
function mul(x, y) {
|
|
62132
|
+
return new this(x).mul(y);
|
|
62133
|
+
}
|
|
62134
|
+
function pow(x, y) {
|
|
62135
|
+
return new this(x).pow(y);
|
|
62136
|
+
}
|
|
62137
|
+
function random(sd) {
|
|
62138
|
+
var d, e, k, n, i = 0, r = new this(1), rd = [];
|
|
62139
|
+
if (sd === void 0) sd = this.precision;
|
|
62140
|
+
else checkInt32(sd, 1, MAX_DIGITS);
|
|
62141
|
+
k = Math.ceil(sd / LOG_BASE);
|
|
62142
|
+
if (!this.crypto) {
|
|
62143
|
+
for (; i < k; ) rd[i++] = Math.random() * 1e7 | 0;
|
|
62144
|
+
} else if (crypto.getRandomValues) {
|
|
62145
|
+
d = crypto.getRandomValues(new Uint32Array(k));
|
|
62146
|
+
for (; i < k; ) {
|
|
62147
|
+
n = d[i];
|
|
62148
|
+
if (n >= 429e7) {
|
|
62149
|
+
d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
|
|
62150
|
+
} else {
|
|
62151
|
+
rd[i++] = n % 1e7;
|
|
62152
|
+
}
|
|
62153
|
+
}
|
|
62154
|
+
} else if (crypto.randomBytes) {
|
|
62155
|
+
d = crypto.randomBytes(k *= 4);
|
|
62156
|
+
for (; i < k; ) {
|
|
62157
|
+
n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
|
|
62158
|
+
if (n >= 214e7) {
|
|
62159
|
+
crypto.randomBytes(4).copy(d, i);
|
|
62160
|
+
} else {
|
|
62161
|
+
rd.push(n % 1e7);
|
|
62162
|
+
i += 4;
|
|
62163
|
+
}
|
|
62164
|
+
}
|
|
62165
|
+
i = k / 4;
|
|
62166
|
+
} else {
|
|
62167
|
+
throw Error(cryptoUnavailable);
|
|
62168
|
+
}
|
|
62169
|
+
k = rd[--i];
|
|
62170
|
+
sd %= LOG_BASE;
|
|
62171
|
+
if (k && sd) {
|
|
62172
|
+
n = mathpow(10, LOG_BASE - sd);
|
|
62173
|
+
rd[i] = (k / n | 0) * n;
|
|
62174
|
+
}
|
|
62175
|
+
for (; rd[i] === 0; i--) rd.pop();
|
|
62176
|
+
if (i < 0) {
|
|
62177
|
+
e = 0;
|
|
62178
|
+
rd = [0];
|
|
62179
|
+
} else {
|
|
62180
|
+
e = -1;
|
|
62181
|
+
for (; rd[0] === 0; e -= LOG_BASE) rd.shift();
|
|
62182
|
+
for (k = 1, n = rd[0]; n >= 10; n /= 10) k++;
|
|
62183
|
+
if (k < LOG_BASE) e -= LOG_BASE - k;
|
|
62184
|
+
}
|
|
62185
|
+
r.e = e;
|
|
62186
|
+
r.d = rd;
|
|
62187
|
+
return r;
|
|
62188
|
+
}
|
|
62189
|
+
function round(x) {
|
|
62190
|
+
return finalise(x = new this(x), x.e + 1, this.rounding);
|
|
62191
|
+
}
|
|
62192
|
+
function sign(x) {
|
|
62193
|
+
x = new this(x);
|
|
62194
|
+
return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
|
|
62195
|
+
}
|
|
62196
|
+
function sin(x) {
|
|
62197
|
+
return new this(x).sin();
|
|
62198
|
+
}
|
|
62199
|
+
function sinh(x) {
|
|
62200
|
+
return new this(x).sinh();
|
|
62201
|
+
}
|
|
62202
|
+
function sqrt(x) {
|
|
62203
|
+
return new this(x).sqrt();
|
|
62204
|
+
}
|
|
62205
|
+
function sub(x, y) {
|
|
62206
|
+
return new this(x).sub(y);
|
|
62207
|
+
}
|
|
62208
|
+
function sum() {
|
|
62209
|
+
var i = 0, args = arguments, x = new this(args[i]);
|
|
62210
|
+
external = false;
|
|
62211
|
+
for (; x.s && ++i < args.length; ) x = x.plus(args[i]);
|
|
62212
|
+
external = true;
|
|
62213
|
+
return finalise(x, this.precision, this.rounding);
|
|
62214
|
+
}
|
|
62215
|
+
function tan(x) {
|
|
62216
|
+
return new this(x).tan();
|
|
62217
|
+
}
|
|
62218
|
+
function tanh(x) {
|
|
62219
|
+
return new this(x).tanh();
|
|
62220
|
+
}
|
|
62221
|
+
function trunc(x) {
|
|
62222
|
+
return finalise(x = new this(x), x.e + 1, 1);
|
|
62223
|
+
}
|
|
62224
|
+
P[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = P.toString;
|
|
62225
|
+
P[Symbol.toStringTag] = "Decimal";
|
|
62226
|
+
var Decimal = P.constructor = clone2(DEFAULTS);
|
|
62227
|
+
LN10 = new Decimal(LN10);
|
|
62228
|
+
PI = new Decimal(PI);
|
|
62229
62229
|
|
|
62230
62230
|
// ../hyperline-lib/build/utils/config/usStates.js
|
|
62231
62231
|
var usStates = [
|