@naturalcycles/abba 1.7.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abba.d.ts +45 -72
- package/dist/abba.js +119 -165
- package/dist/dao/bucket.dao.d.ts +5 -0
- package/dist/dao/bucket.dao.js +15 -0
- package/dist/dao/experiment.dao.d.ts +10 -0
- package/dist/dao/experiment.dao.js +19 -0
- package/dist/dao/userAssignment.dao.d.ts +5 -0
- package/dist/dao/userAssignment.dao.js +15 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -1
- package/dist/migrations/init.sql +47 -0
- package/dist/types.d.ts +30 -7
- package/dist/util.d.ts +5 -21
- package/dist/util.js +0 -16
- package/package.json +9 -9
- package/readme.md +14 -15
- package/src/abba.ts +160 -191
- package/src/dao/bucket.dao.ts +13 -0
- package/src/dao/experiment.dao.ts +22 -0
- package/src/dao/userAssignment.dao.ts +13 -0
- package/src/index.ts +0 -3
- package/src/migrations/init.sql +47 -0
- package/src/types.ts +41 -7
- package/src/util.ts +5 -21
- package/dist/prisma-output/index-browser.js +0 -141
- package/dist/prisma-output/index.d.ts +0 -5526
- package/dist/prisma-output/index.js +0 -217
- package/dist/prisma-output/libquery_engine-darwin-arm64.dylib.node +0 -0
- package/dist/prisma-output/libquery_engine-darwin.dylib.node +0 -0
- package/dist/prisma-output/libquery_engine-debian-openssl-1.1.x.so.node +0 -0
- package/dist/prisma-output/libquery_engine-debian-openssl-3.0.x.so.node +0 -0
- package/dist/prisma-output/runtime/esm/index-browser.mjs +0 -2370
- package/dist/prisma-output/runtime/esm/index.mjs +0 -40587
- package/dist/prisma-output/runtime/esm/proxy.mjs +0 -113
- package/dist/prisma-output/runtime/index-browser.d.ts +0 -269
- package/dist/prisma-output/runtime/index-browser.js +0 -2621
- package/dist/prisma-output/runtime/index.d.ts +0 -1384
- package/dist/prisma-output/runtime/index.js +0 -59183
- package/dist/prisma-output/runtime/proxy.d.ts +0 -1384
- package/dist/prisma-output/runtime/proxy.js +0 -13576
- package/dist/prisma-output/schema.prisma +0 -47
- package/src/prisma-output/index-browser.js +0 -141
- package/src/prisma-output/index.d.ts +0 -5526
- package/src/prisma-output/index.js +0 -217
- package/src/prisma-output/libquery_engine-darwin-arm64.dylib.node +0 -0
- package/src/prisma-output/libquery_engine-darwin.dylib.node +0 -0
- package/src/prisma-output/libquery_engine-debian-openssl-1.1.x.so.node +0 -0
- package/src/prisma-output/libquery_engine-debian-openssl-3.0.x.so.node +0 -0
- package/src/prisma-output/runtime/esm/index-browser.mjs +0 -2370
- package/src/prisma-output/runtime/esm/index.mjs +0 -40587
- package/src/prisma-output/runtime/esm/proxy.mjs +0 -113
- package/src/prisma-output/runtime/index-browser.d.ts +0 -269
- package/src/prisma-output/runtime/index-browser.js +0 -2621
- package/src/prisma-output/runtime/index.d.ts +0 -1384
- package/src/prisma-output/runtime/index.js +0 -59183
- package/src/prisma-output/runtime/proxy.d.ts +0 -1384
- package/src/prisma-output/runtime/proxy.js +0 -13576
- package/src/prisma-output/schema.prisma +0 -47
|
@@ -1,2621 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty
|
|
2
|
-
var __markAsModule = target => __defProp(target, '__esModule', { value: true })
|
|
3
|
-
var __name = (target, value) => __defProp(target, 'name', { value, configurable: true })
|
|
4
|
-
var __export = (target, all) => {
|
|
5
|
-
__markAsModule(target)
|
|
6
|
-
for (var name in all) __defProp(target, name, { get: all[name], enumerable: true })
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// esm/runtime/index-browser.mjs
|
|
10
|
-
__export(exports, {
|
|
11
|
-
Decimal: () => decimal_default,
|
|
12
|
-
})
|
|
13
|
-
var __defProp2 = Object.defineProperty
|
|
14
|
-
var __name2 = /* @__PURE__ */ __name(
|
|
15
|
-
(target, value) => __defProp2(target, 'name', { value, configurable: true }),
|
|
16
|
-
'__name',
|
|
17
|
-
)
|
|
18
|
-
var EXP_LIMIT = 9e15
|
|
19
|
-
var MAX_DIGITS = 1e9
|
|
20
|
-
var NUMERALS = '0123456789abcdef'
|
|
21
|
-
var LN10 =
|
|
22
|
-
'2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058'
|
|
23
|
-
var PI =
|
|
24
|
-
'3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789'
|
|
25
|
-
var DEFAULTS = {
|
|
26
|
-
precision: 20,
|
|
27
|
-
rounding: 4,
|
|
28
|
-
modulo: 1,
|
|
29
|
-
toExpNeg: -7,
|
|
30
|
-
toExpPos: 21,
|
|
31
|
-
minE: -EXP_LIMIT,
|
|
32
|
-
maxE: EXP_LIMIT,
|
|
33
|
-
crypto: false,
|
|
34
|
-
}
|
|
35
|
-
var inexact
|
|
36
|
-
var quadrant
|
|
37
|
-
var external = true
|
|
38
|
-
var decimalError = '[DecimalError] '
|
|
39
|
-
var invalidArgument = decimalError + 'Invalid argument: '
|
|
40
|
-
var precisionLimitExceeded = decimalError + 'Precision limit exceeded'
|
|
41
|
-
var cryptoUnavailable = decimalError + 'crypto unavailable'
|
|
42
|
-
var tag = '[object Decimal]'
|
|
43
|
-
var mathfloor = Math.floor
|
|
44
|
-
var mathpow = Math.pow
|
|
45
|
-
var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i
|
|
46
|
-
var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i
|
|
47
|
-
var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i
|
|
48
|
-
var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i
|
|
49
|
-
var BASE = 1e7
|
|
50
|
-
var LOG_BASE = 7
|
|
51
|
-
var MAX_SAFE_INTEGER = 9007199254740991
|
|
52
|
-
var LN10_PRECISION = LN10.length - 1
|
|
53
|
-
var PI_PRECISION = PI.length - 1
|
|
54
|
-
var P = { toStringTag: tag }
|
|
55
|
-
P.absoluteValue = P.abs = function () {
|
|
56
|
-
var x = new this.constructor(this)
|
|
57
|
-
if (x.s < 0) x.s = 1
|
|
58
|
-
return finalise(x)
|
|
59
|
-
}
|
|
60
|
-
P.ceil = function () {
|
|
61
|
-
return finalise(new this.constructor(this), this.e + 1, 2)
|
|
62
|
-
}
|
|
63
|
-
P.clampedTo = P.clamp = function (min2, max2) {
|
|
64
|
-
var k,
|
|
65
|
-
x = this,
|
|
66
|
-
Ctor = x.constructor
|
|
67
|
-
min2 = new Ctor(min2)
|
|
68
|
-
max2 = new Ctor(max2)
|
|
69
|
-
if (!min2.s || !max2.s) return new Ctor(NaN)
|
|
70
|
-
if (min2.gt(max2)) throw Error(invalidArgument + max2)
|
|
71
|
-
k = x.cmp(min2)
|
|
72
|
-
return k < 0 ? min2 : x.cmp(max2) > 0 ? max2 : new Ctor(x)
|
|
73
|
-
}
|
|
74
|
-
P.comparedTo = P.cmp = function (y) {
|
|
75
|
-
var i,
|
|
76
|
-
j,
|
|
77
|
-
xdL,
|
|
78
|
-
ydL,
|
|
79
|
-
x = this,
|
|
80
|
-
xd = x.d,
|
|
81
|
-
yd = (y = new x.constructor(y)).d,
|
|
82
|
-
xs = x.s,
|
|
83
|
-
ys = y.s
|
|
84
|
-
if (!xd || !yd) {
|
|
85
|
-
return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ (xs < 0) ? 1 : -1
|
|
86
|
-
}
|
|
87
|
-
if (!xd[0] || !yd[0]) return xd[0] ? xs : yd[0] ? -ys : 0
|
|
88
|
-
if (xs !== ys) return xs
|
|
89
|
-
if (x.e !== y.e) return (x.e > y.e) ^ (xs < 0) ? 1 : -1
|
|
90
|
-
xdL = xd.length
|
|
91
|
-
ydL = yd.length
|
|
92
|
-
for (i = 0, j = xdL < ydL ? xdL : ydL; i < j; ++i) {
|
|
93
|
-
if (xd[i] !== yd[i]) return (xd[i] > yd[i]) ^ (xs < 0) ? 1 : -1
|
|
94
|
-
}
|
|
95
|
-
return xdL === ydL ? 0 : (xdL > ydL) ^ (xs < 0) ? 1 : -1
|
|
96
|
-
}
|
|
97
|
-
P.cosine = P.cos = function () {
|
|
98
|
-
var pr,
|
|
99
|
-
rm,
|
|
100
|
-
x = this,
|
|
101
|
-
Ctor = x.constructor
|
|
102
|
-
if (!x.d) return new Ctor(NaN)
|
|
103
|
-
if (!x.d[0]) return new Ctor(1)
|
|
104
|
-
pr = Ctor.precision
|
|
105
|
-
rm = Ctor.rounding
|
|
106
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE
|
|
107
|
-
Ctor.rounding = 1
|
|
108
|
-
x = cosine(Ctor, toLessThanHalfPi(Ctor, x))
|
|
109
|
-
Ctor.precision = pr
|
|
110
|
-
Ctor.rounding = rm
|
|
111
|
-
return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true)
|
|
112
|
-
}
|
|
113
|
-
P.cubeRoot = P.cbrt = function () {
|
|
114
|
-
var e,
|
|
115
|
-
m,
|
|
116
|
-
n,
|
|
117
|
-
r,
|
|
118
|
-
rep,
|
|
119
|
-
s,
|
|
120
|
-
sd,
|
|
121
|
-
t,
|
|
122
|
-
t3,
|
|
123
|
-
t3plusx,
|
|
124
|
-
x = this,
|
|
125
|
-
Ctor = x.constructor
|
|
126
|
-
if (!x.isFinite() || x.isZero()) return new Ctor(x)
|
|
127
|
-
external = false
|
|
128
|
-
s = x.s * mathpow(x.s * x, 1 / 3)
|
|
129
|
-
if (!s || Math.abs(s) == 1 / 0) {
|
|
130
|
-
n = digitsToString(x.d)
|
|
131
|
-
e = x.e
|
|
132
|
-
if ((s = (e - n.length + 1) % 3)) n += s == 1 || s == -2 ? '0' : '00'
|
|
133
|
-
s = mathpow(n, 1 / 3)
|
|
134
|
-
e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2))
|
|
135
|
-
if (s == 1 / 0) {
|
|
136
|
-
n = '5e' + e
|
|
137
|
-
} else {
|
|
138
|
-
n = s.toExponential()
|
|
139
|
-
n = n.slice(0, n.indexOf('e') + 1) + e
|
|
140
|
-
}
|
|
141
|
-
r = new Ctor(n)
|
|
142
|
-
r.s = x.s
|
|
143
|
-
} else {
|
|
144
|
-
r = new Ctor(s.toString())
|
|
145
|
-
}
|
|
146
|
-
sd = (e = Ctor.precision) + 3
|
|
147
|
-
for (;;) {
|
|
148
|
-
t = r
|
|
149
|
-
t3 = t.times(t).times(t)
|
|
150
|
-
t3plusx = t3.plus(x)
|
|
151
|
-
r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1)
|
|
152
|
-
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
153
|
-
n = n.slice(sd - 3, sd + 1)
|
|
154
|
-
if (n == '9999' || (!rep && n == '4999')) {
|
|
155
|
-
if (!rep) {
|
|
156
|
-
finalise(t, e + 1, 0)
|
|
157
|
-
if (t.times(t).times(t).eq(x)) {
|
|
158
|
-
r = t
|
|
159
|
-
break
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
sd += 4
|
|
163
|
-
rep = 1
|
|
164
|
-
} else {
|
|
165
|
-
if (!+n || (!+n.slice(1) && n.charAt(0) == '5')) {
|
|
166
|
-
finalise(r, e + 1, 1)
|
|
167
|
-
m = !r.times(r).times(r).eq(x)
|
|
168
|
-
}
|
|
169
|
-
break
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
external = true
|
|
174
|
-
return finalise(r, e, Ctor.rounding, m)
|
|
175
|
-
}
|
|
176
|
-
P.decimalPlaces = P.dp = function () {
|
|
177
|
-
var w,
|
|
178
|
-
d = this.d,
|
|
179
|
-
n = NaN
|
|
180
|
-
if (d) {
|
|
181
|
-
w = d.length - 1
|
|
182
|
-
n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE
|
|
183
|
-
w = d[w]
|
|
184
|
-
if (w) for (; w % 10 == 0; w /= 10) n--
|
|
185
|
-
if (n < 0) n = 0
|
|
186
|
-
}
|
|
187
|
-
return n
|
|
188
|
-
}
|
|
189
|
-
P.dividedBy = P.div = function (y) {
|
|
190
|
-
return divide(this, new this.constructor(y))
|
|
191
|
-
}
|
|
192
|
-
P.dividedToIntegerBy = P.divToInt = function (y) {
|
|
193
|
-
var x = this,
|
|
194
|
-
Ctor = x.constructor
|
|
195
|
-
return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding)
|
|
196
|
-
}
|
|
197
|
-
P.equals = P.eq = function (y) {
|
|
198
|
-
return this.cmp(y) === 0
|
|
199
|
-
}
|
|
200
|
-
P.floor = function () {
|
|
201
|
-
return finalise(new this.constructor(this), this.e + 1, 3)
|
|
202
|
-
}
|
|
203
|
-
P.greaterThan = P.gt = function (y) {
|
|
204
|
-
return this.cmp(y) > 0
|
|
205
|
-
}
|
|
206
|
-
P.greaterThanOrEqualTo = P.gte = function (y) {
|
|
207
|
-
var k = this.cmp(y)
|
|
208
|
-
return k == 1 || k === 0
|
|
209
|
-
}
|
|
210
|
-
P.hyperbolicCosine = P.cosh = function () {
|
|
211
|
-
var k,
|
|
212
|
-
n,
|
|
213
|
-
pr,
|
|
214
|
-
rm,
|
|
215
|
-
len,
|
|
216
|
-
x = this,
|
|
217
|
-
Ctor = x.constructor,
|
|
218
|
-
one = new Ctor(1)
|
|
219
|
-
if (!x.isFinite()) return new Ctor(x.s ? 1 / 0 : NaN)
|
|
220
|
-
if (x.isZero()) return one
|
|
221
|
-
pr = Ctor.precision
|
|
222
|
-
rm = Ctor.rounding
|
|
223
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4
|
|
224
|
-
Ctor.rounding = 1
|
|
225
|
-
len = x.d.length
|
|
226
|
-
if (len < 32) {
|
|
227
|
-
k = Math.ceil(len / 3)
|
|
228
|
-
n = (1 / tinyPow(4, k)).toString()
|
|
229
|
-
} else {
|
|
230
|
-
k = 16
|
|
231
|
-
n = '2.3283064365386962890625e-10'
|
|
232
|
-
}
|
|
233
|
-
x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true)
|
|
234
|
-
var cosh2_x,
|
|
235
|
-
i = k,
|
|
236
|
-
d8 = new Ctor(8)
|
|
237
|
-
for (; i--; ) {
|
|
238
|
-
cosh2_x = x.times(x)
|
|
239
|
-
x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))))
|
|
240
|
-
}
|
|
241
|
-
return finalise(x, (Ctor.precision = pr), (Ctor.rounding = rm), true)
|
|
242
|
-
}
|
|
243
|
-
P.hyperbolicSine = P.sinh = function () {
|
|
244
|
-
var k,
|
|
245
|
-
pr,
|
|
246
|
-
rm,
|
|
247
|
-
len,
|
|
248
|
-
x = this,
|
|
249
|
-
Ctor = x.constructor
|
|
250
|
-
if (!x.isFinite() || x.isZero()) return new Ctor(x)
|
|
251
|
-
pr = Ctor.precision
|
|
252
|
-
rm = Ctor.rounding
|
|
253
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4
|
|
254
|
-
Ctor.rounding = 1
|
|
255
|
-
len = x.d.length
|
|
256
|
-
if (len < 3) {
|
|
257
|
-
x = taylorSeries(Ctor, 2, x, x, true)
|
|
258
|
-
} else {
|
|
259
|
-
k = 1.4 * Math.sqrt(len)
|
|
260
|
-
k = k > 16 ? 16 : k | 0
|
|
261
|
-
x = x.times(1 / tinyPow(5, k))
|
|
262
|
-
x = taylorSeries(Ctor, 2, x, x, true)
|
|
263
|
-
var sinh2_x,
|
|
264
|
-
d5 = new Ctor(5),
|
|
265
|
-
d16 = new Ctor(16),
|
|
266
|
-
d20 = new Ctor(20)
|
|
267
|
-
for (; k--; ) {
|
|
268
|
-
sinh2_x = x.times(x)
|
|
269
|
-
x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))))
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
Ctor.precision = pr
|
|
273
|
-
Ctor.rounding = rm
|
|
274
|
-
return finalise(x, pr, rm, true)
|
|
275
|
-
}
|
|
276
|
-
P.hyperbolicTangent = P.tanh = function () {
|
|
277
|
-
var pr,
|
|
278
|
-
rm,
|
|
279
|
-
x = this,
|
|
280
|
-
Ctor = x.constructor
|
|
281
|
-
if (!x.isFinite()) return new Ctor(x.s)
|
|
282
|
-
if (x.isZero()) return new Ctor(x)
|
|
283
|
-
pr = Ctor.precision
|
|
284
|
-
rm = Ctor.rounding
|
|
285
|
-
Ctor.precision = pr + 7
|
|
286
|
-
Ctor.rounding = 1
|
|
287
|
-
return divide(x.sinh(), x.cosh(), (Ctor.precision = pr), (Ctor.rounding = rm))
|
|
288
|
-
}
|
|
289
|
-
P.inverseCosine = P.acos = function () {
|
|
290
|
-
var halfPi,
|
|
291
|
-
x = this,
|
|
292
|
-
Ctor = x.constructor,
|
|
293
|
-
k = x.abs().cmp(1),
|
|
294
|
-
pr = Ctor.precision,
|
|
295
|
-
rm = Ctor.rounding
|
|
296
|
-
if (k !== -1) {
|
|
297
|
-
return k === 0 ? (x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0)) : new Ctor(NaN)
|
|
298
|
-
}
|
|
299
|
-
if (x.isZero()) return getPi(Ctor, pr + 4, rm).times(0.5)
|
|
300
|
-
Ctor.precision = pr + 6
|
|
301
|
-
Ctor.rounding = 1
|
|
302
|
-
x = x.asin()
|
|
303
|
-
halfPi = getPi(Ctor, pr + 4, rm).times(0.5)
|
|
304
|
-
Ctor.precision = pr
|
|
305
|
-
Ctor.rounding = rm
|
|
306
|
-
return halfPi.minus(x)
|
|
307
|
-
}
|
|
308
|
-
P.inverseHyperbolicCosine = P.acosh = function () {
|
|
309
|
-
var pr,
|
|
310
|
-
rm,
|
|
311
|
-
x = this,
|
|
312
|
-
Ctor = x.constructor
|
|
313
|
-
if (x.lte(1)) return new Ctor(x.eq(1) ? 0 : NaN)
|
|
314
|
-
if (!x.isFinite()) return new Ctor(x)
|
|
315
|
-
pr = Ctor.precision
|
|
316
|
-
rm = Ctor.rounding
|
|
317
|
-
Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4
|
|
318
|
-
Ctor.rounding = 1
|
|
319
|
-
external = false
|
|
320
|
-
x = x.times(x).minus(1).sqrt().plus(x)
|
|
321
|
-
external = true
|
|
322
|
-
Ctor.precision = pr
|
|
323
|
-
Ctor.rounding = rm
|
|
324
|
-
return x.ln()
|
|
325
|
-
}
|
|
326
|
-
P.inverseHyperbolicSine = P.asinh = function () {
|
|
327
|
-
var pr,
|
|
328
|
-
rm,
|
|
329
|
-
x = this,
|
|
330
|
-
Ctor = x.constructor
|
|
331
|
-
if (!x.isFinite() || x.isZero()) return new Ctor(x)
|
|
332
|
-
pr = Ctor.precision
|
|
333
|
-
rm = Ctor.rounding
|
|
334
|
-
Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6
|
|
335
|
-
Ctor.rounding = 1
|
|
336
|
-
external = false
|
|
337
|
-
x = x.times(x).plus(1).sqrt().plus(x)
|
|
338
|
-
external = true
|
|
339
|
-
Ctor.precision = pr
|
|
340
|
-
Ctor.rounding = rm
|
|
341
|
-
return x.ln()
|
|
342
|
-
}
|
|
343
|
-
P.inverseHyperbolicTangent = P.atanh = function () {
|
|
344
|
-
var pr,
|
|
345
|
-
rm,
|
|
346
|
-
wpr,
|
|
347
|
-
xsd,
|
|
348
|
-
x = this,
|
|
349
|
-
Ctor = x.constructor
|
|
350
|
-
if (!x.isFinite()) return new Ctor(NaN)
|
|
351
|
-
if (x.e >= 0) return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN)
|
|
352
|
-
pr = Ctor.precision
|
|
353
|
-
rm = Ctor.rounding
|
|
354
|
-
xsd = x.sd()
|
|
355
|
-
if (Math.max(xsd, pr) < 2 * -x.e - 1) return finalise(new Ctor(x), pr, rm, true)
|
|
356
|
-
Ctor.precision = wpr = xsd - x.e
|
|
357
|
-
x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1)
|
|
358
|
-
Ctor.precision = pr + 4
|
|
359
|
-
Ctor.rounding = 1
|
|
360
|
-
x = x.ln()
|
|
361
|
-
Ctor.precision = pr
|
|
362
|
-
Ctor.rounding = rm
|
|
363
|
-
return x.times(0.5)
|
|
364
|
-
}
|
|
365
|
-
P.inverseSine = P.asin = function () {
|
|
366
|
-
var halfPi,
|
|
367
|
-
k,
|
|
368
|
-
pr,
|
|
369
|
-
rm,
|
|
370
|
-
x = this,
|
|
371
|
-
Ctor = x.constructor
|
|
372
|
-
if (x.isZero()) return new Ctor(x)
|
|
373
|
-
k = x.abs().cmp(1)
|
|
374
|
-
pr = Ctor.precision
|
|
375
|
-
rm = Ctor.rounding
|
|
376
|
-
if (k !== -1) {
|
|
377
|
-
if (k === 0) {
|
|
378
|
-
halfPi = getPi(Ctor, pr + 4, rm).times(0.5)
|
|
379
|
-
halfPi.s = x.s
|
|
380
|
-
return halfPi
|
|
381
|
-
}
|
|
382
|
-
return new Ctor(NaN)
|
|
383
|
-
}
|
|
384
|
-
Ctor.precision = pr + 6
|
|
385
|
-
Ctor.rounding = 1
|
|
386
|
-
x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan()
|
|
387
|
-
Ctor.precision = pr
|
|
388
|
-
Ctor.rounding = rm
|
|
389
|
-
return x.times(2)
|
|
390
|
-
}
|
|
391
|
-
P.inverseTangent = P.atan = function () {
|
|
392
|
-
var i,
|
|
393
|
-
j,
|
|
394
|
-
k,
|
|
395
|
-
n,
|
|
396
|
-
px,
|
|
397
|
-
t,
|
|
398
|
-
r,
|
|
399
|
-
wpr,
|
|
400
|
-
x2,
|
|
401
|
-
x = this,
|
|
402
|
-
Ctor = x.constructor,
|
|
403
|
-
pr = Ctor.precision,
|
|
404
|
-
rm = Ctor.rounding
|
|
405
|
-
if (!x.isFinite()) {
|
|
406
|
-
if (!x.s) return new Ctor(NaN)
|
|
407
|
-
if (pr + 4 <= PI_PRECISION) {
|
|
408
|
-
r = getPi(Ctor, pr + 4, rm).times(0.5)
|
|
409
|
-
r.s = x.s
|
|
410
|
-
return r
|
|
411
|
-
}
|
|
412
|
-
} else if (x.isZero()) {
|
|
413
|
-
return new Ctor(x)
|
|
414
|
-
} else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
|
|
415
|
-
r = getPi(Ctor, pr + 4, rm).times(0.25)
|
|
416
|
-
r.s = x.s
|
|
417
|
-
return r
|
|
418
|
-
}
|
|
419
|
-
Ctor.precision = wpr = pr + 10
|
|
420
|
-
Ctor.rounding = 1
|
|
421
|
-
k = Math.min(28, (wpr / LOG_BASE + 2) | 0)
|
|
422
|
-
for (i = k; i; --i) x = x.div(x.times(x).plus(1).sqrt().plus(1))
|
|
423
|
-
external = false
|
|
424
|
-
j = Math.ceil(wpr / LOG_BASE)
|
|
425
|
-
n = 1
|
|
426
|
-
x2 = x.times(x)
|
|
427
|
-
r = new Ctor(x)
|
|
428
|
-
px = x
|
|
429
|
-
for (; i !== -1; ) {
|
|
430
|
-
px = px.times(x2)
|
|
431
|
-
t = r.minus(px.div((n += 2)))
|
|
432
|
-
px = px.times(x2)
|
|
433
|
-
r = t.plus(px.div((n += 2)))
|
|
434
|
-
if (r.d[j] !== void 0) for (i = j; r.d[i] === t.d[i] && i--; );
|
|
435
|
-
}
|
|
436
|
-
if (k) r = r.times(2 << (k - 1))
|
|
437
|
-
external = true
|
|
438
|
-
return finalise(r, (Ctor.precision = pr), (Ctor.rounding = rm), true)
|
|
439
|
-
}
|
|
440
|
-
P.isFinite = function () {
|
|
441
|
-
return !!this.d
|
|
442
|
-
}
|
|
443
|
-
P.isInteger = P.isInt = function () {
|
|
444
|
-
return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2
|
|
445
|
-
}
|
|
446
|
-
P.isNaN = function () {
|
|
447
|
-
return !this.s
|
|
448
|
-
}
|
|
449
|
-
P.isNegative = P.isNeg = function () {
|
|
450
|
-
return this.s < 0
|
|
451
|
-
}
|
|
452
|
-
P.isPositive = P.isPos = function () {
|
|
453
|
-
return this.s > 0
|
|
454
|
-
}
|
|
455
|
-
P.isZero = function () {
|
|
456
|
-
return !!this.d && this.d[0] === 0
|
|
457
|
-
}
|
|
458
|
-
P.lessThan = P.lt = function (y) {
|
|
459
|
-
return this.cmp(y) < 0
|
|
460
|
-
}
|
|
461
|
-
P.lessThanOrEqualTo = P.lte = function (y) {
|
|
462
|
-
return this.cmp(y) < 1
|
|
463
|
-
}
|
|
464
|
-
P.logarithm = P.log = function (base) {
|
|
465
|
-
var isBase10,
|
|
466
|
-
d,
|
|
467
|
-
denominator,
|
|
468
|
-
k,
|
|
469
|
-
inf,
|
|
470
|
-
num,
|
|
471
|
-
sd,
|
|
472
|
-
r,
|
|
473
|
-
arg = this,
|
|
474
|
-
Ctor = arg.constructor,
|
|
475
|
-
pr = Ctor.precision,
|
|
476
|
-
rm = Ctor.rounding,
|
|
477
|
-
guard = 5
|
|
478
|
-
if (base == null) {
|
|
479
|
-
base = new Ctor(10)
|
|
480
|
-
isBase10 = true
|
|
481
|
-
} else {
|
|
482
|
-
base = new Ctor(base)
|
|
483
|
-
d = base.d
|
|
484
|
-
if (base.s < 0 || !d || !d[0] || base.eq(1)) return new Ctor(NaN)
|
|
485
|
-
isBase10 = base.eq(10)
|
|
486
|
-
}
|
|
487
|
-
d = arg.d
|
|
488
|
-
if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
|
|
489
|
-
return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0)
|
|
490
|
-
}
|
|
491
|
-
if (isBase10) {
|
|
492
|
-
if (d.length > 1) {
|
|
493
|
-
inf = true
|
|
494
|
-
} else {
|
|
495
|
-
for (k = d[0]; k % 10 === 0; ) k /= 10
|
|
496
|
-
inf = k !== 1
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
external = false
|
|
500
|
-
sd = pr + guard
|
|
501
|
-
num = naturalLogarithm(arg, sd)
|
|
502
|
-
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd)
|
|
503
|
-
r = divide(num, denominator, sd, 1)
|
|
504
|
-
if (checkRoundingDigits(r.d, (k = pr), rm)) {
|
|
505
|
-
do {
|
|
506
|
-
sd += 10
|
|
507
|
-
num = naturalLogarithm(arg, sd)
|
|
508
|
-
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd)
|
|
509
|
-
r = divide(num, denominator, sd, 1)
|
|
510
|
-
if (!inf) {
|
|
511
|
-
if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 1e14) {
|
|
512
|
-
r = finalise(r, pr + 1, 0)
|
|
513
|
-
}
|
|
514
|
-
break
|
|
515
|
-
}
|
|
516
|
-
} while (checkRoundingDigits(r.d, (k += 10), rm))
|
|
517
|
-
}
|
|
518
|
-
external = true
|
|
519
|
-
return finalise(r, pr, rm)
|
|
520
|
-
}
|
|
521
|
-
P.minus = P.sub = function (y) {
|
|
522
|
-
var d,
|
|
523
|
-
e,
|
|
524
|
-
i,
|
|
525
|
-
j,
|
|
526
|
-
k,
|
|
527
|
-
len,
|
|
528
|
-
pr,
|
|
529
|
-
rm,
|
|
530
|
-
xd,
|
|
531
|
-
xe,
|
|
532
|
-
xLTy,
|
|
533
|
-
yd,
|
|
534
|
-
x = this,
|
|
535
|
-
Ctor = x.constructor
|
|
536
|
-
y = new Ctor(y)
|
|
537
|
-
if (!x.d || !y.d) {
|
|
538
|
-
if (!x.s || !y.s) y = new Ctor(NaN)
|
|
539
|
-
else if (x.d) y.s = -y.s
|
|
540
|
-
else y = new Ctor(y.d || x.s !== y.s ? x : NaN)
|
|
541
|
-
return y
|
|
542
|
-
}
|
|
543
|
-
if (x.s != y.s) {
|
|
544
|
-
y.s = -y.s
|
|
545
|
-
return x.plus(y)
|
|
546
|
-
}
|
|
547
|
-
xd = x.d
|
|
548
|
-
yd = y.d
|
|
549
|
-
pr = Ctor.precision
|
|
550
|
-
rm = Ctor.rounding
|
|
551
|
-
if (!xd[0] || !yd[0]) {
|
|
552
|
-
if (yd[0]) y.s = -y.s
|
|
553
|
-
else if (xd[0]) y = new Ctor(x)
|
|
554
|
-
else return new Ctor(rm === 3 ? -0 : 0)
|
|
555
|
-
return external ? finalise(y, pr, rm) : y
|
|
556
|
-
}
|
|
557
|
-
e = mathfloor(y.e / LOG_BASE)
|
|
558
|
-
xe = mathfloor(x.e / LOG_BASE)
|
|
559
|
-
xd = xd.slice()
|
|
560
|
-
k = xe - e
|
|
561
|
-
if (k) {
|
|
562
|
-
xLTy = k < 0
|
|
563
|
-
if (xLTy) {
|
|
564
|
-
d = xd
|
|
565
|
-
k = -k
|
|
566
|
-
len = yd.length
|
|
567
|
-
} else {
|
|
568
|
-
d = yd
|
|
569
|
-
e = xe
|
|
570
|
-
len = xd.length
|
|
571
|
-
}
|
|
572
|
-
i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2
|
|
573
|
-
if (k > i) {
|
|
574
|
-
k = i
|
|
575
|
-
d.length = 1
|
|
576
|
-
}
|
|
577
|
-
d.reverse()
|
|
578
|
-
for (i = k; i--; ) d.push(0)
|
|
579
|
-
d.reverse()
|
|
580
|
-
} else {
|
|
581
|
-
i = xd.length
|
|
582
|
-
len = yd.length
|
|
583
|
-
xLTy = i < len
|
|
584
|
-
if (xLTy) len = i
|
|
585
|
-
for (i = 0; i < len; i++) {
|
|
586
|
-
if (xd[i] != yd[i]) {
|
|
587
|
-
xLTy = xd[i] < yd[i]
|
|
588
|
-
break
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
k = 0
|
|
592
|
-
}
|
|
593
|
-
if (xLTy) {
|
|
594
|
-
d = xd
|
|
595
|
-
xd = yd
|
|
596
|
-
yd = d
|
|
597
|
-
y.s = -y.s
|
|
598
|
-
}
|
|
599
|
-
len = xd.length
|
|
600
|
-
for (i = yd.length - len; i > 0; --i) xd[len++] = 0
|
|
601
|
-
for (i = yd.length; i > k; ) {
|
|
602
|
-
if (xd[--i] < yd[i]) {
|
|
603
|
-
for (j = i; j && xd[--j] === 0; ) xd[j] = BASE - 1
|
|
604
|
-
--xd[j]
|
|
605
|
-
xd[i] += BASE
|
|
606
|
-
}
|
|
607
|
-
xd[i] -= yd[i]
|
|
608
|
-
}
|
|
609
|
-
for (; xd[--len] === 0; ) xd.pop()
|
|
610
|
-
for (; xd[0] === 0; xd.shift()) --e
|
|
611
|
-
if (!xd[0]) return new Ctor(rm === 3 ? -0 : 0)
|
|
612
|
-
y.d = xd
|
|
613
|
-
y.e = getBase10Exponent(xd, e)
|
|
614
|
-
return external ? finalise(y, pr, rm) : y
|
|
615
|
-
}
|
|
616
|
-
P.modulo = P.mod = function (y) {
|
|
617
|
-
var q,
|
|
618
|
-
x = this,
|
|
619
|
-
Ctor = x.constructor
|
|
620
|
-
y = new Ctor(y)
|
|
621
|
-
if (!x.d || !y.s || (y.d && !y.d[0])) return new Ctor(NaN)
|
|
622
|
-
if (!y.d || (x.d && !x.d[0])) {
|
|
623
|
-
return finalise(new Ctor(x), Ctor.precision, Ctor.rounding)
|
|
624
|
-
}
|
|
625
|
-
external = false
|
|
626
|
-
if (Ctor.modulo == 9) {
|
|
627
|
-
q = divide(x, y.abs(), 0, 3, 1)
|
|
628
|
-
q.s *= y.s
|
|
629
|
-
} else {
|
|
630
|
-
q = divide(x, y, 0, Ctor.modulo, 1)
|
|
631
|
-
}
|
|
632
|
-
q = q.times(y)
|
|
633
|
-
external = true
|
|
634
|
-
return x.minus(q)
|
|
635
|
-
}
|
|
636
|
-
P.naturalExponential = P.exp = function () {
|
|
637
|
-
return naturalExponential(this)
|
|
638
|
-
}
|
|
639
|
-
P.naturalLogarithm = P.ln = function () {
|
|
640
|
-
return naturalLogarithm(this)
|
|
641
|
-
}
|
|
642
|
-
P.negated = P.neg = function () {
|
|
643
|
-
var x = new this.constructor(this)
|
|
644
|
-
x.s = -x.s
|
|
645
|
-
return finalise(x)
|
|
646
|
-
}
|
|
647
|
-
P.plus = P.add = function (y) {
|
|
648
|
-
var carry,
|
|
649
|
-
d,
|
|
650
|
-
e,
|
|
651
|
-
i,
|
|
652
|
-
k,
|
|
653
|
-
len,
|
|
654
|
-
pr,
|
|
655
|
-
rm,
|
|
656
|
-
xd,
|
|
657
|
-
yd,
|
|
658
|
-
x = this,
|
|
659
|
-
Ctor = x.constructor
|
|
660
|
-
y = new Ctor(y)
|
|
661
|
-
if (!x.d || !y.d) {
|
|
662
|
-
if (!x.s || !y.s) y = new Ctor(NaN)
|
|
663
|
-
else if (!x.d) y = new Ctor(y.d || x.s === y.s ? x : NaN)
|
|
664
|
-
return y
|
|
665
|
-
}
|
|
666
|
-
if (x.s != y.s) {
|
|
667
|
-
y.s = -y.s
|
|
668
|
-
return x.minus(y)
|
|
669
|
-
}
|
|
670
|
-
xd = x.d
|
|
671
|
-
yd = y.d
|
|
672
|
-
pr = Ctor.precision
|
|
673
|
-
rm = Ctor.rounding
|
|
674
|
-
if (!xd[0] || !yd[0]) {
|
|
675
|
-
if (!yd[0]) y = new Ctor(x)
|
|
676
|
-
return external ? finalise(y, pr, rm) : y
|
|
677
|
-
}
|
|
678
|
-
k = mathfloor(x.e / LOG_BASE)
|
|
679
|
-
e = mathfloor(y.e / LOG_BASE)
|
|
680
|
-
xd = xd.slice()
|
|
681
|
-
i = k - e
|
|
682
|
-
if (i) {
|
|
683
|
-
if (i < 0) {
|
|
684
|
-
d = xd
|
|
685
|
-
i = -i
|
|
686
|
-
len = yd.length
|
|
687
|
-
} else {
|
|
688
|
-
d = yd
|
|
689
|
-
e = k
|
|
690
|
-
len = xd.length
|
|
691
|
-
}
|
|
692
|
-
k = Math.ceil(pr / LOG_BASE)
|
|
693
|
-
len = k > len ? k + 1 : len + 1
|
|
694
|
-
if (i > len) {
|
|
695
|
-
i = len
|
|
696
|
-
d.length = 1
|
|
697
|
-
}
|
|
698
|
-
d.reverse()
|
|
699
|
-
for (; i--; ) d.push(0)
|
|
700
|
-
d.reverse()
|
|
701
|
-
}
|
|
702
|
-
len = xd.length
|
|
703
|
-
i = yd.length
|
|
704
|
-
if (len - i < 0) {
|
|
705
|
-
i = len
|
|
706
|
-
d = yd
|
|
707
|
-
yd = xd
|
|
708
|
-
xd = d
|
|
709
|
-
}
|
|
710
|
-
for (carry = 0; i; ) {
|
|
711
|
-
carry = ((xd[--i] = xd[i] + yd[i] + carry) / BASE) | 0
|
|
712
|
-
xd[i] %= BASE
|
|
713
|
-
}
|
|
714
|
-
if (carry) {
|
|
715
|
-
xd.unshift(carry)
|
|
716
|
-
++e
|
|
717
|
-
}
|
|
718
|
-
for (len = xd.length; xd[--len] == 0; ) xd.pop()
|
|
719
|
-
y.d = xd
|
|
720
|
-
y.e = getBase10Exponent(xd, e)
|
|
721
|
-
return external ? finalise(y, pr, rm) : y
|
|
722
|
-
}
|
|
723
|
-
P.precision = P.sd = function (z) {
|
|
724
|
-
var k,
|
|
725
|
-
x = this
|
|
726
|
-
if (z !== void 0 && z !== !!z && z !== 1 && z !== 0) throw Error(invalidArgument + z)
|
|
727
|
-
if (x.d) {
|
|
728
|
-
k = getPrecision(x.d)
|
|
729
|
-
if (z && x.e + 1 > k) k = x.e + 1
|
|
730
|
-
} else {
|
|
731
|
-
k = NaN
|
|
732
|
-
}
|
|
733
|
-
return k
|
|
734
|
-
}
|
|
735
|
-
P.round = function () {
|
|
736
|
-
var x = this,
|
|
737
|
-
Ctor = x.constructor
|
|
738
|
-
return finalise(new Ctor(x), x.e + 1, Ctor.rounding)
|
|
739
|
-
}
|
|
740
|
-
P.sine = P.sin = function () {
|
|
741
|
-
var pr,
|
|
742
|
-
rm,
|
|
743
|
-
x = this,
|
|
744
|
-
Ctor = x.constructor
|
|
745
|
-
if (!x.isFinite()) return new Ctor(NaN)
|
|
746
|
-
if (x.isZero()) return new Ctor(x)
|
|
747
|
-
pr = Ctor.precision
|
|
748
|
-
rm = Ctor.rounding
|
|
749
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE
|
|
750
|
-
Ctor.rounding = 1
|
|
751
|
-
x = sine(Ctor, toLessThanHalfPi(Ctor, x))
|
|
752
|
-
Ctor.precision = pr
|
|
753
|
-
Ctor.rounding = rm
|
|
754
|
-
return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true)
|
|
755
|
-
}
|
|
756
|
-
P.squareRoot = P.sqrt = function () {
|
|
757
|
-
var m,
|
|
758
|
-
n,
|
|
759
|
-
sd,
|
|
760
|
-
r,
|
|
761
|
-
rep,
|
|
762
|
-
t,
|
|
763
|
-
x = this,
|
|
764
|
-
d = x.d,
|
|
765
|
-
e = x.e,
|
|
766
|
-
s = x.s,
|
|
767
|
-
Ctor = x.constructor
|
|
768
|
-
if (s !== 1 || !d || !d[0]) {
|
|
769
|
-
return new Ctor(!s || (s < 0 && (!d || d[0])) ? NaN : d ? x : 1 / 0)
|
|
770
|
-
}
|
|
771
|
-
external = false
|
|
772
|
-
s = Math.sqrt(+x)
|
|
773
|
-
if (s == 0 || s == 1 / 0) {
|
|
774
|
-
n = digitsToString(d)
|
|
775
|
-
if ((n.length + e) % 2 == 0) n += '0'
|
|
776
|
-
s = Math.sqrt(n)
|
|
777
|
-
e = mathfloor((e + 1) / 2) - (e < 0 || e % 2)
|
|
778
|
-
if (s == 1 / 0) {
|
|
779
|
-
n = '5e' + e
|
|
780
|
-
} else {
|
|
781
|
-
n = s.toExponential()
|
|
782
|
-
n = n.slice(0, n.indexOf('e') + 1) + e
|
|
783
|
-
}
|
|
784
|
-
r = new Ctor(n)
|
|
785
|
-
} else {
|
|
786
|
-
r = new Ctor(s.toString())
|
|
787
|
-
}
|
|
788
|
-
sd = (e = Ctor.precision) + 3
|
|
789
|
-
for (;;) {
|
|
790
|
-
t = r
|
|
791
|
-
r = t.plus(divide(x, t, sd + 2, 1)).times(0.5)
|
|
792
|
-
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
793
|
-
n = n.slice(sd - 3, sd + 1)
|
|
794
|
-
if (n == '9999' || (!rep && n == '4999')) {
|
|
795
|
-
if (!rep) {
|
|
796
|
-
finalise(t, e + 1, 0)
|
|
797
|
-
if (t.times(t).eq(x)) {
|
|
798
|
-
r = t
|
|
799
|
-
break
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
sd += 4
|
|
803
|
-
rep = 1
|
|
804
|
-
} else {
|
|
805
|
-
if (!+n || (!+n.slice(1) && n.charAt(0) == '5')) {
|
|
806
|
-
finalise(r, e + 1, 1)
|
|
807
|
-
m = !r.times(r).eq(x)
|
|
808
|
-
}
|
|
809
|
-
break
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
external = true
|
|
814
|
-
return finalise(r, e, Ctor.rounding, m)
|
|
815
|
-
}
|
|
816
|
-
P.tangent = P.tan = function () {
|
|
817
|
-
var pr,
|
|
818
|
-
rm,
|
|
819
|
-
x = this,
|
|
820
|
-
Ctor = x.constructor
|
|
821
|
-
if (!x.isFinite()) return new Ctor(NaN)
|
|
822
|
-
if (x.isZero()) return new Ctor(x)
|
|
823
|
-
pr = Ctor.precision
|
|
824
|
-
rm = Ctor.rounding
|
|
825
|
-
Ctor.precision = pr + 10
|
|
826
|
-
Ctor.rounding = 1
|
|
827
|
-
x = x.sin()
|
|
828
|
-
x.s = 1
|
|
829
|
-
x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0)
|
|
830
|
-
Ctor.precision = pr
|
|
831
|
-
Ctor.rounding = rm
|
|
832
|
-
return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true)
|
|
833
|
-
}
|
|
834
|
-
P.times = P.mul = function (y) {
|
|
835
|
-
var carry,
|
|
836
|
-
e,
|
|
837
|
-
i,
|
|
838
|
-
k,
|
|
839
|
-
r,
|
|
840
|
-
rL,
|
|
841
|
-
t,
|
|
842
|
-
xdL,
|
|
843
|
-
ydL,
|
|
844
|
-
x = this,
|
|
845
|
-
Ctor = x.constructor,
|
|
846
|
-
xd = x.d,
|
|
847
|
-
yd = (y = new Ctor(y)).d
|
|
848
|
-
y.s *= x.s
|
|
849
|
-
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
850
|
-
return new Ctor(
|
|
851
|
-
!y.s || (xd && !xd[0] && !yd) || (yd && !yd[0] && !xd) ? NaN : !xd || !yd ? y.s / 0 : y.s * 0,
|
|
852
|
-
)
|
|
853
|
-
}
|
|
854
|
-
e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE)
|
|
855
|
-
xdL = xd.length
|
|
856
|
-
ydL = yd.length
|
|
857
|
-
if (xdL < ydL) {
|
|
858
|
-
r = xd
|
|
859
|
-
xd = yd
|
|
860
|
-
yd = r
|
|
861
|
-
rL = xdL
|
|
862
|
-
xdL = ydL
|
|
863
|
-
ydL = rL
|
|
864
|
-
}
|
|
865
|
-
r = []
|
|
866
|
-
rL = xdL + ydL
|
|
867
|
-
for (i = rL; i--; ) r.push(0)
|
|
868
|
-
for (i = ydL; --i >= 0; ) {
|
|
869
|
-
carry = 0
|
|
870
|
-
for (k = xdL + i; k > i; ) {
|
|
871
|
-
t = r[k] + yd[i] * xd[k - i - 1] + carry
|
|
872
|
-
r[k--] = t % BASE | 0
|
|
873
|
-
carry = (t / BASE) | 0
|
|
874
|
-
}
|
|
875
|
-
r[k] = (r[k] + carry) % BASE | 0
|
|
876
|
-
}
|
|
877
|
-
for (; !r[--rL]; ) r.pop()
|
|
878
|
-
if (carry) ++e
|
|
879
|
-
else r.shift()
|
|
880
|
-
y.d = r
|
|
881
|
-
y.e = getBase10Exponent(r, e)
|
|
882
|
-
return external ? finalise(y, Ctor.precision, Ctor.rounding) : y
|
|
883
|
-
}
|
|
884
|
-
P.toBinary = function (sd, rm) {
|
|
885
|
-
return toStringBinary(this, 2, sd, rm)
|
|
886
|
-
}
|
|
887
|
-
P.toDecimalPlaces = P.toDP = function (dp, rm) {
|
|
888
|
-
var x = this,
|
|
889
|
-
Ctor = x.constructor
|
|
890
|
-
x = new Ctor(x)
|
|
891
|
-
if (dp === void 0) return x
|
|
892
|
-
checkInt32(dp, 0, MAX_DIGITS)
|
|
893
|
-
if (rm === void 0) rm = Ctor.rounding
|
|
894
|
-
else checkInt32(rm, 0, 8)
|
|
895
|
-
return finalise(x, dp + x.e + 1, rm)
|
|
896
|
-
}
|
|
897
|
-
P.toExponential = function (dp, rm) {
|
|
898
|
-
var str,
|
|
899
|
-
x = this,
|
|
900
|
-
Ctor = x.constructor
|
|
901
|
-
if (dp === void 0) {
|
|
902
|
-
str = finiteToString(x, true)
|
|
903
|
-
} else {
|
|
904
|
-
checkInt32(dp, 0, MAX_DIGITS)
|
|
905
|
-
if (rm === void 0) rm = Ctor.rounding
|
|
906
|
-
else checkInt32(rm, 0, 8)
|
|
907
|
-
x = finalise(new Ctor(x), dp + 1, rm)
|
|
908
|
-
str = finiteToString(x, true, dp + 1)
|
|
909
|
-
}
|
|
910
|
-
return x.isNeg() && !x.isZero() ? '-' + str : str
|
|
911
|
-
}
|
|
912
|
-
P.toFixed = function (dp, rm) {
|
|
913
|
-
var str,
|
|
914
|
-
y,
|
|
915
|
-
x = this,
|
|
916
|
-
Ctor = x.constructor
|
|
917
|
-
if (dp === void 0) {
|
|
918
|
-
str = finiteToString(x)
|
|
919
|
-
} else {
|
|
920
|
-
checkInt32(dp, 0, MAX_DIGITS)
|
|
921
|
-
if (rm === void 0) rm = Ctor.rounding
|
|
922
|
-
else checkInt32(rm, 0, 8)
|
|
923
|
-
y = finalise(new Ctor(x), dp + x.e + 1, rm)
|
|
924
|
-
str = finiteToString(y, false, dp + y.e + 1)
|
|
925
|
-
}
|
|
926
|
-
return x.isNeg() && !x.isZero() ? '-' + str : str
|
|
927
|
-
}
|
|
928
|
-
P.toFraction = function (maxD) {
|
|
929
|
-
var d,
|
|
930
|
-
d0,
|
|
931
|
-
d1,
|
|
932
|
-
d2,
|
|
933
|
-
e,
|
|
934
|
-
k,
|
|
935
|
-
n,
|
|
936
|
-
n0,
|
|
937
|
-
n1,
|
|
938
|
-
pr,
|
|
939
|
-
q,
|
|
940
|
-
r,
|
|
941
|
-
x = this,
|
|
942
|
-
xd = x.d,
|
|
943
|
-
Ctor = x.constructor
|
|
944
|
-
if (!xd) return new Ctor(x)
|
|
945
|
-
n1 = d0 = new Ctor(1)
|
|
946
|
-
d1 = n0 = new Ctor(0)
|
|
947
|
-
d = new Ctor(d1)
|
|
948
|
-
e = d.e = getPrecision(xd) - x.e - 1
|
|
949
|
-
k = e % LOG_BASE
|
|
950
|
-
d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k)
|
|
951
|
-
if (maxD == null) {
|
|
952
|
-
maxD = e > 0 ? d : n1
|
|
953
|
-
} else {
|
|
954
|
-
n = new Ctor(maxD)
|
|
955
|
-
if (!n.isInt() || n.lt(n1)) throw Error(invalidArgument + n)
|
|
956
|
-
maxD = n.gt(d) ? (e > 0 ? d : n1) : n
|
|
957
|
-
}
|
|
958
|
-
external = false
|
|
959
|
-
n = new Ctor(digitsToString(xd))
|
|
960
|
-
pr = Ctor.precision
|
|
961
|
-
Ctor.precision = e = xd.length * LOG_BASE * 2
|
|
962
|
-
for (;;) {
|
|
963
|
-
q = divide(n, d, 0, 1, 1)
|
|
964
|
-
d2 = d0.plus(q.times(d1))
|
|
965
|
-
if (d2.cmp(maxD) == 1) break
|
|
966
|
-
d0 = d1
|
|
967
|
-
d1 = d2
|
|
968
|
-
d2 = n1
|
|
969
|
-
n1 = n0.plus(q.times(d2))
|
|
970
|
-
n0 = d2
|
|
971
|
-
d2 = d
|
|
972
|
-
d = n.minus(q.times(d2))
|
|
973
|
-
n = d2
|
|
974
|
-
}
|
|
975
|
-
d2 = divide(maxD.minus(d0), d1, 0, 1, 1)
|
|
976
|
-
n0 = n0.plus(d2.times(n1))
|
|
977
|
-
d0 = d0.plus(d2.times(d1))
|
|
978
|
-
n0.s = n1.s = x.s
|
|
979
|
-
r =
|
|
980
|
-
divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1
|
|
981
|
-
? [n1, d1]
|
|
982
|
-
: [n0, d0]
|
|
983
|
-
Ctor.precision = pr
|
|
984
|
-
external = true
|
|
985
|
-
return r
|
|
986
|
-
}
|
|
987
|
-
P.toHexadecimal = P.toHex = function (sd, rm) {
|
|
988
|
-
return toStringBinary(this, 16, sd, rm)
|
|
989
|
-
}
|
|
990
|
-
P.toNearest = function (y, rm) {
|
|
991
|
-
var x = this,
|
|
992
|
-
Ctor = x.constructor
|
|
993
|
-
x = new Ctor(x)
|
|
994
|
-
if (y == null) {
|
|
995
|
-
if (!x.d) return x
|
|
996
|
-
y = new Ctor(1)
|
|
997
|
-
rm = Ctor.rounding
|
|
998
|
-
} else {
|
|
999
|
-
y = new Ctor(y)
|
|
1000
|
-
if (rm === void 0) {
|
|
1001
|
-
rm = Ctor.rounding
|
|
1002
|
-
} else {
|
|
1003
|
-
checkInt32(rm, 0, 8)
|
|
1004
|
-
}
|
|
1005
|
-
if (!x.d) return y.s ? x : y
|
|
1006
|
-
if (!y.d) {
|
|
1007
|
-
if (y.s) y.s = x.s
|
|
1008
|
-
return y
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
if (y.d[0]) {
|
|
1012
|
-
external = false
|
|
1013
|
-
x = divide(x, y, 0, rm, 1).times(y)
|
|
1014
|
-
external = true
|
|
1015
|
-
finalise(x)
|
|
1016
|
-
} else {
|
|
1017
|
-
y.s = x.s
|
|
1018
|
-
x = y
|
|
1019
|
-
}
|
|
1020
|
-
return x
|
|
1021
|
-
}
|
|
1022
|
-
P.toNumber = function () {
|
|
1023
|
-
return +this
|
|
1024
|
-
}
|
|
1025
|
-
P.toOctal = function (sd, rm) {
|
|
1026
|
-
return toStringBinary(this, 8, sd, rm)
|
|
1027
|
-
}
|
|
1028
|
-
P.toPower = P.pow = function (y) {
|
|
1029
|
-
var e,
|
|
1030
|
-
k,
|
|
1031
|
-
pr,
|
|
1032
|
-
r,
|
|
1033
|
-
rm,
|
|
1034
|
-
s,
|
|
1035
|
-
x = this,
|
|
1036
|
-
Ctor = x.constructor,
|
|
1037
|
-
yn = +(y = new Ctor(y))
|
|
1038
|
-
if (!x.d || !y.d || !x.d[0] || !y.d[0]) return new Ctor(mathpow(+x, yn))
|
|
1039
|
-
x = new Ctor(x)
|
|
1040
|
-
if (x.eq(1)) return x
|
|
1041
|
-
pr = Ctor.precision
|
|
1042
|
-
rm = Ctor.rounding
|
|
1043
|
-
if (y.eq(1)) return finalise(x, pr, rm)
|
|
1044
|
-
e = mathfloor(y.e / LOG_BASE)
|
|
1045
|
-
if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
|
|
1046
|
-
r = intPow(Ctor, x, k, pr)
|
|
1047
|
-
return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm)
|
|
1048
|
-
}
|
|
1049
|
-
s = x.s
|
|
1050
|
-
if (s < 0) {
|
|
1051
|
-
if (e < y.d.length - 1) return new Ctor(NaN)
|
|
1052
|
-
if ((y.d[e] & 1) == 0) s = 1
|
|
1053
|
-
if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
|
|
1054
|
-
x.s = s
|
|
1055
|
-
return x
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
k = mathpow(+x, yn)
|
|
1059
|
-
e =
|
|
1060
|
-
k == 0 || !isFinite(k)
|
|
1061
|
-
? mathfloor(yn * (Math.log('0.' + digitsToString(x.d)) / Math.LN10 + x.e + 1))
|
|
1062
|
-
: new Ctor(k + '').e
|
|
1063
|
-
if (e > Ctor.maxE + 1 || e < Ctor.minE - 1) return new Ctor(e > 0 ? s / 0 : 0)
|
|
1064
|
-
external = false
|
|
1065
|
-
Ctor.rounding = x.s = 1
|
|
1066
|
-
k = Math.min(12, (e + '').length)
|
|
1067
|
-
r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr)
|
|
1068
|
-
if (r.d) {
|
|
1069
|
-
r = finalise(r, pr + 5, 1)
|
|
1070
|
-
if (checkRoundingDigits(r.d, pr, rm)) {
|
|
1071
|
-
e = pr + 10
|
|
1072
|
-
r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1)
|
|
1073
|
-
if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 1e14) {
|
|
1074
|
-
r = finalise(r, pr + 1, 0)
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
r.s = s
|
|
1079
|
-
external = true
|
|
1080
|
-
Ctor.rounding = rm
|
|
1081
|
-
return finalise(r, pr, rm)
|
|
1082
|
-
}
|
|
1083
|
-
P.toPrecision = function (sd, rm) {
|
|
1084
|
-
var str,
|
|
1085
|
-
x = this,
|
|
1086
|
-
Ctor = x.constructor
|
|
1087
|
-
if (sd === void 0) {
|
|
1088
|
-
str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos)
|
|
1089
|
-
} else {
|
|
1090
|
-
checkInt32(sd, 1, MAX_DIGITS)
|
|
1091
|
-
if (rm === void 0) rm = Ctor.rounding
|
|
1092
|
-
else checkInt32(rm, 0, 8)
|
|
1093
|
-
x = finalise(new Ctor(x), sd, rm)
|
|
1094
|
-
str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd)
|
|
1095
|
-
}
|
|
1096
|
-
return x.isNeg() && !x.isZero() ? '-' + str : str
|
|
1097
|
-
}
|
|
1098
|
-
P.toSignificantDigits = P.toSD = function (sd, rm) {
|
|
1099
|
-
var x = this,
|
|
1100
|
-
Ctor = x.constructor
|
|
1101
|
-
if (sd === void 0) {
|
|
1102
|
-
sd = Ctor.precision
|
|
1103
|
-
rm = Ctor.rounding
|
|
1104
|
-
} else {
|
|
1105
|
-
checkInt32(sd, 1, MAX_DIGITS)
|
|
1106
|
-
if (rm === void 0) rm = Ctor.rounding
|
|
1107
|
-
else checkInt32(rm, 0, 8)
|
|
1108
|
-
}
|
|
1109
|
-
return finalise(new Ctor(x), sd, rm)
|
|
1110
|
-
}
|
|
1111
|
-
P.toString = function () {
|
|
1112
|
-
var x = this,
|
|
1113
|
-
Ctor = x.constructor,
|
|
1114
|
-
str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos)
|
|
1115
|
-
return x.isNeg() && !x.isZero() ? '-' + str : str
|
|
1116
|
-
}
|
|
1117
|
-
P.truncated = P.trunc = function () {
|
|
1118
|
-
return finalise(new this.constructor(this), this.e + 1, 1)
|
|
1119
|
-
}
|
|
1120
|
-
P.valueOf = P.toJSON = function () {
|
|
1121
|
-
var x = this,
|
|
1122
|
-
Ctor = x.constructor,
|
|
1123
|
-
str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos)
|
|
1124
|
-
return x.isNeg() ? '-' + str : str
|
|
1125
|
-
}
|
|
1126
|
-
function digitsToString(d) {
|
|
1127
|
-
var i,
|
|
1128
|
-
k,
|
|
1129
|
-
ws,
|
|
1130
|
-
indexOfLastWord = d.length - 1,
|
|
1131
|
-
str = '',
|
|
1132
|
-
w = d[0]
|
|
1133
|
-
if (indexOfLastWord > 0) {
|
|
1134
|
-
str += w
|
|
1135
|
-
for (i = 1; i < indexOfLastWord; i++) {
|
|
1136
|
-
ws = d[i] + ''
|
|
1137
|
-
k = LOG_BASE - ws.length
|
|
1138
|
-
if (k) str += getZeroString(k)
|
|
1139
|
-
str += ws
|
|
1140
|
-
}
|
|
1141
|
-
w = d[i]
|
|
1142
|
-
ws = w + ''
|
|
1143
|
-
k = LOG_BASE - ws.length
|
|
1144
|
-
if (k) str += getZeroString(k)
|
|
1145
|
-
} else if (w === 0) {
|
|
1146
|
-
return '0'
|
|
1147
|
-
}
|
|
1148
|
-
for (; w % 10 === 0; ) w /= 10
|
|
1149
|
-
return str + w
|
|
1150
|
-
}
|
|
1151
|
-
__name(digitsToString, 'digitsToString')
|
|
1152
|
-
__name2(digitsToString, 'digitsToString')
|
|
1153
|
-
function checkInt32(i, min2, max2) {
|
|
1154
|
-
if (i !== ~~i || i < min2 || i > max2) {
|
|
1155
|
-
throw Error(invalidArgument + i)
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
__name(checkInt32, 'checkInt32')
|
|
1159
|
-
__name2(checkInt32, 'checkInt32')
|
|
1160
|
-
function checkRoundingDigits(d, i, rm, repeating) {
|
|
1161
|
-
var di, k, r, rd
|
|
1162
|
-
for (k = d[0]; k >= 10; k /= 10) --i
|
|
1163
|
-
if (--i < 0) {
|
|
1164
|
-
i += LOG_BASE
|
|
1165
|
-
di = 0
|
|
1166
|
-
} else {
|
|
1167
|
-
di = Math.ceil((i + 1) / LOG_BASE)
|
|
1168
|
-
i %= LOG_BASE
|
|
1169
|
-
}
|
|
1170
|
-
k = mathpow(10, LOG_BASE - i)
|
|
1171
|
-
rd = d[di] % k | 0
|
|
1172
|
-
if (repeating == null) {
|
|
1173
|
-
if (i < 3) {
|
|
1174
|
-
if (i == 0) rd = (rd / 100) | 0
|
|
1175
|
-
else if (i == 1) rd = (rd / 10) | 0
|
|
1176
|
-
r = (rm < 4 && rd == 99999) || (rm > 3 && rd == 49999) || rd == 5e4 || rd == 0
|
|
1177
|
-
} else {
|
|
1178
|
-
r =
|
|
1179
|
-
(((rm < 4 && rd + 1 == k) || (rm > 3 && rd + 1 == k / 2)) &&
|
|
1180
|
-
((d[di + 1] / k / 100) | 0) == mathpow(10, i - 2) - 1) ||
|
|
1181
|
-
((rd == k / 2 || rd == 0) && ((d[di + 1] / k / 100) | 0) == 0)
|
|
1182
|
-
}
|
|
1183
|
-
} else {
|
|
1184
|
-
if (i < 4) {
|
|
1185
|
-
if (i == 0) rd = (rd / 1e3) | 0
|
|
1186
|
-
else if (i == 1) rd = (rd / 100) | 0
|
|
1187
|
-
else if (i == 2) rd = (rd / 10) | 0
|
|
1188
|
-
r = ((repeating || rm < 4) && rd == 9999) || (!repeating && rm > 3 && rd == 4999)
|
|
1189
|
-
} else {
|
|
1190
|
-
r =
|
|
1191
|
-
(((repeating || rm < 4) && rd + 1 == k) || (!repeating && rm > 3 && rd + 1 == k / 2)) &&
|
|
1192
|
-
((d[di + 1] / k / 1e3) | 0) == mathpow(10, i - 3) - 1
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
return r
|
|
1196
|
-
}
|
|
1197
|
-
__name(checkRoundingDigits, 'checkRoundingDigits')
|
|
1198
|
-
__name2(checkRoundingDigits, 'checkRoundingDigits')
|
|
1199
|
-
function convertBase(str, baseIn, baseOut) {
|
|
1200
|
-
var j,
|
|
1201
|
-
arr = [0],
|
|
1202
|
-
arrL,
|
|
1203
|
-
i = 0,
|
|
1204
|
-
strL = str.length
|
|
1205
|
-
for (; i < strL; ) {
|
|
1206
|
-
for (arrL = arr.length; arrL--; ) arr[arrL] *= baseIn
|
|
1207
|
-
arr[0] += NUMERALS.indexOf(str.charAt(i++))
|
|
1208
|
-
for (j = 0; j < arr.length; j++) {
|
|
1209
|
-
if (arr[j] > baseOut - 1) {
|
|
1210
|
-
if (arr[j + 1] === void 0) arr[j + 1] = 0
|
|
1211
|
-
arr[j + 1] += (arr[j] / baseOut) | 0
|
|
1212
|
-
arr[j] %= baseOut
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
return arr.reverse()
|
|
1217
|
-
}
|
|
1218
|
-
__name(convertBase, 'convertBase')
|
|
1219
|
-
__name2(convertBase, 'convertBase')
|
|
1220
|
-
function cosine(Ctor, x) {
|
|
1221
|
-
var k, len, y
|
|
1222
|
-
if (x.isZero()) return x
|
|
1223
|
-
len = x.d.length
|
|
1224
|
-
if (len < 32) {
|
|
1225
|
-
k = Math.ceil(len / 3)
|
|
1226
|
-
y = (1 / tinyPow(4, k)).toString()
|
|
1227
|
-
} else {
|
|
1228
|
-
k = 16
|
|
1229
|
-
y = '2.3283064365386962890625e-10'
|
|
1230
|
-
}
|
|
1231
|
-
Ctor.precision += k
|
|
1232
|
-
x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1))
|
|
1233
|
-
for (var i = k; i--; ) {
|
|
1234
|
-
var cos2x = x.times(x)
|
|
1235
|
-
x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1)
|
|
1236
|
-
}
|
|
1237
|
-
Ctor.precision -= k
|
|
1238
|
-
return x
|
|
1239
|
-
}
|
|
1240
|
-
__name(cosine, 'cosine')
|
|
1241
|
-
__name2(cosine, 'cosine')
|
|
1242
|
-
var divide = (function () {
|
|
1243
|
-
function multiplyInteger(x, k, base) {
|
|
1244
|
-
var temp,
|
|
1245
|
-
carry = 0,
|
|
1246
|
-
i = x.length
|
|
1247
|
-
for (x = x.slice(); i--; ) {
|
|
1248
|
-
temp = x[i] * k + carry
|
|
1249
|
-
x[i] = temp % base | 0
|
|
1250
|
-
carry = (temp / base) | 0
|
|
1251
|
-
}
|
|
1252
|
-
if (carry) x.unshift(carry)
|
|
1253
|
-
return x
|
|
1254
|
-
}
|
|
1255
|
-
__name(multiplyInteger, 'multiplyInteger')
|
|
1256
|
-
__name2(multiplyInteger, 'multiplyInteger')
|
|
1257
|
-
function compare(a, b, aL, bL) {
|
|
1258
|
-
var i, r
|
|
1259
|
-
if (aL != bL) {
|
|
1260
|
-
r = aL > bL ? 1 : -1
|
|
1261
|
-
} else {
|
|
1262
|
-
for (i = r = 0; i < aL; i++) {
|
|
1263
|
-
if (a[i] != b[i]) {
|
|
1264
|
-
r = a[i] > b[i] ? 1 : -1
|
|
1265
|
-
break
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
return r
|
|
1270
|
-
}
|
|
1271
|
-
__name(compare, 'compare')
|
|
1272
|
-
__name2(compare, 'compare')
|
|
1273
|
-
function subtract(a, b, aL, base) {
|
|
1274
|
-
var i = 0
|
|
1275
|
-
for (; aL--; ) {
|
|
1276
|
-
a[aL] -= i
|
|
1277
|
-
i = a[aL] < b[aL] ? 1 : 0
|
|
1278
|
-
a[aL] = i * base + a[aL] - b[aL]
|
|
1279
|
-
}
|
|
1280
|
-
for (; !a[0] && a.length > 1; ) a.shift()
|
|
1281
|
-
}
|
|
1282
|
-
__name(subtract, 'subtract')
|
|
1283
|
-
__name2(subtract, 'subtract')
|
|
1284
|
-
return function (x, y, pr, rm, dp, base) {
|
|
1285
|
-
var cmp,
|
|
1286
|
-
e,
|
|
1287
|
-
i,
|
|
1288
|
-
k,
|
|
1289
|
-
logBase,
|
|
1290
|
-
more,
|
|
1291
|
-
prod,
|
|
1292
|
-
prodL,
|
|
1293
|
-
q,
|
|
1294
|
-
qd,
|
|
1295
|
-
rem,
|
|
1296
|
-
remL,
|
|
1297
|
-
rem0,
|
|
1298
|
-
sd,
|
|
1299
|
-
t,
|
|
1300
|
-
xi,
|
|
1301
|
-
xL,
|
|
1302
|
-
yd0,
|
|
1303
|
-
yL,
|
|
1304
|
-
yz,
|
|
1305
|
-
Ctor = x.constructor,
|
|
1306
|
-
sign2 = x.s == y.s ? 1 : -1,
|
|
1307
|
-
xd = x.d,
|
|
1308
|
-
yd = y.d
|
|
1309
|
-
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
1310
|
-
return new Ctor(
|
|
1311
|
-
!x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd)
|
|
1312
|
-
? NaN
|
|
1313
|
-
: (xd && xd[0] == 0) || !yd
|
|
1314
|
-
? sign2 * 0
|
|
1315
|
-
: sign2 / 0,
|
|
1316
|
-
)
|
|
1317
|
-
}
|
|
1318
|
-
if (base) {
|
|
1319
|
-
logBase = 1
|
|
1320
|
-
e = x.e - y.e
|
|
1321
|
-
} else {
|
|
1322
|
-
base = BASE
|
|
1323
|
-
logBase = LOG_BASE
|
|
1324
|
-
e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase)
|
|
1325
|
-
}
|
|
1326
|
-
yL = yd.length
|
|
1327
|
-
xL = xd.length
|
|
1328
|
-
q = new Ctor(sign2)
|
|
1329
|
-
qd = q.d = []
|
|
1330
|
-
for (i = 0; yd[i] == (xd[i] || 0); i++);
|
|
1331
|
-
if (yd[i] > (xd[i] || 0)) e--
|
|
1332
|
-
if (pr == null) {
|
|
1333
|
-
sd = pr = Ctor.precision
|
|
1334
|
-
rm = Ctor.rounding
|
|
1335
|
-
} else if (dp) {
|
|
1336
|
-
sd = pr + (x.e - y.e) + 1
|
|
1337
|
-
} else {
|
|
1338
|
-
sd = pr
|
|
1339
|
-
}
|
|
1340
|
-
if (sd < 0) {
|
|
1341
|
-
qd.push(1)
|
|
1342
|
-
more = true
|
|
1343
|
-
} else {
|
|
1344
|
-
sd = (sd / logBase + 2) | 0
|
|
1345
|
-
i = 0
|
|
1346
|
-
if (yL == 1) {
|
|
1347
|
-
k = 0
|
|
1348
|
-
yd = yd[0]
|
|
1349
|
-
sd++
|
|
1350
|
-
for (; (i < xL || k) && sd--; i++) {
|
|
1351
|
-
t = k * base + (xd[i] || 0)
|
|
1352
|
-
qd[i] = (t / yd) | 0
|
|
1353
|
-
k = t % yd | 0
|
|
1354
|
-
}
|
|
1355
|
-
more = k || i < xL
|
|
1356
|
-
} else {
|
|
1357
|
-
k = (base / (yd[0] + 1)) | 0
|
|
1358
|
-
if (k > 1) {
|
|
1359
|
-
yd = multiplyInteger(yd, k, base)
|
|
1360
|
-
xd = multiplyInteger(xd, k, base)
|
|
1361
|
-
yL = yd.length
|
|
1362
|
-
xL = xd.length
|
|
1363
|
-
}
|
|
1364
|
-
xi = yL
|
|
1365
|
-
rem = xd.slice(0, yL)
|
|
1366
|
-
remL = rem.length
|
|
1367
|
-
for (; remL < yL; ) rem[remL++] = 0
|
|
1368
|
-
yz = yd.slice()
|
|
1369
|
-
yz.unshift(0)
|
|
1370
|
-
yd0 = yd[0]
|
|
1371
|
-
if (yd[1] >= base / 2) ++yd0
|
|
1372
|
-
do {
|
|
1373
|
-
k = 0
|
|
1374
|
-
cmp = compare(yd, rem, yL, remL)
|
|
1375
|
-
if (cmp < 0) {
|
|
1376
|
-
rem0 = rem[0]
|
|
1377
|
-
if (yL != remL) rem0 = rem0 * base + (rem[1] || 0)
|
|
1378
|
-
k = (rem0 / yd0) | 0
|
|
1379
|
-
if (k > 1) {
|
|
1380
|
-
if (k >= base) k = base - 1
|
|
1381
|
-
prod = multiplyInteger(yd, k, base)
|
|
1382
|
-
prodL = prod.length
|
|
1383
|
-
remL = rem.length
|
|
1384
|
-
cmp = compare(prod, rem, prodL, remL)
|
|
1385
|
-
if (cmp == 1) {
|
|
1386
|
-
k--
|
|
1387
|
-
subtract(prod, yL < prodL ? yz : yd, prodL, base)
|
|
1388
|
-
}
|
|
1389
|
-
} else {
|
|
1390
|
-
if (k == 0) cmp = k = 1
|
|
1391
|
-
prod = yd.slice()
|
|
1392
|
-
}
|
|
1393
|
-
prodL = prod.length
|
|
1394
|
-
if (prodL < remL) prod.unshift(0)
|
|
1395
|
-
subtract(rem, prod, remL, base)
|
|
1396
|
-
if (cmp == -1) {
|
|
1397
|
-
remL = rem.length
|
|
1398
|
-
cmp = compare(yd, rem, yL, remL)
|
|
1399
|
-
if (cmp < 1) {
|
|
1400
|
-
k++
|
|
1401
|
-
subtract(rem, yL < remL ? yz : yd, remL, base)
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
remL = rem.length
|
|
1405
|
-
} else if (cmp === 0) {
|
|
1406
|
-
k++
|
|
1407
|
-
rem = [0]
|
|
1408
|
-
}
|
|
1409
|
-
qd[i++] = k
|
|
1410
|
-
if (cmp && rem[0]) {
|
|
1411
|
-
rem[remL++] = xd[xi] || 0
|
|
1412
|
-
} else {
|
|
1413
|
-
rem = [xd[xi]]
|
|
1414
|
-
remL = 1
|
|
1415
|
-
}
|
|
1416
|
-
} while ((xi++ < xL || rem[0] !== void 0) && sd--)
|
|
1417
|
-
more = rem[0] !== void 0
|
|
1418
|
-
}
|
|
1419
|
-
if (!qd[0]) qd.shift()
|
|
1420
|
-
}
|
|
1421
|
-
if (logBase == 1) {
|
|
1422
|
-
q.e = e
|
|
1423
|
-
inexact = more
|
|
1424
|
-
} else {
|
|
1425
|
-
for (i = 1, k = qd[0]; k >= 10; k /= 10) i++
|
|
1426
|
-
q.e = i + e * logBase - 1
|
|
1427
|
-
finalise(q, dp ? pr + q.e + 1 : pr, rm, more)
|
|
1428
|
-
}
|
|
1429
|
-
return q
|
|
1430
|
-
}
|
|
1431
|
-
})()
|
|
1432
|
-
function finalise(x, sd, rm, isTruncated) {
|
|
1433
|
-
var digits,
|
|
1434
|
-
i,
|
|
1435
|
-
j,
|
|
1436
|
-
k,
|
|
1437
|
-
rd,
|
|
1438
|
-
roundUp,
|
|
1439
|
-
w,
|
|
1440
|
-
xd,
|
|
1441
|
-
xdi,
|
|
1442
|
-
Ctor = x.constructor
|
|
1443
|
-
out: if (sd != null) {
|
|
1444
|
-
xd = x.d
|
|
1445
|
-
if (!xd) return x
|
|
1446
|
-
for (digits = 1, k = xd[0]; k >= 10; k /= 10) digits++
|
|
1447
|
-
i = sd - digits
|
|
1448
|
-
if (i < 0) {
|
|
1449
|
-
i += LOG_BASE
|
|
1450
|
-
j = sd
|
|
1451
|
-
w = xd[(xdi = 0)]
|
|
1452
|
-
rd = (w / mathpow(10, digits - j - 1)) % 10 | 0
|
|
1453
|
-
} else {
|
|
1454
|
-
xdi = Math.ceil((i + 1) / LOG_BASE)
|
|
1455
|
-
k = xd.length
|
|
1456
|
-
if (xdi >= k) {
|
|
1457
|
-
if (isTruncated) {
|
|
1458
|
-
for (; k++ <= xdi; ) xd.push(0)
|
|
1459
|
-
w = rd = 0
|
|
1460
|
-
digits = 1
|
|
1461
|
-
i %= LOG_BASE
|
|
1462
|
-
j = i - LOG_BASE + 1
|
|
1463
|
-
} else {
|
|
1464
|
-
break out
|
|
1465
|
-
}
|
|
1466
|
-
} else {
|
|
1467
|
-
w = k = xd[xdi]
|
|
1468
|
-
for (digits = 1; k >= 10; k /= 10) digits++
|
|
1469
|
-
i %= LOG_BASE
|
|
1470
|
-
j = i - LOG_BASE + digits
|
|
1471
|
-
rd = j < 0 ? 0 : (w / mathpow(10, digits - j - 1)) % 10 | 0
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
isTruncated =
|
|
1475
|
-
isTruncated ||
|
|
1476
|
-
sd < 0 ||
|
|
1477
|
-
xd[xdi + 1] !== void 0 ||
|
|
1478
|
-
(j < 0 ? w : w % mathpow(10, digits - j - 1))
|
|
1479
|
-
roundUp =
|
|
1480
|
-
rm < 4
|
|
1481
|
-
? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))
|
|
1482
|
-
: rd > 5 ||
|
|
1483
|
-
(rd == 5 &&
|
|
1484
|
-
(rm == 4 ||
|
|
1485
|
-
isTruncated ||
|
|
1486
|
-
(rm == 6 &&
|
|
1487
|
-
(i > 0 ? (j > 0 ? w / mathpow(10, digits - j) : 0) : xd[xdi - 1]) % 10 & 1) ||
|
|
1488
|
-
rm == (x.s < 0 ? 8 : 7)))
|
|
1489
|
-
if (sd < 1 || !xd[0]) {
|
|
1490
|
-
xd.length = 0
|
|
1491
|
-
if (roundUp) {
|
|
1492
|
-
sd -= x.e + 1
|
|
1493
|
-
xd[0] = mathpow(10, (LOG_BASE - (sd % LOG_BASE)) % LOG_BASE)
|
|
1494
|
-
x.e = -sd || 0
|
|
1495
|
-
} else {
|
|
1496
|
-
xd[0] = x.e = 0
|
|
1497
|
-
}
|
|
1498
|
-
return x
|
|
1499
|
-
}
|
|
1500
|
-
if (i == 0) {
|
|
1501
|
-
xd.length = xdi
|
|
1502
|
-
k = 1
|
|
1503
|
-
xdi--
|
|
1504
|
-
} else {
|
|
1505
|
-
xd.length = xdi + 1
|
|
1506
|
-
k = mathpow(10, LOG_BASE - i)
|
|
1507
|
-
xd[xdi] = j > 0 ? ((w / mathpow(10, digits - j)) % mathpow(10, j) | 0) * k : 0
|
|
1508
|
-
}
|
|
1509
|
-
if (roundUp) {
|
|
1510
|
-
for (;;) {
|
|
1511
|
-
if (xdi == 0) {
|
|
1512
|
-
for (i = 1, j = xd[0]; j >= 10; j /= 10) i++
|
|
1513
|
-
j = xd[0] += k
|
|
1514
|
-
for (k = 1; j >= 10; j /= 10) k++
|
|
1515
|
-
if (i != k) {
|
|
1516
|
-
x.e++
|
|
1517
|
-
if (xd[0] == BASE) xd[0] = 1
|
|
1518
|
-
}
|
|
1519
|
-
break
|
|
1520
|
-
} else {
|
|
1521
|
-
xd[xdi] += k
|
|
1522
|
-
if (xd[xdi] != BASE) break
|
|
1523
|
-
xd[xdi--] = 0
|
|
1524
|
-
k = 1
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
for (i = xd.length; xd[--i] === 0; ) xd.pop()
|
|
1529
|
-
}
|
|
1530
|
-
if (external) {
|
|
1531
|
-
if (x.e > Ctor.maxE) {
|
|
1532
|
-
x.d = null
|
|
1533
|
-
x.e = NaN
|
|
1534
|
-
} else if (x.e < Ctor.minE) {
|
|
1535
|
-
x.e = 0
|
|
1536
|
-
x.d = [0]
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
return x
|
|
1540
|
-
}
|
|
1541
|
-
__name(finalise, 'finalise')
|
|
1542
|
-
__name2(finalise, 'finalise')
|
|
1543
|
-
function finiteToString(x, isExp, sd) {
|
|
1544
|
-
if (!x.isFinite()) return nonFiniteToString(x)
|
|
1545
|
-
var k,
|
|
1546
|
-
e = x.e,
|
|
1547
|
-
str = digitsToString(x.d),
|
|
1548
|
-
len = str.length
|
|
1549
|
-
if (isExp) {
|
|
1550
|
-
if (sd && (k = sd - len) > 0) {
|
|
1551
|
-
str = str.charAt(0) + '.' + str.slice(1) + getZeroString(k)
|
|
1552
|
-
} else if (len > 1) {
|
|
1553
|
-
str = str.charAt(0) + '.' + str.slice(1)
|
|
1554
|
-
}
|
|
1555
|
-
str = str + (x.e < 0 ? 'e' : 'e+') + x.e
|
|
1556
|
-
} else if (e < 0) {
|
|
1557
|
-
str = '0.' + getZeroString(-e - 1) + str
|
|
1558
|
-
if (sd && (k = sd - len) > 0) str += getZeroString(k)
|
|
1559
|
-
} else if (e >= len) {
|
|
1560
|
-
str += getZeroString(e + 1 - len)
|
|
1561
|
-
if (sd && (k = sd - e - 1) > 0) str = str + '.' + getZeroString(k)
|
|
1562
|
-
} else {
|
|
1563
|
-
if ((k = e + 1) < len) str = str.slice(0, k) + '.' + str.slice(k)
|
|
1564
|
-
if (sd && (k = sd - len) > 0) {
|
|
1565
|
-
if (e + 1 === len) str += '.'
|
|
1566
|
-
str += getZeroString(k)
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
return str
|
|
1570
|
-
}
|
|
1571
|
-
__name(finiteToString, 'finiteToString')
|
|
1572
|
-
__name2(finiteToString, 'finiteToString')
|
|
1573
|
-
function getBase10Exponent(digits, e) {
|
|
1574
|
-
var w = digits[0]
|
|
1575
|
-
for (e *= LOG_BASE; w >= 10; w /= 10) e++
|
|
1576
|
-
return e
|
|
1577
|
-
}
|
|
1578
|
-
__name(getBase10Exponent, 'getBase10Exponent')
|
|
1579
|
-
__name2(getBase10Exponent, 'getBase10Exponent')
|
|
1580
|
-
function getLn10(Ctor, sd, pr) {
|
|
1581
|
-
if (sd > LN10_PRECISION) {
|
|
1582
|
-
external = true
|
|
1583
|
-
if (pr) Ctor.precision = pr
|
|
1584
|
-
throw Error(precisionLimitExceeded)
|
|
1585
|
-
}
|
|
1586
|
-
return finalise(new Ctor(LN10), sd, 1, true)
|
|
1587
|
-
}
|
|
1588
|
-
__name(getLn10, 'getLn10')
|
|
1589
|
-
__name2(getLn10, 'getLn10')
|
|
1590
|
-
function getPi(Ctor, sd, rm) {
|
|
1591
|
-
if (sd > PI_PRECISION) throw Error(precisionLimitExceeded)
|
|
1592
|
-
return finalise(new Ctor(PI), sd, rm, true)
|
|
1593
|
-
}
|
|
1594
|
-
__name(getPi, 'getPi')
|
|
1595
|
-
__name2(getPi, 'getPi')
|
|
1596
|
-
function getPrecision(digits) {
|
|
1597
|
-
var w = digits.length - 1,
|
|
1598
|
-
len = w * LOG_BASE + 1
|
|
1599
|
-
w = digits[w]
|
|
1600
|
-
if (w) {
|
|
1601
|
-
for (; w % 10 == 0; w /= 10) len--
|
|
1602
|
-
for (w = digits[0]; w >= 10; w /= 10) len++
|
|
1603
|
-
}
|
|
1604
|
-
return len
|
|
1605
|
-
}
|
|
1606
|
-
__name(getPrecision, 'getPrecision')
|
|
1607
|
-
__name2(getPrecision, 'getPrecision')
|
|
1608
|
-
function getZeroString(k) {
|
|
1609
|
-
var zs = ''
|
|
1610
|
-
for (; k--; ) zs += '0'
|
|
1611
|
-
return zs
|
|
1612
|
-
}
|
|
1613
|
-
__name(getZeroString, 'getZeroString')
|
|
1614
|
-
__name2(getZeroString, 'getZeroString')
|
|
1615
|
-
function intPow(Ctor, x, n, pr) {
|
|
1616
|
-
var isTruncated,
|
|
1617
|
-
r = new Ctor(1),
|
|
1618
|
-
k = Math.ceil(pr / LOG_BASE + 4)
|
|
1619
|
-
external = false
|
|
1620
|
-
for (;;) {
|
|
1621
|
-
if (n % 2) {
|
|
1622
|
-
r = r.times(x)
|
|
1623
|
-
if (truncate(r.d, k)) isTruncated = true
|
|
1624
|
-
}
|
|
1625
|
-
n = mathfloor(n / 2)
|
|
1626
|
-
if (n === 0) {
|
|
1627
|
-
n = r.d.length - 1
|
|
1628
|
-
if (isTruncated && r.d[n] === 0) ++r.d[n]
|
|
1629
|
-
break
|
|
1630
|
-
}
|
|
1631
|
-
x = x.times(x)
|
|
1632
|
-
truncate(x.d, k)
|
|
1633
|
-
}
|
|
1634
|
-
external = true
|
|
1635
|
-
return r
|
|
1636
|
-
}
|
|
1637
|
-
__name(intPow, 'intPow')
|
|
1638
|
-
__name2(intPow, 'intPow')
|
|
1639
|
-
function isOdd(n) {
|
|
1640
|
-
return n.d[n.d.length - 1] & 1
|
|
1641
|
-
}
|
|
1642
|
-
__name(isOdd, 'isOdd')
|
|
1643
|
-
__name2(isOdd, 'isOdd')
|
|
1644
|
-
function maxOrMin(Ctor, args, ltgt) {
|
|
1645
|
-
var y,
|
|
1646
|
-
x = new Ctor(args[0]),
|
|
1647
|
-
i = 0
|
|
1648
|
-
for (; ++i < args.length; ) {
|
|
1649
|
-
y = new Ctor(args[i])
|
|
1650
|
-
if (!y.s) {
|
|
1651
|
-
x = y
|
|
1652
|
-
break
|
|
1653
|
-
} else if (x[ltgt](y)) {
|
|
1654
|
-
x = y
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
return x
|
|
1658
|
-
}
|
|
1659
|
-
__name(maxOrMin, 'maxOrMin')
|
|
1660
|
-
__name2(maxOrMin, 'maxOrMin')
|
|
1661
|
-
function naturalExponential(x, sd) {
|
|
1662
|
-
var denominator,
|
|
1663
|
-
guard,
|
|
1664
|
-
j,
|
|
1665
|
-
pow2,
|
|
1666
|
-
sum2,
|
|
1667
|
-
t,
|
|
1668
|
-
wpr,
|
|
1669
|
-
rep = 0,
|
|
1670
|
-
i = 0,
|
|
1671
|
-
k = 0,
|
|
1672
|
-
Ctor = x.constructor,
|
|
1673
|
-
rm = Ctor.rounding,
|
|
1674
|
-
pr = Ctor.precision
|
|
1675
|
-
if (!x.d || !x.d[0] || x.e > 17) {
|
|
1676
|
-
return new Ctor(x.d ? (!x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0) : x.s ? (x.s < 0 ? 0 : x) : 0 / 0)
|
|
1677
|
-
}
|
|
1678
|
-
if (sd == null) {
|
|
1679
|
-
external = false
|
|
1680
|
-
wpr = pr
|
|
1681
|
-
} else {
|
|
1682
|
-
wpr = sd
|
|
1683
|
-
}
|
|
1684
|
-
t = new Ctor(0.03125)
|
|
1685
|
-
while (x.e > -2) {
|
|
1686
|
-
x = x.times(t)
|
|
1687
|
-
k += 5
|
|
1688
|
-
}
|
|
1689
|
-
guard = ((Math.log(mathpow(2, k)) / Math.LN10) * 2 + 5) | 0
|
|
1690
|
-
wpr += guard
|
|
1691
|
-
denominator = pow2 = sum2 = new Ctor(1)
|
|
1692
|
-
Ctor.precision = wpr
|
|
1693
|
-
for (;;) {
|
|
1694
|
-
pow2 = finalise(pow2.times(x), wpr, 1)
|
|
1695
|
-
denominator = denominator.times(++i)
|
|
1696
|
-
t = sum2.plus(divide(pow2, denominator, wpr, 1))
|
|
1697
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
|
1698
|
-
j = k
|
|
1699
|
-
while (j--) sum2 = finalise(sum2.times(sum2), wpr, 1)
|
|
1700
|
-
if (sd == null) {
|
|
1701
|
-
if (rep < 3 && checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
|
1702
|
-
Ctor.precision = wpr += 10
|
|
1703
|
-
denominator = pow2 = t = new Ctor(1)
|
|
1704
|
-
i = 0
|
|
1705
|
-
rep++
|
|
1706
|
-
} else {
|
|
1707
|
-
return finalise(sum2, (Ctor.precision = pr), rm, (external = true))
|
|
1708
|
-
}
|
|
1709
|
-
} else {
|
|
1710
|
-
Ctor.precision = pr
|
|
1711
|
-
return sum2
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
sum2 = t
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
__name(naturalExponential, 'naturalExponential')
|
|
1718
|
-
__name2(naturalExponential, 'naturalExponential')
|
|
1719
|
-
function naturalLogarithm(y, sd) {
|
|
1720
|
-
var c,
|
|
1721
|
-
c0,
|
|
1722
|
-
denominator,
|
|
1723
|
-
e,
|
|
1724
|
-
numerator,
|
|
1725
|
-
rep,
|
|
1726
|
-
sum2,
|
|
1727
|
-
t,
|
|
1728
|
-
wpr,
|
|
1729
|
-
x1,
|
|
1730
|
-
x2,
|
|
1731
|
-
n = 1,
|
|
1732
|
-
guard = 10,
|
|
1733
|
-
x = y,
|
|
1734
|
-
xd = x.d,
|
|
1735
|
-
Ctor = x.constructor,
|
|
1736
|
-
rm = Ctor.rounding,
|
|
1737
|
-
pr = Ctor.precision
|
|
1738
|
-
if (x.s < 0 || !xd || !xd[0] || (!x.e && xd[0] == 1 && xd.length == 1)) {
|
|
1739
|
-
return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x)
|
|
1740
|
-
}
|
|
1741
|
-
if (sd == null) {
|
|
1742
|
-
external = false
|
|
1743
|
-
wpr = pr
|
|
1744
|
-
} else {
|
|
1745
|
-
wpr = sd
|
|
1746
|
-
}
|
|
1747
|
-
Ctor.precision = wpr += guard
|
|
1748
|
-
c = digitsToString(xd)
|
|
1749
|
-
c0 = c.charAt(0)
|
|
1750
|
-
if (Math.abs((e = x.e)) < 15e14) {
|
|
1751
|
-
while ((c0 < 7 && c0 != 1) || (c0 == 1 && c.charAt(1) > 3)) {
|
|
1752
|
-
x = x.times(y)
|
|
1753
|
-
c = digitsToString(x.d)
|
|
1754
|
-
c0 = c.charAt(0)
|
|
1755
|
-
n++
|
|
1756
|
-
}
|
|
1757
|
-
e = x.e
|
|
1758
|
-
if (c0 > 1) {
|
|
1759
|
-
x = new Ctor('0.' + c)
|
|
1760
|
-
e++
|
|
1761
|
-
} else {
|
|
1762
|
-
x = new Ctor(c0 + '.' + c.slice(1))
|
|
1763
|
-
}
|
|
1764
|
-
} else {
|
|
1765
|
-
t = getLn10(Ctor, wpr + 2, pr).times(e + '')
|
|
1766
|
-
x = naturalLogarithm(new Ctor(c0 + '.' + c.slice(1)), wpr - guard).plus(t)
|
|
1767
|
-
Ctor.precision = pr
|
|
1768
|
-
return sd == null ? finalise(x, pr, rm, (external = true)) : x
|
|
1769
|
-
}
|
|
1770
|
-
x1 = x
|
|
1771
|
-
sum2 = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1)
|
|
1772
|
-
x2 = finalise(x.times(x), wpr, 1)
|
|
1773
|
-
denominator = 3
|
|
1774
|
-
for (;;) {
|
|
1775
|
-
numerator = finalise(numerator.times(x2), wpr, 1)
|
|
1776
|
-
t = sum2.plus(divide(numerator, new Ctor(denominator), wpr, 1))
|
|
1777
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
|
|
1778
|
-
sum2 = sum2.times(2)
|
|
1779
|
-
if (e !== 0) sum2 = sum2.plus(getLn10(Ctor, wpr + 2, pr).times(e + ''))
|
|
1780
|
-
sum2 = divide(sum2, new Ctor(n), wpr, 1)
|
|
1781
|
-
if (sd == null) {
|
|
1782
|
-
if (checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
|
|
1783
|
-
Ctor.precision = wpr += guard
|
|
1784
|
-
t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1)
|
|
1785
|
-
x2 = finalise(x.times(x), wpr, 1)
|
|
1786
|
-
denominator = rep = 1
|
|
1787
|
-
} else {
|
|
1788
|
-
return finalise(sum2, (Ctor.precision = pr), rm, (external = true))
|
|
1789
|
-
}
|
|
1790
|
-
} else {
|
|
1791
|
-
Ctor.precision = pr
|
|
1792
|
-
return sum2
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
sum2 = t
|
|
1796
|
-
denominator += 2
|
|
1797
|
-
}
|
|
1798
|
-
}
|
|
1799
|
-
__name(naturalLogarithm, 'naturalLogarithm')
|
|
1800
|
-
__name2(naturalLogarithm, 'naturalLogarithm')
|
|
1801
|
-
function nonFiniteToString(x) {
|
|
1802
|
-
return String((x.s * x.s) / 0)
|
|
1803
|
-
}
|
|
1804
|
-
__name(nonFiniteToString, 'nonFiniteToString')
|
|
1805
|
-
__name2(nonFiniteToString, 'nonFiniteToString')
|
|
1806
|
-
function parseDecimal(x, str) {
|
|
1807
|
-
var e, i, len
|
|
1808
|
-
if ((e = str.indexOf('.')) > -1) str = str.replace('.', '')
|
|
1809
|
-
if ((i = str.search(/e/i)) > 0) {
|
|
1810
|
-
if (e < 0) e = i
|
|
1811
|
-
e += +str.slice(i + 1)
|
|
1812
|
-
str = str.substring(0, i)
|
|
1813
|
-
} else if (e < 0) {
|
|
1814
|
-
e = str.length
|
|
1815
|
-
}
|
|
1816
|
-
for (i = 0; str.charCodeAt(i) === 48; i++);
|
|
1817
|
-
for (len = str.length; str.charCodeAt(len - 1) === 48; --len);
|
|
1818
|
-
str = str.slice(i, len)
|
|
1819
|
-
if (str) {
|
|
1820
|
-
len -= i
|
|
1821
|
-
x.e = e = e - i - 1
|
|
1822
|
-
x.d = []
|
|
1823
|
-
i = (e + 1) % LOG_BASE
|
|
1824
|
-
if (e < 0) i += LOG_BASE
|
|
1825
|
-
if (i < len) {
|
|
1826
|
-
if (i) x.d.push(+str.slice(0, i))
|
|
1827
|
-
for (len -= LOG_BASE; i < len; ) x.d.push(+str.slice(i, (i += LOG_BASE)))
|
|
1828
|
-
str = str.slice(i)
|
|
1829
|
-
i = LOG_BASE - str.length
|
|
1830
|
-
} else {
|
|
1831
|
-
i -= len
|
|
1832
|
-
}
|
|
1833
|
-
for (; i--; ) str += '0'
|
|
1834
|
-
x.d.push(+str)
|
|
1835
|
-
if (external) {
|
|
1836
|
-
if (x.e > x.constructor.maxE) {
|
|
1837
|
-
x.d = null
|
|
1838
|
-
x.e = NaN
|
|
1839
|
-
} else if (x.e < x.constructor.minE) {
|
|
1840
|
-
x.e = 0
|
|
1841
|
-
x.d = [0]
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
} else {
|
|
1845
|
-
x.e = 0
|
|
1846
|
-
x.d = [0]
|
|
1847
|
-
}
|
|
1848
|
-
return x
|
|
1849
|
-
}
|
|
1850
|
-
__name(parseDecimal, 'parseDecimal')
|
|
1851
|
-
__name2(parseDecimal, 'parseDecimal')
|
|
1852
|
-
function parseOther(x, str) {
|
|
1853
|
-
var base, Ctor, divisor, i, isFloat, len, p, xd, xe
|
|
1854
|
-
if (str.indexOf('_') > -1) {
|
|
1855
|
-
str = str.replace(/(\d)_(?=\d)/g, '$1')
|
|
1856
|
-
if (isDecimal.test(str)) return parseDecimal(x, str)
|
|
1857
|
-
} else if (str === 'Infinity' || str === 'NaN') {
|
|
1858
|
-
if (!+str) x.s = NaN
|
|
1859
|
-
x.e = NaN
|
|
1860
|
-
x.d = null
|
|
1861
|
-
return x
|
|
1862
|
-
}
|
|
1863
|
-
if (isHex.test(str)) {
|
|
1864
|
-
base = 16
|
|
1865
|
-
str = str.toLowerCase()
|
|
1866
|
-
} else if (isBinary.test(str)) {
|
|
1867
|
-
base = 2
|
|
1868
|
-
} else if (isOctal.test(str)) {
|
|
1869
|
-
base = 8
|
|
1870
|
-
} else {
|
|
1871
|
-
throw Error(invalidArgument + str)
|
|
1872
|
-
}
|
|
1873
|
-
i = str.search(/p/i)
|
|
1874
|
-
if (i > 0) {
|
|
1875
|
-
p = +str.slice(i + 1)
|
|
1876
|
-
str = str.substring(2, i)
|
|
1877
|
-
} else {
|
|
1878
|
-
str = str.slice(2)
|
|
1879
|
-
}
|
|
1880
|
-
i = str.indexOf('.')
|
|
1881
|
-
isFloat = i >= 0
|
|
1882
|
-
Ctor = x.constructor
|
|
1883
|
-
if (isFloat) {
|
|
1884
|
-
str = str.replace('.', '')
|
|
1885
|
-
len = str.length
|
|
1886
|
-
i = len - i
|
|
1887
|
-
divisor = intPow(Ctor, new Ctor(base), i, i * 2)
|
|
1888
|
-
}
|
|
1889
|
-
xd = convertBase(str, base, BASE)
|
|
1890
|
-
xe = xd.length - 1
|
|
1891
|
-
for (i = xe; xd[i] === 0; --i) xd.pop()
|
|
1892
|
-
if (i < 0) return new Ctor(x.s * 0)
|
|
1893
|
-
x.e = getBase10Exponent(xd, xe)
|
|
1894
|
-
x.d = xd
|
|
1895
|
-
external = false
|
|
1896
|
-
if (isFloat) x = divide(x, divisor, len * 4)
|
|
1897
|
-
if (p) x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p))
|
|
1898
|
-
external = true
|
|
1899
|
-
return x
|
|
1900
|
-
}
|
|
1901
|
-
__name(parseOther, 'parseOther')
|
|
1902
|
-
__name2(parseOther, 'parseOther')
|
|
1903
|
-
function sine(Ctor, x) {
|
|
1904
|
-
var k,
|
|
1905
|
-
len = x.d.length
|
|
1906
|
-
if (len < 3) {
|
|
1907
|
-
return x.isZero() ? x : taylorSeries(Ctor, 2, x, x)
|
|
1908
|
-
}
|
|
1909
|
-
k = 1.4 * Math.sqrt(len)
|
|
1910
|
-
k = k > 16 ? 16 : k | 0
|
|
1911
|
-
x = x.times(1 / tinyPow(5, k))
|
|
1912
|
-
x = taylorSeries(Ctor, 2, x, x)
|
|
1913
|
-
var sin2_x,
|
|
1914
|
-
d5 = new Ctor(5),
|
|
1915
|
-
d16 = new Ctor(16),
|
|
1916
|
-
d20 = new Ctor(20)
|
|
1917
|
-
for (; k--; ) {
|
|
1918
|
-
sin2_x = x.times(x)
|
|
1919
|
-
x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))))
|
|
1920
|
-
}
|
|
1921
|
-
return x
|
|
1922
|
-
}
|
|
1923
|
-
__name(sine, 'sine')
|
|
1924
|
-
__name2(sine, 'sine')
|
|
1925
|
-
function taylorSeries(Ctor, n, x, y, isHyperbolic) {
|
|
1926
|
-
var j,
|
|
1927
|
-
t,
|
|
1928
|
-
u,
|
|
1929
|
-
x2,
|
|
1930
|
-
i = 1,
|
|
1931
|
-
pr = Ctor.precision,
|
|
1932
|
-
k = Math.ceil(pr / LOG_BASE)
|
|
1933
|
-
external = false
|
|
1934
|
-
x2 = x.times(x)
|
|
1935
|
-
u = new Ctor(y)
|
|
1936
|
-
for (;;) {
|
|
1937
|
-
t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1)
|
|
1938
|
-
u = isHyperbolic ? y.plus(t) : y.minus(t)
|
|
1939
|
-
y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1)
|
|
1940
|
-
t = u.plus(y)
|
|
1941
|
-
if (t.d[k] !== void 0) {
|
|
1942
|
-
for (j = k; t.d[j] === u.d[j] && j--; );
|
|
1943
|
-
if (j == -1) break
|
|
1944
|
-
}
|
|
1945
|
-
j = u
|
|
1946
|
-
u = y
|
|
1947
|
-
y = t
|
|
1948
|
-
t = j
|
|
1949
|
-
i++
|
|
1950
|
-
}
|
|
1951
|
-
external = true
|
|
1952
|
-
t.d.length = k + 1
|
|
1953
|
-
return t
|
|
1954
|
-
}
|
|
1955
|
-
__name(taylorSeries, 'taylorSeries')
|
|
1956
|
-
__name2(taylorSeries, 'taylorSeries')
|
|
1957
|
-
function tinyPow(b, e) {
|
|
1958
|
-
var n = b
|
|
1959
|
-
while (--e) n *= b
|
|
1960
|
-
return n
|
|
1961
|
-
}
|
|
1962
|
-
__name(tinyPow, 'tinyPow')
|
|
1963
|
-
__name2(tinyPow, 'tinyPow')
|
|
1964
|
-
function toLessThanHalfPi(Ctor, x) {
|
|
1965
|
-
var t,
|
|
1966
|
-
isNeg = x.s < 0,
|
|
1967
|
-
pi = getPi(Ctor, Ctor.precision, 1),
|
|
1968
|
-
halfPi = pi.times(0.5)
|
|
1969
|
-
x = x.abs()
|
|
1970
|
-
if (x.lte(halfPi)) {
|
|
1971
|
-
quadrant = isNeg ? 4 : 1
|
|
1972
|
-
return x
|
|
1973
|
-
}
|
|
1974
|
-
t = x.divToInt(pi)
|
|
1975
|
-
if (t.isZero()) {
|
|
1976
|
-
quadrant = isNeg ? 3 : 2
|
|
1977
|
-
} else {
|
|
1978
|
-
x = x.minus(t.times(pi))
|
|
1979
|
-
if (x.lte(halfPi)) {
|
|
1980
|
-
quadrant = isOdd(t) ? (isNeg ? 2 : 3) : isNeg ? 4 : 1
|
|
1981
|
-
return x
|
|
1982
|
-
}
|
|
1983
|
-
quadrant = isOdd(t) ? (isNeg ? 1 : 4) : isNeg ? 3 : 2
|
|
1984
|
-
}
|
|
1985
|
-
return x.minus(pi).abs()
|
|
1986
|
-
}
|
|
1987
|
-
__name(toLessThanHalfPi, 'toLessThanHalfPi')
|
|
1988
|
-
__name2(toLessThanHalfPi, 'toLessThanHalfPi')
|
|
1989
|
-
function toStringBinary(x, baseOut, sd, rm) {
|
|
1990
|
-
var base,
|
|
1991
|
-
e,
|
|
1992
|
-
i,
|
|
1993
|
-
k,
|
|
1994
|
-
len,
|
|
1995
|
-
roundUp,
|
|
1996
|
-
str,
|
|
1997
|
-
xd,
|
|
1998
|
-
y,
|
|
1999
|
-
Ctor = x.constructor,
|
|
2000
|
-
isExp = sd !== void 0
|
|
2001
|
-
if (isExp) {
|
|
2002
|
-
checkInt32(sd, 1, MAX_DIGITS)
|
|
2003
|
-
if (rm === void 0) rm = Ctor.rounding
|
|
2004
|
-
else checkInt32(rm, 0, 8)
|
|
2005
|
-
} else {
|
|
2006
|
-
sd = Ctor.precision
|
|
2007
|
-
rm = Ctor.rounding
|
|
2008
|
-
}
|
|
2009
|
-
if (!x.isFinite()) {
|
|
2010
|
-
str = nonFiniteToString(x)
|
|
2011
|
-
} else {
|
|
2012
|
-
str = finiteToString(x)
|
|
2013
|
-
i = str.indexOf('.')
|
|
2014
|
-
if (isExp) {
|
|
2015
|
-
base = 2
|
|
2016
|
-
if (baseOut == 16) {
|
|
2017
|
-
sd = sd * 4 - 3
|
|
2018
|
-
} else if (baseOut == 8) {
|
|
2019
|
-
sd = sd * 3 - 2
|
|
2020
|
-
}
|
|
2021
|
-
} else {
|
|
2022
|
-
base = baseOut
|
|
2023
|
-
}
|
|
2024
|
-
if (i >= 0) {
|
|
2025
|
-
str = str.replace('.', '')
|
|
2026
|
-
y = new Ctor(1)
|
|
2027
|
-
y.e = str.length - i
|
|
2028
|
-
y.d = convertBase(finiteToString(y), 10, base)
|
|
2029
|
-
y.e = y.d.length
|
|
2030
|
-
}
|
|
2031
|
-
xd = convertBase(str, 10, base)
|
|
2032
|
-
e = len = xd.length
|
|
2033
|
-
for (; xd[--len] == 0; ) xd.pop()
|
|
2034
|
-
if (!xd[0]) {
|
|
2035
|
-
str = isExp ? '0p+0' : '0'
|
|
2036
|
-
} else {
|
|
2037
|
-
if (i < 0) {
|
|
2038
|
-
e--
|
|
2039
|
-
} else {
|
|
2040
|
-
x = new Ctor(x)
|
|
2041
|
-
x.d = xd
|
|
2042
|
-
x.e = e
|
|
2043
|
-
x = divide(x, y, sd, rm, 0, base)
|
|
2044
|
-
xd = x.d
|
|
2045
|
-
e = x.e
|
|
2046
|
-
roundUp = inexact
|
|
2047
|
-
}
|
|
2048
|
-
i = xd[sd]
|
|
2049
|
-
k = base / 2
|
|
2050
|
-
roundUp = roundUp || xd[sd + 1] !== void 0
|
|
2051
|
-
roundUp =
|
|
2052
|
-
rm < 4
|
|
2053
|
-
? (i !== void 0 || roundUp) && (rm === 0 || rm === (x.s < 0 ? 3 : 2))
|
|
2054
|
-
: i > k ||
|
|
2055
|
-
(i === k &&
|
|
2056
|
-
(rm === 4 || roundUp || (rm === 6 && xd[sd - 1] & 1) || rm === (x.s < 0 ? 8 : 7)))
|
|
2057
|
-
xd.length = sd
|
|
2058
|
-
if (roundUp) {
|
|
2059
|
-
for (; ++xd[--sd] > base - 1; ) {
|
|
2060
|
-
xd[sd] = 0
|
|
2061
|
-
if (!sd) {
|
|
2062
|
-
++e
|
|
2063
|
-
xd.unshift(1)
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
for (len = xd.length; !xd[len - 1]; --len);
|
|
2068
|
-
for (i = 0, str = ''; i < len; i++) str += NUMERALS.charAt(xd[i])
|
|
2069
|
-
if (isExp) {
|
|
2070
|
-
if (len > 1) {
|
|
2071
|
-
if (baseOut == 16 || baseOut == 8) {
|
|
2072
|
-
i = baseOut == 16 ? 4 : 3
|
|
2073
|
-
for (--len; len % i; len++) str += '0'
|
|
2074
|
-
xd = convertBase(str, base, baseOut)
|
|
2075
|
-
for (len = xd.length; !xd[len - 1]; --len);
|
|
2076
|
-
for (i = 1, str = '1.'; i < len; i++) str += NUMERALS.charAt(xd[i])
|
|
2077
|
-
} else {
|
|
2078
|
-
str = str.charAt(0) + '.' + str.slice(1)
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
str = str + (e < 0 ? 'p' : 'p+') + e
|
|
2082
|
-
} else if (e < 0) {
|
|
2083
|
-
for (; ++e; ) str = '0' + str
|
|
2084
|
-
str = '0.' + str
|
|
2085
|
-
} else {
|
|
2086
|
-
if (++e > len) for (e -= len; e--; ) str += '0'
|
|
2087
|
-
else if (e < len) str = str.slice(0, e) + '.' + str.slice(e)
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
str = (baseOut == 16 ? '0x' : baseOut == 2 ? '0b' : baseOut == 8 ? '0o' : '') + str
|
|
2091
|
-
}
|
|
2092
|
-
return x.s < 0 ? '-' + str : str
|
|
2093
|
-
}
|
|
2094
|
-
__name(toStringBinary, 'toStringBinary')
|
|
2095
|
-
__name2(toStringBinary, 'toStringBinary')
|
|
2096
|
-
function truncate(arr, len) {
|
|
2097
|
-
if (arr.length > len) {
|
|
2098
|
-
arr.length = len
|
|
2099
|
-
return true
|
|
2100
|
-
}
|
|
2101
|
-
}
|
|
2102
|
-
__name(truncate, 'truncate')
|
|
2103
|
-
__name2(truncate, 'truncate')
|
|
2104
|
-
function abs(x) {
|
|
2105
|
-
return new this(x).abs()
|
|
2106
|
-
}
|
|
2107
|
-
__name(abs, 'abs')
|
|
2108
|
-
__name2(abs, 'abs')
|
|
2109
|
-
function acos(x) {
|
|
2110
|
-
return new this(x).acos()
|
|
2111
|
-
}
|
|
2112
|
-
__name(acos, 'acos')
|
|
2113
|
-
__name2(acos, 'acos')
|
|
2114
|
-
function acosh(x) {
|
|
2115
|
-
return new this(x).acosh()
|
|
2116
|
-
}
|
|
2117
|
-
__name(acosh, 'acosh')
|
|
2118
|
-
__name2(acosh, 'acosh')
|
|
2119
|
-
function add(x, y) {
|
|
2120
|
-
return new this(x).plus(y)
|
|
2121
|
-
}
|
|
2122
|
-
__name(add, 'add')
|
|
2123
|
-
__name2(add, 'add')
|
|
2124
|
-
function asin(x) {
|
|
2125
|
-
return new this(x).asin()
|
|
2126
|
-
}
|
|
2127
|
-
__name(asin, 'asin')
|
|
2128
|
-
__name2(asin, 'asin')
|
|
2129
|
-
function asinh(x) {
|
|
2130
|
-
return new this(x).asinh()
|
|
2131
|
-
}
|
|
2132
|
-
__name(asinh, 'asinh')
|
|
2133
|
-
__name2(asinh, 'asinh')
|
|
2134
|
-
function atan(x) {
|
|
2135
|
-
return new this(x).atan()
|
|
2136
|
-
}
|
|
2137
|
-
__name(atan, 'atan')
|
|
2138
|
-
__name2(atan, 'atan')
|
|
2139
|
-
function atanh(x) {
|
|
2140
|
-
return new this(x).atanh()
|
|
2141
|
-
}
|
|
2142
|
-
__name(atanh, 'atanh')
|
|
2143
|
-
__name2(atanh, 'atanh')
|
|
2144
|
-
function atan2(y, x) {
|
|
2145
|
-
y = new this(y)
|
|
2146
|
-
x = new this(x)
|
|
2147
|
-
var r,
|
|
2148
|
-
pr = this.precision,
|
|
2149
|
-
rm = this.rounding,
|
|
2150
|
-
wpr = pr + 4
|
|
2151
|
-
if (!y.s || !x.s) {
|
|
2152
|
-
r = new this(NaN)
|
|
2153
|
-
} else if (!y.d && !x.d) {
|
|
2154
|
-
r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75)
|
|
2155
|
-
r.s = y.s
|
|
2156
|
-
} else if (!x.d || y.isZero()) {
|
|
2157
|
-
r = x.s < 0 ? getPi(this, pr, rm) : new this(0)
|
|
2158
|
-
r.s = y.s
|
|
2159
|
-
} else if (!y.d || x.isZero()) {
|
|
2160
|
-
r = getPi(this, wpr, 1).times(0.5)
|
|
2161
|
-
r.s = y.s
|
|
2162
|
-
} else if (x.s < 0) {
|
|
2163
|
-
this.precision = wpr
|
|
2164
|
-
this.rounding = 1
|
|
2165
|
-
r = this.atan(divide(y, x, wpr, 1))
|
|
2166
|
-
x = getPi(this, wpr, 1)
|
|
2167
|
-
this.precision = pr
|
|
2168
|
-
this.rounding = rm
|
|
2169
|
-
r = y.s < 0 ? r.minus(x) : r.plus(x)
|
|
2170
|
-
} else {
|
|
2171
|
-
r = this.atan(divide(y, x, wpr, 1))
|
|
2172
|
-
}
|
|
2173
|
-
return r
|
|
2174
|
-
}
|
|
2175
|
-
__name(atan2, 'atan2')
|
|
2176
|
-
__name2(atan2, 'atan2')
|
|
2177
|
-
function cbrt(x) {
|
|
2178
|
-
return new this(x).cbrt()
|
|
2179
|
-
}
|
|
2180
|
-
__name(cbrt, 'cbrt')
|
|
2181
|
-
__name2(cbrt, 'cbrt')
|
|
2182
|
-
function ceil(x) {
|
|
2183
|
-
return finalise((x = new this(x)), x.e + 1, 2)
|
|
2184
|
-
}
|
|
2185
|
-
__name(ceil, 'ceil')
|
|
2186
|
-
__name2(ceil, 'ceil')
|
|
2187
|
-
function clamp(x, min2, max2) {
|
|
2188
|
-
return new this(x).clamp(min2, max2)
|
|
2189
|
-
}
|
|
2190
|
-
__name(clamp, 'clamp')
|
|
2191
|
-
__name2(clamp, 'clamp')
|
|
2192
|
-
function config(obj) {
|
|
2193
|
-
if (!obj || typeof obj !== 'object') throw Error(decimalError + 'Object expected')
|
|
2194
|
-
var i,
|
|
2195
|
-
p,
|
|
2196
|
-
v,
|
|
2197
|
-
useDefaults = obj.defaults === true,
|
|
2198
|
-
ps = [
|
|
2199
|
-
'precision',
|
|
2200
|
-
1,
|
|
2201
|
-
MAX_DIGITS,
|
|
2202
|
-
'rounding',
|
|
2203
|
-
0,
|
|
2204
|
-
8,
|
|
2205
|
-
'toExpNeg',
|
|
2206
|
-
-EXP_LIMIT,
|
|
2207
|
-
0,
|
|
2208
|
-
'toExpPos',
|
|
2209
|
-
0,
|
|
2210
|
-
EXP_LIMIT,
|
|
2211
|
-
'maxE',
|
|
2212
|
-
0,
|
|
2213
|
-
EXP_LIMIT,
|
|
2214
|
-
'minE',
|
|
2215
|
-
-EXP_LIMIT,
|
|
2216
|
-
0,
|
|
2217
|
-
'modulo',
|
|
2218
|
-
0,
|
|
2219
|
-
9,
|
|
2220
|
-
]
|
|
2221
|
-
for (i = 0; i < ps.length; i += 3) {
|
|
2222
|
-
if (((p = ps[i]), useDefaults)) this[p] = DEFAULTS[p]
|
|
2223
|
-
if ((v = obj[p]) !== void 0) {
|
|
2224
|
-
if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2]) this[p] = v
|
|
2225
|
-
else throw Error(invalidArgument + p + ': ' + v)
|
|
2226
|
-
}
|
|
2227
|
-
}
|
|
2228
|
-
if (((p = 'crypto'), useDefaults)) this[p] = DEFAULTS[p]
|
|
2229
|
-
if ((v = obj[p]) !== void 0) {
|
|
2230
|
-
if (v === true || v === false || v === 0 || v === 1) {
|
|
2231
|
-
if (v) {
|
|
2232
|
-
if (
|
|
2233
|
-
typeof crypto != 'undefined' &&
|
|
2234
|
-
crypto &&
|
|
2235
|
-
(crypto.getRandomValues || crypto.randomBytes)
|
|
2236
|
-
) {
|
|
2237
|
-
this[p] = true
|
|
2238
|
-
} else {
|
|
2239
|
-
throw Error(cryptoUnavailable)
|
|
2240
|
-
}
|
|
2241
|
-
} else {
|
|
2242
|
-
this[p] = false
|
|
2243
|
-
}
|
|
2244
|
-
} else {
|
|
2245
|
-
throw Error(invalidArgument + p + ': ' + v)
|
|
2246
|
-
}
|
|
2247
|
-
}
|
|
2248
|
-
return this
|
|
2249
|
-
}
|
|
2250
|
-
__name(config, 'config')
|
|
2251
|
-
__name2(config, 'config')
|
|
2252
|
-
function cos(x) {
|
|
2253
|
-
return new this(x).cos()
|
|
2254
|
-
}
|
|
2255
|
-
__name(cos, 'cos')
|
|
2256
|
-
__name2(cos, 'cos')
|
|
2257
|
-
function cosh(x) {
|
|
2258
|
-
return new this(x).cosh()
|
|
2259
|
-
}
|
|
2260
|
-
__name(cosh, 'cosh')
|
|
2261
|
-
__name2(cosh, 'cosh')
|
|
2262
|
-
function clone(obj) {
|
|
2263
|
-
var i, p, ps
|
|
2264
|
-
function Decimal2(v) {
|
|
2265
|
-
var e,
|
|
2266
|
-
i2,
|
|
2267
|
-
t,
|
|
2268
|
-
x = this
|
|
2269
|
-
if (!(x instanceof Decimal2)) return new Decimal2(v)
|
|
2270
|
-
x.constructor = Decimal2
|
|
2271
|
-
if (isDecimalInstance(v)) {
|
|
2272
|
-
x.s = v.s
|
|
2273
|
-
if (external) {
|
|
2274
|
-
if (!v.d || v.e > Decimal2.maxE) {
|
|
2275
|
-
x.e = NaN
|
|
2276
|
-
x.d = null
|
|
2277
|
-
} else if (v.e < Decimal2.minE) {
|
|
2278
|
-
x.e = 0
|
|
2279
|
-
x.d = [0]
|
|
2280
|
-
} else {
|
|
2281
|
-
x.e = v.e
|
|
2282
|
-
x.d = v.d.slice()
|
|
2283
|
-
}
|
|
2284
|
-
} else {
|
|
2285
|
-
x.e = v.e
|
|
2286
|
-
x.d = v.d ? v.d.slice() : v.d
|
|
2287
|
-
}
|
|
2288
|
-
return
|
|
2289
|
-
}
|
|
2290
|
-
t = typeof v
|
|
2291
|
-
if (t === 'number') {
|
|
2292
|
-
if (v === 0) {
|
|
2293
|
-
x.s = 1 / v < 0 ? -1 : 1
|
|
2294
|
-
x.e = 0
|
|
2295
|
-
x.d = [0]
|
|
2296
|
-
return
|
|
2297
|
-
}
|
|
2298
|
-
if (v < 0) {
|
|
2299
|
-
v = -v
|
|
2300
|
-
x.s = -1
|
|
2301
|
-
} else {
|
|
2302
|
-
x.s = 1
|
|
2303
|
-
}
|
|
2304
|
-
if (v === ~~v && v < 1e7) {
|
|
2305
|
-
for (e = 0, i2 = v; i2 >= 10; i2 /= 10) e++
|
|
2306
|
-
if (external) {
|
|
2307
|
-
if (e > Decimal2.maxE) {
|
|
2308
|
-
x.e = NaN
|
|
2309
|
-
x.d = null
|
|
2310
|
-
} else if (e < Decimal2.minE) {
|
|
2311
|
-
x.e = 0
|
|
2312
|
-
x.d = [0]
|
|
2313
|
-
} else {
|
|
2314
|
-
x.e = e
|
|
2315
|
-
x.d = [v]
|
|
2316
|
-
}
|
|
2317
|
-
} else {
|
|
2318
|
-
x.e = e
|
|
2319
|
-
x.d = [v]
|
|
2320
|
-
}
|
|
2321
|
-
return
|
|
2322
|
-
} else if (v * 0 !== 0) {
|
|
2323
|
-
if (!v) x.s = NaN
|
|
2324
|
-
x.e = NaN
|
|
2325
|
-
x.d = null
|
|
2326
|
-
return
|
|
2327
|
-
}
|
|
2328
|
-
return parseDecimal(x, v.toString())
|
|
2329
|
-
} else if (t !== 'string') {
|
|
2330
|
-
throw Error(invalidArgument + v)
|
|
2331
|
-
}
|
|
2332
|
-
if ((i2 = v.charCodeAt(0)) === 45) {
|
|
2333
|
-
v = v.slice(1)
|
|
2334
|
-
x.s = -1
|
|
2335
|
-
} else {
|
|
2336
|
-
if (i2 === 43) v = v.slice(1)
|
|
2337
|
-
x.s = 1
|
|
2338
|
-
}
|
|
2339
|
-
return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v)
|
|
2340
|
-
}
|
|
2341
|
-
__name(Decimal2, 'Decimal2')
|
|
2342
|
-
__name2(Decimal2, 'Decimal')
|
|
2343
|
-
Decimal2.prototype = P
|
|
2344
|
-
Decimal2.ROUND_UP = 0
|
|
2345
|
-
Decimal2.ROUND_DOWN = 1
|
|
2346
|
-
Decimal2.ROUND_CEIL = 2
|
|
2347
|
-
Decimal2.ROUND_FLOOR = 3
|
|
2348
|
-
Decimal2.ROUND_HALF_UP = 4
|
|
2349
|
-
Decimal2.ROUND_HALF_DOWN = 5
|
|
2350
|
-
Decimal2.ROUND_HALF_EVEN = 6
|
|
2351
|
-
Decimal2.ROUND_HALF_CEIL = 7
|
|
2352
|
-
Decimal2.ROUND_HALF_FLOOR = 8
|
|
2353
|
-
Decimal2.EUCLID = 9
|
|
2354
|
-
Decimal2.config = Decimal2.set = config
|
|
2355
|
-
Decimal2.clone = clone
|
|
2356
|
-
Decimal2.isDecimal = isDecimalInstance
|
|
2357
|
-
Decimal2.abs = abs
|
|
2358
|
-
Decimal2.acos = acos
|
|
2359
|
-
Decimal2.acosh = acosh
|
|
2360
|
-
Decimal2.add = add
|
|
2361
|
-
Decimal2.asin = asin
|
|
2362
|
-
Decimal2.asinh = asinh
|
|
2363
|
-
Decimal2.atan = atan
|
|
2364
|
-
Decimal2.atanh = atanh
|
|
2365
|
-
Decimal2.atan2 = atan2
|
|
2366
|
-
Decimal2.cbrt = cbrt
|
|
2367
|
-
Decimal2.ceil = ceil
|
|
2368
|
-
Decimal2.clamp = clamp
|
|
2369
|
-
Decimal2.cos = cos
|
|
2370
|
-
Decimal2.cosh = cosh
|
|
2371
|
-
Decimal2.div = div
|
|
2372
|
-
Decimal2.exp = exp
|
|
2373
|
-
Decimal2.floor = floor
|
|
2374
|
-
Decimal2.hypot = hypot
|
|
2375
|
-
Decimal2.ln = ln
|
|
2376
|
-
Decimal2.log = log
|
|
2377
|
-
Decimal2.log10 = log10
|
|
2378
|
-
Decimal2.log2 = log2
|
|
2379
|
-
Decimal2.max = max
|
|
2380
|
-
Decimal2.min = min
|
|
2381
|
-
Decimal2.mod = mod
|
|
2382
|
-
Decimal2.mul = mul
|
|
2383
|
-
Decimal2.pow = pow
|
|
2384
|
-
Decimal2.random = random
|
|
2385
|
-
Decimal2.round = round
|
|
2386
|
-
Decimal2.sign = sign
|
|
2387
|
-
Decimal2.sin = sin
|
|
2388
|
-
Decimal2.sinh = sinh
|
|
2389
|
-
Decimal2.sqrt = sqrt
|
|
2390
|
-
Decimal2.sub = sub
|
|
2391
|
-
Decimal2.sum = sum
|
|
2392
|
-
Decimal2.tan = tan
|
|
2393
|
-
Decimal2.tanh = tanh
|
|
2394
|
-
Decimal2.trunc = trunc
|
|
2395
|
-
if (obj === void 0) obj = {}
|
|
2396
|
-
if (obj) {
|
|
2397
|
-
if (obj.defaults !== true) {
|
|
2398
|
-
ps = ['precision', 'rounding', 'toExpNeg', 'toExpPos', 'maxE', 'minE', 'modulo', 'crypto']
|
|
2399
|
-
for (i = 0; i < ps.length; ) if (!obj.hasOwnProperty((p = ps[i++]))) obj[p] = this[p]
|
|
2400
|
-
}
|
|
2401
|
-
}
|
|
2402
|
-
Decimal2.config(obj)
|
|
2403
|
-
return Decimal2
|
|
2404
|
-
}
|
|
2405
|
-
__name(clone, 'clone')
|
|
2406
|
-
__name2(clone, 'clone')
|
|
2407
|
-
function div(x, y) {
|
|
2408
|
-
return new this(x).div(y)
|
|
2409
|
-
}
|
|
2410
|
-
__name(div, 'div')
|
|
2411
|
-
__name2(div, 'div')
|
|
2412
|
-
function exp(x) {
|
|
2413
|
-
return new this(x).exp()
|
|
2414
|
-
}
|
|
2415
|
-
__name(exp, 'exp')
|
|
2416
|
-
__name2(exp, 'exp')
|
|
2417
|
-
function floor(x) {
|
|
2418
|
-
return finalise((x = new this(x)), x.e + 1, 3)
|
|
2419
|
-
}
|
|
2420
|
-
__name(floor, 'floor')
|
|
2421
|
-
__name2(floor, 'floor')
|
|
2422
|
-
function hypot() {
|
|
2423
|
-
var i,
|
|
2424
|
-
n,
|
|
2425
|
-
t = new this(0)
|
|
2426
|
-
external = false
|
|
2427
|
-
for (i = 0; i < arguments.length; ) {
|
|
2428
|
-
n = new this(arguments[i++])
|
|
2429
|
-
if (!n.d) {
|
|
2430
|
-
if (n.s) {
|
|
2431
|
-
external = true
|
|
2432
|
-
return new this(1 / 0)
|
|
2433
|
-
}
|
|
2434
|
-
t = n
|
|
2435
|
-
} else if (t.d) {
|
|
2436
|
-
t = t.plus(n.times(n))
|
|
2437
|
-
}
|
|
2438
|
-
}
|
|
2439
|
-
external = true
|
|
2440
|
-
return t.sqrt()
|
|
2441
|
-
}
|
|
2442
|
-
__name(hypot, 'hypot')
|
|
2443
|
-
__name2(hypot, 'hypot')
|
|
2444
|
-
function isDecimalInstance(obj) {
|
|
2445
|
-
return obj instanceof Decimal || (obj && obj.toStringTag === tag) || false
|
|
2446
|
-
}
|
|
2447
|
-
__name(isDecimalInstance, 'isDecimalInstance')
|
|
2448
|
-
__name2(isDecimalInstance, 'isDecimalInstance')
|
|
2449
|
-
function ln(x) {
|
|
2450
|
-
return new this(x).ln()
|
|
2451
|
-
}
|
|
2452
|
-
__name(ln, 'ln')
|
|
2453
|
-
__name2(ln, 'ln')
|
|
2454
|
-
function log(x, y) {
|
|
2455
|
-
return new this(x).log(y)
|
|
2456
|
-
}
|
|
2457
|
-
__name(log, 'log')
|
|
2458
|
-
__name2(log, 'log')
|
|
2459
|
-
function log2(x) {
|
|
2460
|
-
return new this(x).log(2)
|
|
2461
|
-
}
|
|
2462
|
-
__name(log2, 'log2')
|
|
2463
|
-
__name2(log2, 'log2')
|
|
2464
|
-
function log10(x) {
|
|
2465
|
-
return new this(x).log(10)
|
|
2466
|
-
}
|
|
2467
|
-
__name(log10, 'log10')
|
|
2468
|
-
__name2(log10, 'log10')
|
|
2469
|
-
function max() {
|
|
2470
|
-
return maxOrMin(this, arguments, 'lt')
|
|
2471
|
-
}
|
|
2472
|
-
__name(max, 'max')
|
|
2473
|
-
__name2(max, 'max')
|
|
2474
|
-
function min() {
|
|
2475
|
-
return maxOrMin(this, arguments, 'gt')
|
|
2476
|
-
}
|
|
2477
|
-
__name(min, 'min')
|
|
2478
|
-
__name2(min, 'min')
|
|
2479
|
-
function mod(x, y) {
|
|
2480
|
-
return new this(x).mod(y)
|
|
2481
|
-
}
|
|
2482
|
-
__name(mod, 'mod')
|
|
2483
|
-
__name2(mod, 'mod')
|
|
2484
|
-
function mul(x, y) {
|
|
2485
|
-
return new this(x).mul(y)
|
|
2486
|
-
}
|
|
2487
|
-
__name(mul, 'mul')
|
|
2488
|
-
__name2(mul, 'mul')
|
|
2489
|
-
function pow(x, y) {
|
|
2490
|
-
return new this(x).pow(y)
|
|
2491
|
-
}
|
|
2492
|
-
__name(pow, 'pow')
|
|
2493
|
-
__name2(pow, 'pow')
|
|
2494
|
-
function random(sd) {
|
|
2495
|
-
var d,
|
|
2496
|
-
e,
|
|
2497
|
-
k,
|
|
2498
|
-
n,
|
|
2499
|
-
i = 0,
|
|
2500
|
-
r = new this(1),
|
|
2501
|
-
rd = []
|
|
2502
|
-
if (sd === void 0) sd = this.precision
|
|
2503
|
-
else checkInt32(sd, 1, MAX_DIGITS)
|
|
2504
|
-
k = Math.ceil(sd / LOG_BASE)
|
|
2505
|
-
if (!this.crypto) {
|
|
2506
|
-
for (; i < k; ) rd[i++] = (Math.random() * 1e7) | 0
|
|
2507
|
-
} else if (crypto.getRandomValues) {
|
|
2508
|
-
d = crypto.getRandomValues(new Uint32Array(k))
|
|
2509
|
-
for (; i < k; ) {
|
|
2510
|
-
n = d[i]
|
|
2511
|
-
if (n >= 429e7) {
|
|
2512
|
-
d[i] = crypto.getRandomValues(new Uint32Array(1))[0]
|
|
2513
|
-
} else {
|
|
2514
|
-
rd[i++] = n % 1e7
|
|
2515
|
-
}
|
|
2516
|
-
}
|
|
2517
|
-
} else if (crypto.randomBytes) {
|
|
2518
|
-
d = crypto.randomBytes((k *= 4))
|
|
2519
|
-
for (; i < k; ) {
|
|
2520
|
-
n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24)
|
|
2521
|
-
if (n >= 214e7) {
|
|
2522
|
-
crypto.randomBytes(4).copy(d, i)
|
|
2523
|
-
} else {
|
|
2524
|
-
rd.push(n % 1e7)
|
|
2525
|
-
i += 4
|
|
2526
|
-
}
|
|
2527
|
-
}
|
|
2528
|
-
i = k / 4
|
|
2529
|
-
} else {
|
|
2530
|
-
throw Error(cryptoUnavailable)
|
|
2531
|
-
}
|
|
2532
|
-
k = rd[--i]
|
|
2533
|
-
sd %= LOG_BASE
|
|
2534
|
-
if (k && sd) {
|
|
2535
|
-
n = mathpow(10, LOG_BASE - sd)
|
|
2536
|
-
rd[i] = ((k / n) | 0) * n
|
|
2537
|
-
}
|
|
2538
|
-
for (; rd[i] === 0; i--) rd.pop()
|
|
2539
|
-
if (i < 0) {
|
|
2540
|
-
e = 0
|
|
2541
|
-
rd = [0]
|
|
2542
|
-
} else {
|
|
2543
|
-
e = -1
|
|
2544
|
-
for (; rd[0] === 0; e -= LOG_BASE) rd.shift()
|
|
2545
|
-
for (k = 1, n = rd[0]; n >= 10; n /= 10) k++
|
|
2546
|
-
if (k < LOG_BASE) e -= LOG_BASE - k
|
|
2547
|
-
}
|
|
2548
|
-
r.e = e
|
|
2549
|
-
r.d = rd
|
|
2550
|
-
return r
|
|
2551
|
-
}
|
|
2552
|
-
__name(random, 'random')
|
|
2553
|
-
__name2(random, 'random')
|
|
2554
|
-
function round(x) {
|
|
2555
|
-
return finalise((x = new this(x)), x.e + 1, this.rounding)
|
|
2556
|
-
}
|
|
2557
|
-
__name(round, 'round')
|
|
2558
|
-
__name2(round, 'round')
|
|
2559
|
-
function sign(x) {
|
|
2560
|
-
x = new this(x)
|
|
2561
|
-
return x.d ? (x.d[0] ? x.s : 0 * x.s) : x.s || NaN
|
|
2562
|
-
}
|
|
2563
|
-
__name(sign, 'sign')
|
|
2564
|
-
__name2(sign, 'sign')
|
|
2565
|
-
function sin(x) {
|
|
2566
|
-
return new this(x).sin()
|
|
2567
|
-
}
|
|
2568
|
-
__name(sin, 'sin')
|
|
2569
|
-
__name2(sin, 'sin')
|
|
2570
|
-
function sinh(x) {
|
|
2571
|
-
return new this(x).sinh()
|
|
2572
|
-
}
|
|
2573
|
-
__name(sinh, 'sinh')
|
|
2574
|
-
__name2(sinh, 'sinh')
|
|
2575
|
-
function sqrt(x) {
|
|
2576
|
-
return new this(x).sqrt()
|
|
2577
|
-
}
|
|
2578
|
-
__name(sqrt, 'sqrt')
|
|
2579
|
-
__name2(sqrt, 'sqrt')
|
|
2580
|
-
function sub(x, y) {
|
|
2581
|
-
return new this(x).sub(y)
|
|
2582
|
-
}
|
|
2583
|
-
__name(sub, 'sub')
|
|
2584
|
-
__name2(sub, 'sub')
|
|
2585
|
-
function sum() {
|
|
2586
|
-
var i = 0,
|
|
2587
|
-
args = arguments,
|
|
2588
|
-
x = new this(args[i])
|
|
2589
|
-
external = false
|
|
2590
|
-
for (; x.s && ++i < args.length; ) x = x.plus(args[i])
|
|
2591
|
-
external = true
|
|
2592
|
-
return finalise(x, this.precision, this.rounding)
|
|
2593
|
-
}
|
|
2594
|
-
__name(sum, 'sum')
|
|
2595
|
-
__name2(sum, 'sum')
|
|
2596
|
-
function tan(x) {
|
|
2597
|
-
return new this(x).tan()
|
|
2598
|
-
}
|
|
2599
|
-
__name(tan, 'tan')
|
|
2600
|
-
__name2(tan, 'tan')
|
|
2601
|
-
function tanh(x) {
|
|
2602
|
-
return new this(x).tanh()
|
|
2603
|
-
}
|
|
2604
|
-
__name(tanh, 'tanh')
|
|
2605
|
-
__name2(tanh, 'tanh')
|
|
2606
|
-
function trunc(x) {
|
|
2607
|
-
return finalise((x = new this(x)), x.e + 1, 1)
|
|
2608
|
-
}
|
|
2609
|
-
__name(trunc, 'trunc')
|
|
2610
|
-
__name2(trunc, 'trunc')
|
|
2611
|
-
P[Symbol.for('nodejs.util.inspect.custom')] = P.toString
|
|
2612
|
-
P[Symbol.toStringTag] = 'Decimal'
|
|
2613
|
-
var Decimal = (P.constructor = clone(DEFAULTS))
|
|
2614
|
-
LN10 = new Decimal(LN10)
|
|
2615
|
-
PI = new Decimal(PI)
|
|
2616
|
-
var decimal_default = Decimal
|
|
2617
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
2618
|
-
0 &&
|
|
2619
|
-
(module.exports = {
|
|
2620
|
-
Decimal,
|
|
2621
|
-
})
|