@wzyjs/utils 0.3.4 → 0.3.6
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/common/ai/302/image/index.d.ts +0 -1
- package/dist/common/ai/302/index.d.ts +0 -2
- package/dist/common/index.d.ts +3 -5
- package/dist/node.cjs.js +158 -3289
- package/dist/node.esm.js +155 -3286
- package/dist/web.cjs.js +112 -3238
- package/dist/web.esm.js +119 -3245
- package/package.json +2 -2
- package/dist/common/ai/302/audio/doubao.d.ts +0 -29
- package/dist/common/ai/302/audio/index.d.ts +0 -2
- package/dist/common/ai/302/audio/tts.d.ts +0 -51
- package/dist/common/ai/302/image/gpt.d.ts +0 -97
- package/dist/common/ai/doubao/index.d.ts +0 -2
- package/dist/common/ai/doubao/tts.d.ts +0 -30
- package/dist/common/ai/doubao/vc.d.ts +0 -21
package/dist/node.esm.js
CHANGED
|
@@ -723,7 +723,7 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
723
723
|
var objectCtorString = funcToString.call(Object2);
|
|
724
724
|
var oldDash = root._;
|
|
725
725
|
var reIsNative = RegExp2("^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$");
|
|
726
|
-
var Buffer2 = moduleExports ? context.Buffer : undefined2, Symbol2 = context.Symbol,
|
|
726
|
+
var Buffer2 = moduleExports ? context.Buffer : undefined2, Symbol2 = context.Symbol, Uint8Array = context.Uint8Array, allocUnsafe = Buffer2 ? Buffer2.allocUnsafe : undefined2, getPrototype = overArg(Object2.getPrototypeOf, Object2), objectCreate = Object2.create, propertyIsEnumerable = objectProto.propertyIsEnumerable, splice = arrayProto.splice, spreadableSymbol = Symbol2 ? Symbol2.isConcatSpreadable : undefined2, symIterator = Symbol2 ? Symbol2.iterator : undefined2, symToStringTag = Symbol2 ? Symbol2.toStringTag : undefined2;
|
|
727
727
|
var defineProperty = function() {
|
|
728
728
|
try {
|
|
729
729
|
var func = getNative(Object2, "defineProperty");
|
|
@@ -1189,7 +1189,7 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
1189
1189
|
if (typeof func != "function") {
|
|
1190
1190
|
throw new TypeError2(FUNC_ERROR_TEXT);
|
|
1191
1191
|
}
|
|
1192
|
-
return
|
|
1192
|
+
return setTimeout(function() {
|
|
1193
1193
|
func.apply(undefined2, args);
|
|
1194
1194
|
}, wait);
|
|
1195
1195
|
}
|
|
@@ -1981,7 +1981,7 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
1981
1981
|
}
|
|
1982
1982
|
function cloneArrayBuffer(arrayBuffer) {
|
|
1983
1983
|
var result2 = new arrayBuffer.constructor(arrayBuffer.byteLength);
|
|
1984
|
-
new
|
|
1984
|
+
new Uint8Array(result2).set(new Uint8Array(arrayBuffer));
|
|
1985
1985
|
return result2;
|
|
1986
1986
|
}
|
|
1987
1987
|
function cloneDataView(dataView, isDeep) {
|
|
@@ -2563,7 +2563,7 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
2563
2563
|
object = object.buffer;
|
|
2564
2564
|
other = other.buffer;
|
|
2565
2565
|
case arrayBufferTag:
|
|
2566
|
-
if (object.byteLength != other.byteLength || !equalFunc(new
|
|
2566
|
+
if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
|
|
2567
2567
|
return false;
|
|
2568
2568
|
}
|
|
2569
2569
|
return true;
|
|
@@ -2998,7 +2998,7 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
2998
2998
|
return object[key];
|
|
2999
2999
|
}
|
|
3000
3000
|
var setData = shortOut(baseSetData);
|
|
3001
|
-
var
|
|
3001
|
+
var setTimeout = ctxSetTimeout || function(func, wait) {
|
|
3002
3002
|
return root.setTimeout(func, wait);
|
|
3003
3003
|
};
|
|
3004
3004
|
var setToString = shortOut(baseSetToString);
|
|
@@ -3788,7 +3788,7 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
3788
3788
|
}
|
|
3789
3789
|
function leadingEdge(time) {
|
|
3790
3790
|
lastInvokeTime = time;
|
|
3791
|
-
timerId =
|
|
3791
|
+
timerId = setTimeout(timerExpired, wait);
|
|
3792
3792
|
return leading ? invokeFunc(time) : result2;
|
|
3793
3793
|
}
|
|
3794
3794
|
function remainingWait(time) {
|
|
@@ -3804,7 +3804,7 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
3804
3804
|
if (shouldInvoke(time)) {
|
|
3805
3805
|
return trailingEdge(time);
|
|
3806
3806
|
}
|
|
3807
|
-
timerId =
|
|
3807
|
+
timerId = setTimeout(timerExpired, remainingWait(time));
|
|
3808
3808
|
}
|
|
3809
3809
|
function trailingEdge(time) {
|
|
3810
3810
|
timerId = undefined2;
|
|
@@ -3835,12 +3835,12 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
3835
3835
|
}
|
|
3836
3836
|
if (maxing) {
|
|
3837
3837
|
clearTimeout(timerId);
|
|
3838
|
-
timerId =
|
|
3838
|
+
timerId = setTimeout(timerExpired, wait);
|
|
3839
3839
|
return invokeFunc(lastCallTime);
|
|
3840
3840
|
}
|
|
3841
3841
|
}
|
|
3842
3842
|
if (timerId === undefined2) {
|
|
3843
|
-
timerId =
|
|
3843
|
+
timerId = setTimeout(timerExpired, wait);
|
|
3844
3844
|
}
|
|
3845
3845
|
return result2;
|
|
3846
3846
|
}
|
|
@@ -4047,7 +4047,7 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
4047
4047
|
var tag = baseGetTag(value);
|
|
4048
4048
|
return tag == errorTag || tag == domExcTag || typeof value.message == "string" && typeof value.name == "string" && !isPlainObject(value);
|
|
4049
4049
|
}
|
|
4050
|
-
function
|
|
4050
|
+
function isFinite(value) {
|
|
4051
4051
|
return typeof value == "number" && nativeIsFinite(value);
|
|
4052
4052
|
}
|
|
4053
4053
|
function isFunction(value) {
|
|
@@ -4078,7 +4078,7 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
4078
4078
|
customizer = typeof customizer == "function" ? customizer : undefined2;
|
|
4079
4079
|
return baseIsMatch(object, source, getMatchData(source), customizer);
|
|
4080
4080
|
}
|
|
4081
|
-
function
|
|
4081
|
+
function isNaN(value) {
|
|
4082
4082
|
return isNumber(value) && value != +value;
|
|
4083
4083
|
}
|
|
4084
4084
|
function isNative(value) {
|
|
@@ -4737,7 +4737,7 @@ __p += '`;
|
|
|
4737
4737
|
}
|
|
4738
4738
|
return result2 + omission;
|
|
4739
4739
|
}
|
|
4740
|
-
function
|
|
4740
|
+
function unescape(string) {
|
|
4741
4741
|
string = toString(string);
|
|
4742
4742
|
return string && reHasEscapedHtml.test(string) ? string.replace(reEscapedHtml, unescapeHtmlChar) : string;
|
|
4743
4743
|
}
|
|
@@ -5161,14 +5161,14 @@ __p += '`;
|
|
|
5161
5161
|
lodash.isEqual = isEqual;
|
|
5162
5162
|
lodash.isEqualWith = isEqualWith;
|
|
5163
5163
|
lodash.isError = isError;
|
|
5164
|
-
lodash.isFinite =
|
|
5164
|
+
lodash.isFinite = isFinite;
|
|
5165
5165
|
lodash.isFunction = isFunction;
|
|
5166
5166
|
lodash.isInteger = isInteger;
|
|
5167
5167
|
lodash.isLength = isLength;
|
|
5168
5168
|
lodash.isMap = isMap;
|
|
5169
5169
|
lodash.isMatch = isMatch;
|
|
5170
5170
|
lodash.isMatchWith = isMatchWith;
|
|
5171
|
-
lodash.isNaN =
|
|
5171
|
+
lodash.isNaN = isNaN;
|
|
5172
5172
|
lodash.isNative = isNative;
|
|
5173
5173
|
lodash.isNil = isNil;
|
|
5174
5174
|
lodash.isNull = isNull;
|
|
@@ -5250,7 +5250,7 @@ __p += '`;
|
|
|
5250
5250
|
lodash.trimEnd = trimEnd;
|
|
5251
5251
|
lodash.trimStart = trimStart;
|
|
5252
5252
|
lodash.truncate = truncate;
|
|
5253
|
-
lodash.unescape =
|
|
5253
|
+
lodash.unescape = unescape;
|
|
5254
5254
|
lodash.uniqueId = uniqueId;
|
|
5255
5255
|
lodash.upperCase = upperCase;
|
|
5256
5256
|
lodash.upperFirst = upperFirst;
|
|
@@ -9422,14 +9422,6 @@ var coerce = {
|
|
|
9422
9422
|
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
9423
9423
|
};
|
|
9424
9424
|
var NEVER = INVALID;
|
|
9425
|
-
// src/common/ai/302/index.ts
|
|
9426
|
-
var exports_302 = {};
|
|
9427
|
-
__export(exports_302, {
|
|
9428
|
-
image: () => exports_image,
|
|
9429
|
-
chat: () => chat,
|
|
9430
|
-
audio: () => exports_audio
|
|
9431
|
-
});
|
|
9432
|
-
|
|
9433
9425
|
// src/common/ai/302/axios.ts
|
|
9434
9426
|
import axios_ from "axios";
|
|
9435
9427
|
var key = process.env.AI_302_KEY || process.env.NEXT_PUBLIC_AI_302_KEY;
|
|
@@ -9453,7 +9445,7 @@ var chat = async (message, model = "gpt-4.1", isParse = true) => {
|
|
|
9453
9445
|
message
|
|
9454
9446
|
}
|
|
9455
9447
|
});
|
|
9456
|
-
console.log(666,
|
|
9448
|
+
console.log(666, typeof data, data);
|
|
9457
9449
|
const output = typeof data === "string" ? json5.parse(data)?.output : data?.output;
|
|
9458
9450
|
if (isParse) {
|
|
9459
9451
|
const match = /```(json)?(.*)```/s.exec(output);
|
|
@@ -9465,423 +9457,16 @@ var chat = async (message, model = "gpt-4.1", isParse = true) => {
|
|
|
9465
9457
|
}
|
|
9466
9458
|
return output;
|
|
9467
9459
|
} catch (error) {
|
|
9468
|
-
|
|
9469
|
-
const message2 = responseData?.error?.message_cn || responseData?.error?.message || responseData?.message || error?.response?.statusText || error?.message || "未知原因";
|
|
9470
|
-
throw new Error(message2);
|
|
9471
|
-
}
|
|
9472
|
-
};
|
|
9473
|
-
// src/common/ai/302/audio/index.ts
|
|
9474
|
-
var exports_audio = {};
|
|
9475
|
-
__export(exports_audio, {
|
|
9476
|
-
tts: () => exports_tts,
|
|
9477
|
-
doubao: () => exports_doubao
|
|
9478
|
-
});
|
|
9479
|
-
|
|
9480
|
-
// src/common/ai/302/audio/tts.ts
|
|
9481
|
-
var exports_tts = {};
|
|
9482
|
-
__export(exports_tts, {
|
|
9483
|
-
textToSpeech: () => textToSpeech,
|
|
9484
|
-
fetchTask: () => fetchTask,
|
|
9485
|
-
fetchProviders: () => fetchProviders
|
|
9486
|
-
});
|
|
9487
|
-
var fetchProviders = async () => {
|
|
9488
|
-
try {
|
|
9489
|
-
const { data } = await axios({
|
|
9490
|
-
url: "/302/tts/provider",
|
|
9491
|
-
method: "get"
|
|
9492
|
-
});
|
|
9493
|
-
return data;
|
|
9494
|
-
} catch (error) {
|
|
9495
|
-
throw error;
|
|
9496
|
-
}
|
|
9497
|
-
};
|
|
9498
|
-
var textToSpeech = async (request) => {
|
|
9499
|
-
try {
|
|
9500
|
-
const { webhook, run_async, ...body } = request;
|
|
9501
|
-
const { data } = await axios({
|
|
9502
|
-
url: "/302/v2/audio/tts",
|
|
9503
|
-
method: "post",
|
|
9504
|
-
params: {
|
|
9505
|
-
webhook,
|
|
9506
|
-
run_async
|
|
9507
|
-
},
|
|
9508
|
-
data: {
|
|
9509
|
-
...body,
|
|
9510
|
-
speed: body.speed ?? 1,
|
|
9511
|
-
volume: body.volume ?? 1,
|
|
9512
|
-
timeout: body.timeout ?? 180
|
|
9513
|
-
}
|
|
9514
|
-
});
|
|
9515
|
-
return data;
|
|
9516
|
-
} catch (error) {
|
|
9517
|
-
throw error;
|
|
9518
|
-
}
|
|
9519
|
-
};
|
|
9520
|
-
var fetchTask = async (taskId) => {
|
|
9521
|
-
if (!taskId) {
|
|
9522
|
-
throw new Error("taskId 不能为空");
|
|
9523
|
-
}
|
|
9524
|
-
try {
|
|
9525
|
-
const { data } = await axios({
|
|
9526
|
-
url: `/302/v2/audio/fetch/${encodeURIComponent(taskId)}`,
|
|
9527
|
-
method: "get"
|
|
9528
|
-
});
|
|
9529
|
-
return data;
|
|
9530
|
-
} catch (error) {
|
|
9531
|
-
throw error;
|
|
9532
|
-
}
|
|
9533
|
-
};
|
|
9534
|
-
// src/common/ai/302/audio/doubao.ts
|
|
9535
|
-
var exports_doubao = {};
|
|
9536
|
-
__export(exports_doubao, {
|
|
9537
|
-
ttsHd: () => ttsHd
|
|
9538
|
-
});
|
|
9539
|
-
var createReqid = () => {
|
|
9540
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
9541
|
-
return crypto.randomUUID();
|
|
9542
|
-
}
|
|
9543
|
-
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
9544
|
-
};
|
|
9545
|
-
var getUtf8ByteLength = (value) => {
|
|
9546
|
-
return new TextEncoder().encode(value).length;
|
|
9547
|
-
};
|
|
9548
|
-
var assertNonEmptyString = (value, label) => {
|
|
9549
|
-
if (typeof value !== "string" || !value.trim()) {
|
|
9550
|
-
throw new Error(`${label} 不能为空`);
|
|
9551
|
-
}
|
|
9552
|
-
};
|
|
9553
|
-
var assertSpeedRatio = (value) => {
|
|
9554
|
-
if (value === undefined)
|
|
9555
|
-
return;
|
|
9556
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
9557
|
-
throw new Error("speed_ratio 必须为数字");
|
|
9558
|
-
}
|
|
9559
|
-
if (value < 0.8 || value > 2) {
|
|
9560
|
-
throw new Error("speed_ratio 取值范围为 [0.8, 2]");
|
|
9561
|
-
}
|
|
9562
|
-
};
|
|
9563
|
-
var ttsHd = async (payload) => {
|
|
9564
|
-
const { audio, request } = payload;
|
|
9565
|
-
const { voice_type, encoding, speed_ratio } = audio;
|
|
9566
|
-
const { text, reqid: rawReqid, operation } = request;
|
|
9567
|
-
assertNonEmptyString(voice_type, "voice_type");
|
|
9568
|
-
assertNonEmptyString(text, "text");
|
|
9569
|
-
assertSpeedRatio(speed_ratio);
|
|
9570
|
-
const textByteLength = getUtf8ByteLength(text);
|
|
9571
|
-
if (textByteLength > 1024) {
|
|
9572
|
-
throw new Error(`text 超出长度限制:${textByteLength}/1024 字节`);
|
|
9573
|
-
}
|
|
9574
|
-
const reqid = rawReqid?.trim() || createReqid();
|
|
9575
|
-
const { data } = await axios({
|
|
9576
|
-
url: "/doubao/tts_hd",
|
|
9577
|
-
method: "post",
|
|
9578
|
-
data: {
|
|
9579
|
-
audio: {
|
|
9580
|
-
voice_type,
|
|
9581
|
-
encoding: encoding ?? "pcm",
|
|
9582
|
-
speed_ratio: speed_ratio ?? 1
|
|
9583
|
-
},
|
|
9584
|
-
request: {
|
|
9585
|
-
reqid,
|
|
9586
|
-
text,
|
|
9587
|
-
operation: operation ?? "query"
|
|
9588
|
-
}
|
|
9589
|
-
}
|
|
9590
|
-
});
|
|
9591
|
-
return data;
|
|
9592
|
-
};
|
|
9593
|
-
// src/common/ai/302/image/index.ts
|
|
9594
|
-
var exports_image = {};
|
|
9595
|
-
__export(exports_image, {
|
|
9596
|
-
midjourney: () => exports_midjourney,
|
|
9597
|
-
gpt: () => exports_gpt
|
|
9598
|
-
});
|
|
9599
|
-
|
|
9600
|
-
// src/common/ai/302/image/midjourney.ts
|
|
9601
|
-
var exports_midjourney = {};
|
|
9602
|
-
__export(exports_midjourney, {
|
|
9603
|
-
getImageStatus: () => getImageStatus,
|
|
9604
|
-
generateImage: () => generateImage
|
|
9605
|
-
});
|
|
9606
|
-
var generateImage = async (prompt, base64Array) => {
|
|
9607
|
-
try {
|
|
9608
|
-
const { data } = await axios({
|
|
9609
|
-
url: "/mj/submit/imagine",
|
|
9610
|
-
method: "post",
|
|
9611
|
-
data: {
|
|
9612
|
-
prompt,
|
|
9613
|
-
base64Array,
|
|
9614
|
-
botType: "MID_JOURNEY",
|
|
9615
|
-
notifyHook: "",
|
|
9616
|
-
state: ""
|
|
9617
|
-
}
|
|
9618
|
-
});
|
|
9619
|
-
return data;
|
|
9620
|
-
} catch (error) {
|
|
9621
|
-
throw error;
|
|
9622
|
-
}
|
|
9623
|
-
};
|
|
9624
|
-
var getImageStatus = async (taskId) => {
|
|
9625
|
-
try {
|
|
9626
|
-
const { data } = await axios({
|
|
9627
|
-
url: `/mj/task/${taskId}/fetch`,
|
|
9628
|
-
method: "get"
|
|
9629
|
-
});
|
|
9630
|
-
return data;
|
|
9631
|
-
} catch (error) {
|
|
9632
|
-
throw error;
|
|
9633
|
-
}
|
|
9634
|
-
};
|
|
9635
|
-
// src/common/ai/302/image/gpt.ts
|
|
9636
|
-
var exports_gpt = {};
|
|
9637
|
-
__export(exports_gpt, {
|
|
9638
|
-
generateImage: () => generateImage2
|
|
9639
|
-
});
|
|
9640
|
-
var generateImage2 = async (params) => {
|
|
9641
|
-
if (params.model === "gpt-4o-plus") {
|
|
9642
|
-
const { data: data2 } = await axios.post("/v1/chat/completions", {
|
|
9643
|
-
model: params.model,
|
|
9644
|
-
messages: [{ role: "user", content: params.prompt }]
|
|
9645
|
-
});
|
|
9646
|
-
const content = data2?.choices?.[0]?.message?.content || "";
|
|
9647
|
-
const urlMatch = content.match(/!\[.*?\]\((.*?)\)/) || content.match(/(https?:\/\/[^\s]+)/);
|
|
9648
|
-
const url = urlMatch ? urlMatch[1] : content;
|
|
9649
|
-
return {
|
|
9650
|
-
background: "",
|
|
9651
|
-
created: data2.created,
|
|
9652
|
-
data: [{ url }],
|
|
9653
|
-
output_format: "",
|
|
9654
|
-
quality: "",
|
|
9655
|
-
size: "",
|
|
9656
|
-
usage: {
|
|
9657
|
-
input_tokens: data2.usage?.prompt_tokens || 0,
|
|
9658
|
-
input_tokens_details: {
|
|
9659
|
-
image_tokens: data2.usage?.prompt_tokens_details?.image_tokens || 0,
|
|
9660
|
-
text_tokens: data2.usage?.prompt_tokens_details?.text_tokens || 0
|
|
9661
|
-
},
|
|
9662
|
-
output_tokens: data2.usage?.completion_tokens || 0,
|
|
9663
|
-
output_tokens_details: {
|
|
9664
|
-
image_tokens: data2.usage?.completion_tokens_details?.image_tokens || 0,
|
|
9665
|
-
text_tokens: data2.usage?.completion_tokens_details?.content_tokens || 0
|
|
9666
|
-
},
|
|
9667
|
-
total_tokens: data2.usage?.total_tokens || 0
|
|
9668
|
-
}
|
|
9669
|
-
};
|
|
9670
|
-
}
|
|
9671
|
-
const { data } = await axios.post("/v1/images/generations", params);
|
|
9672
|
-
return data;
|
|
9673
|
-
};
|
|
9674
|
-
// src/common/ai/doubao/index.ts
|
|
9675
|
-
var exports_doubao2 = {};
|
|
9676
|
-
__export(exports_doubao2, {
|
|
9677
|
-
vc: () => vc,
|
|
9678
|
-
tts: () => tts
|
|
9679
|
-
});
|
|
9680
|
-
|
|
9681
|
-
// src/common/ai/doubao/tts.ts
|
|
9682
|
-
import axios2 from "axios";
|
|
9683
|
-
var createReqid2 = () => {
|
|
9684
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
9685
|
-
return crypto.randomUUID();
|
|
9686
|
-
}
|
|
9687
|
-
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
9688
|
-
};
|
|
9689
|
-
var decodeBase64ToArrayBuffer = (value) => {
|
|
9690
|
-
if (typeof window !== "undefined" && typeof window.atob === "function") {
|
|
9691
|
-
const binary = window.atob(value);
|
|
9692
|
-
const bytes = new Uint8Array(binary.length);
|
|
9693
|
-
for (let i = 0;i < binary.length; i++) {
|
|
9694
|
-
bytes[i] = binary.charCodeAt(i);
|
|
9695
|
-
}
|
|
9696
|
-
return bytes.buffer;
|
|
9697
|
-
}
|
|
9698
|
-
const buf = Buffer.from(value, "base64");
|
|
9699
|
-
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
9700
|
-
};
|
|
9701
|
-
var tts = async (params) => {
|
|
9702
|
-
const { app, user, audio, request } = params;
|
|
9703
|
-
const url = "https://openspeech.bytedance.com/api/v3/tts/unidirectional";
|
|
9704
|
-
const reqid = request.reqid || createReqid2();
|
|
9705
|
-
const speechRate = audio.speed_ratio ? Math.round((audio.speed_ratio - 1) * 100) : 0;
|
|
9706
|
-
const loudnessRate = audio.volume_ratio ? Math.round((audio.volume_ratio - 1) * 100) : 0;
|
|
9707
|
-
const headers = {
|
|
9708
|
-
"X-Api-App-Id": app.appid || "",
|
|
9709
|
-
"X-Api-Access-Key": app.accessToken || "",
|
|
9710
|
-
"Content-Type": "application/json",
|
|
9711
|
-
"X-Api-Resource-Id": app.resourceId || "seed-tts-2.0",
|
|
9712
|
-
"X-Api-Request-Id": reqid
|
|
9713
|
-
};
|
|
9714
|
-
const payload = {
|
|
9715
|
-
user: {
|
|
9716
|
-
uid: user?.uid || "uid"
|
|
9717
|
-
},
|
|
9718
|
-
req_params: {
|
|
9719
|
-
text: request.text,
|
|
9720
|
-
speaker: audio.voice_type,
|
|
9721
|
-
audio_params: {
|
|
9722
|
-
format: audio.encoding || "pcm",
|
|
9723
|
-
sample_rate: 24000,
|
|
9724
|
-
speech_rate: speechRate,
|
|
9725
|
-
loudness_rate: loudnessRate,
|
|
9726
|
-
emotion: audio.emotion,
|
|
9727
|
-
emotion_scale: audio.emotion_scale
|
|
9728
|
-
}
|
|
9729
|
-
}
|
|
9730
|
-
};
|
|
9731
|
-
if (audio.context_texts) {
|
|
9732
|
-
payload.req_params.additions = JSON.stringify({
|
|
9733
|
-
context_texts: audio.context_texts
|
|
9734
|
-
});
|
|
9735
|
-
}
|
|
9736
|
-
try {
|
|
9737
|
-
const response = await axios2.post(url, payload, {
|
|
9738
|
-
headers,
|
|
9739
|
-
responseType: "arraybuffer"
|
|
9740
|
-
});
|
|
9741
|
-
const responseText = new TextDecoder().decode(response.data);
|
|
9742
|
-
const jsonObjects = [];
|
|
9743
|
-
let depth = 0;
|
|
9744
|
-
let start = 0;
|
|
9745
|
-
for (let i = 0;i < responseText.length; i++) {
|
|
9746
|
-
if (responseText[i] === "{") {
|
|
9747
|
-
if (depth === 0)
|
|
9748
|
-
start = i;
|
|
9749
|
-
depth++;
|
|
9750
|
-
} else if (responseText[i] === "}") {
|
|
9751
|
-
depth--;
|
|
9752
|
-
if (depth === 0) {
|
|
9753
|
-
try {
|
|
9754
|
-
const jsonStr = responseText.substring(start, i + 1);
|
|
9755
|
-
const jsonObj = JSON.parse(jsonStr);
|
|
9756
|
-
jsonObjects.push(jsonObj);
|
|
9757
|
-
} catch (e) {
|
|
9758
|
-
console.warn("Failed to parse JSON chunk", e);
|
|
9759
|
-
}
|
|
9760
|
-
}
|
|
9761
|
-
}
|
|
9762
|
-
}
|
|
9763
|
-
if (jsonObjects.length === 0) {
|
|
9764
|
-
try {
|
|
9765
|
-
jsonObjects.push(JSON.parse(responseText));
|
|
9766
|
-
} catch (e) {
|
|
9767
|
-
console.error("Doubao TTS Response Parse Error:", responseText);
|
|
9768
|
-
throw new Error("Invalid response format");
|
|
9769
|
-
}
|
|
9770
|
-
}
|
|
9771
|
-
const audioChunks = [];
|
|
9772
|
-
let totalLength = 0;
|
|
9773
|
-
for (const data of jsonObjects) {
|
|
9774
|
-
const code = data.code;
|
|
9775
|
-
const message = data.message;
|
|
9776
|
-
if (typeof code === "number" && code !== 0 && code !== 20000000) {
|
|
9777
|
-
console.error("Doubao TTS Error Response:", JSON.stringify(data, null, 2));
|
|
9778
|
-
const err = new Error(`豆包语音合成失败: ${message} (code: ${code})`);
|
|
9779
|
-
err.code = code;
|
|
9780
|
-
err.reqid = data.reqid;
|
|
9781
|
-
throw err;
|
|
9782
|
-
}
|
|
9783
|
-
if (data.data) {
|
|
9784
|
-
const chunkBuffer = decodeBase64ToArrayBuffer(data.data);
|
|
9785
|
-
audioChunks.push(chunkBuffer);
|
|
9786
|
-
totalLength += chunkBuffer.byteLength;
|
|
9787
|
-
}
|
|
9788
|
-
}
|
|
9789
|
-
if (totalLength === 0) {
|
|
9790
|
-
throw new Error("豆包语音合成失败:未返回音频数据");
|
|
9791
|
-
}
|
|
9792
|
-
const resultBuffer = new Uint8Array(totalLength);
|
|
9793
|
-
let offset = 0;
|
|
9794
|
-
for (const chunk of audioChunks) {
|
|
9795
|
-
resultBuffer.set(new Uint8Array(chunk), offset);
|
|
9796
|
-
offset += chunk.byteLength;
|
|
9797
|
-
}
|
|
9798
|
-
return resultBuffer.buffer;
|
|
9799
|
-
} catch (error) {
|
|
9800
|
-
if (error.response) {
|
|
9801
|
-
try {
|
|
9802
|
-
let errorData = error.response.data;
|
|
9803
|
-
if (errorData instanceof ArrayBuffer || typeof Buffer !== "undefined" && Buffer.isBuffer(errorData)) {
|
|
9804
|
-
errorData = new TextDecoder().decode(errorData);
|
|
9805
|
-
} else if (typeof errorData === "object") {
|
|
9806
|
-
errorData = JSON.stringify(errorData);
|
|
9807
|
-
}
|
|
9808
|
-
throw new Error(`Doubao TTS Error: ${error.response.status} - ${errorData}`);
|
|
9809
|
-
} catch (e) {
|
|
9810
|
-
if (e.message && e.message.startsWith("Doubao TTS Error")) {
|
|
9811
|
-
throw e;
|
|
9812
|
-
}
|
|
9813
|
-
throw new Error(`Doubao TTS Error: ${error.response.status} ${error.message}`);
|
|
9814
|
-
}
|
|
9815
|
-
}
|
|
9816
|
-
throw error;
|
|
9817
|
-
}
|
|
9818
|
-
};
|
|
9819
|
-
// src/common/ai/doubao/vc.ts
|
|
9820
|
-
import axios3 from "axios";
|
|
9821
|
-
var getHeaders = (accessToken, contentType) => {
|
|
9822
|
-
const headers = {
|
|
9823
|
-
Authorization: `Bearer; ${accessToken}`
|
|
9824
|
-
};
|
|
9825
|
-
if (contentType) {
|
|
9826
|
-
headers["content-type"] = contentType;
|
|
9827
|
-
}
|
|
9828
|
-
return headers;
|
|
9829
|
-
};
|
|
9830
|
-
var handleResponse = (data) => {
|
|
9831
|
-
if (data instanceof ArrayBuffer) {
|
|
9832
|
-
return data;
|
|
9833
|
-
}
|
|
9834
|
-
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
|
|
9835
|
-
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
9836
|
-
}
|
|
9837
|
-
return data;
|
|
9838
|
-
};
|
|
9839
|
-
var vc = {
|
|
9840
|
-
submit: async (params) => {
|
|
9841
|
-
const { app, audio, options = {} } = params;
|
|
9842
|
-
const url = new URL("https://openspeech.bytedance.com/api/v1/vc/submit");
|
|
9843
|
-
url.searchParams.set("appid", app.appid);
|
|
9844
|
-
Object.entries(options).forEach(([key2, value]) => {
|
|
9845
|
-
if (value !== undefined && value !== null) {
|
|
9846
|
-
url.searchParams.set(key2, String(value));
|
|
9847
|
-
}
|
|
9848
|
-
});
|
|
9849
|
-
const response = await axios3.post(url.toString(), audio.data, {
|
|
9850
|
-
headers: getHeaders(app.accessToken, audio.contentType || "audio/wav"),
|
|
9851
|
-
responseType: "arraybuffer"
|
|
9852
|
-
});
|
|
9853
|
-
return handleResponse(response.data);
|
|
9854
|
-
},
|
|
9855
|
-
query: async (params) => {
|
|
9856
|
-
const { app, id, blocking } = params;
|
|
9857
|
-
const url = new URL("https://openspeech.bytedance.com/api/v1/vc/query");
|
|
9858
|
-
url.searchParams.set("appid", app.appid);
|
|
9859
|
-
url.searchParams.set("id", id);
|
|
9860
|
-
if (blocking !== undefined) {
|
|
9861
|
-
url.searchParams.set("blocking", String(blocking));
|
|
9862
|
-
}
|
|
9863
|
-
const response = await axios3.get(url.toString(), {
|
|
9864
|
-
headers: getHeaders(app.accessToken),
|
|
9865
|
-
responseType: "arraybuffer"
|
|
9866
|
-
});
|
|
9867
|
-
return handleResponse(response.data);
|
|
9460
|
+
throw new Error(error?.response?.statusText || error?.message || "未知原因");
|
|
9868
9461
|
}
|
|
9869
9462
|
};
|
|
9870
|
-
// src/common/ai/keling/index.ts
|
|
9871
|
-
var exports_keling = {};
|
|
9872
|
-
__export(exports_keling, {
|
|
9873
|
-
setCookie: () => setCookie,
|
|
9874
|
-
getVideoStatus: () => getVideoStatus,
|
|
9875
|
-
generateVideo: () => generateVideo
|
|
9876
|
-
});
|
|
9877
|
-
|
|
9878
9463
|
// src/common/ai/keling/utils.ts
|
|
9879
9464
|
import * as url from "url";
|
|
9880
9465
|
import * as path from "path";
|
|
9881
9466
|
|
|
9882
9467
|
// src/common/ai/keling/axios.ts
|
|
9883
9468
|
import axios_2 from "axios";
|
|
9884
|
-
var
|
|
9469
|
+
var axios2 = axios_2.create({
|
|
9885
9470
|
headers: {
|
|
9886
9471
|
"Content-Type": "application/json",
|
|
9887
9472
|
Cookie: "weblogger_did=web_52354269549862D; did=web_d22eeae73f6e4c74a76a4cc98e3a1188a5b0; anonymous-message-release-notice-1=true; anonymous-message-release-notice-2=true; dev-center-view-welcome-dialog-key=true; userId=2904283585; welcome-future-partner-key=true; old-user-time=1731936878621; kuaishou.ai.portal_st=ChVrdWFpc2hvdS5haS5wb3J0YWwuc3QSoAFuUNTARKNKXARahOJhWZ4iVBl2mIANSUfk2nCSr85bxCg2lrpE3PHj2Kn_kjPW0_KV8DfZS6UnNam4i6gaYeBmxRwOVAldYysCz7YtlsosEZRuiTe2iY7Ziq5SZeAP7jhTg8lxk7gvC-bEELmAc8HSrqN5HLWeU4GUFcEq-ChV7qsodJ8m42oBuvkFgX1qytVTIROpSS4cMmEiBhB3h99EGhLGi0v_iyPMOr2JVXM8LPzBvxQiIJrnuzAheyLtkeb55iZOUgZoAzXjYj0U1e4mLSonbXBGKAUwAQ; kuaishou.ai.portal_ph=2669d9adaa5c0629ac1053ab87e6c123880a"
|
|
@@ -9891,7 +9476,7 @@ var axios4 = axios_2.create({
|
|
|
9891
9476
|
// src/common/ai/keling/utils.ts
|
|
9892
9477
|
var getToken = async (filename) => {
|
|
9893
9478
|
try {
|
|
9894
|
-
const response = await
|
|
9479
|
+
const response = await axios2.get("https://klingai.kuaishou.com/api/upload/issue/token", {
|
|
9895
9480
|
params: { filename }
|
|
9896
9481
|
});
|
|
9897
9482
|
return response.data.data.token;
|
|
@@ -9902,7 +9487,7 @@ var getToken = async (filename) => {
|
|
|
9902
9487
|
};
|
|
9903
9488
|
var uploadFragment = async (uploadToken, imageBuffer) => {
|
|
9904
9489
|
try {
|
|
9905
|
-
const response = await
|
|
9490
|
+
const response = await axios2.post("https://upload.kuaishouzt.com/api/upload/fragment", imageBuffer, {
|
|
9906
9491
|
params: {
|
|
9907
9492
|
upload_token: uploadToken,
|
|
9908
9493
|
fragment_id: 0
|
|
@@ -9919,7 +9504,7 @@ var uploadFragment = async (uploadToken, imageBuffer) => {
|
|
|
9919
9504
|
};
|
|
9920
9505
|
var completeUpload = async (uploadToken) => {
|
|
9921
9506
|
try {
|
|
9922
|
-
const response = await
|
|
9507
|
+
const response = await axios2.post("https://upload.kuaishouzt.com/api/upload/complete", null, {
|
|
9923
9508
|
params: {
|
|
9924
9509
|
upload_token: uploadToken,
|
|
9925
9510
|
fragment_count: 1
|
|
@@ -9933,7 +9518,7 @@ var completeUpload = async (uploadToken) => {
|
|
|
9933
9518
|
};
|
|
9934
9519
|
var verifyUpload = async (token) => {
|
|
9935
9520
|
try {
|
|
9936
|
-
const response = await
|
|
9521
|
+
const response = await axios2.get("https://klingai.kuaishou.com/api/upload/verify/token", {
|
|
9937
9522
|
params: { token }
|
|
9938
9523
|
});
|
|
9939
9524
|
if (response.data?.result === 1 && response.data?.data?.status === 3) {
|
|
@@ -9948,7 +9533,7 @@ var verifyUpload = async (token) => {
|
|
|
9948
9533
|
};
|
|
9949
9534
|
var downloadImage = async (imageUrl) => {
|
|
9950
9535
|
try {
|
|
9951
|
-
const response = await
|
|
9536
|
+
const response = await axios2.get(imageUrl, {
|
|
9952
9537
|
responseType: "arraybuffer"
|
|
9953
9538
|
});
|
|
9954
9539
|
return Buffer.from(response.data, "binary");
|
|
@@ -10028,7 +9613,7 @@ var sbumit = async (imageUrl, prompt) => {
|
|
|
10028
9613
|
],
|
|
10029
9614
|
type: "m2v_img2video_hq"
|
|
10030
9615
|
});
|
|
10031
|
-
const response = await
|
|
9616
|
+
const response = await axios2({
|
|
10032
9617
|
method: "POST",
|
|
10033
9618
|
url: "https://klingai.kuaishou.com/api/task/submit",
|
|
10034
9619
|
data
|
|
@@ -10058,7 +9643,7 @@ var calculateProgress = (taskData) => {
|
|
|
10058
9643
|
return progressRatio;
|
|
10059
9644
|
};
|
|
10060
9645
|
var setCookie = (newCookieValue) => {
|
|
10061
|
-
|
|
9646
|
+
axios2.defaults.headers.Cookie = newCookieValue;
|
|
10062
9647
|
};
|
|
10063
9648
|
|
|
10064
9649
|
// src/common/ai/keling/index.ts
|
|
@@ -10067,7 +9652,7 @@ var getVideoStatus = async (taskId) => {
|
|
|
10067
9652
|
return;
|
|
10068
9653
|
}
|
|
10069
9654
|
try {
|
|
10070
|
-
const response = await
|
|
9655
|
+
const response = await axios2.get("https://klingai.kuaishou.com/api/task/status", {
|
|
10071
9656
|
params: { taskId }
|
|
10072
9657
|
});
|
|
10073
9658
|
return {
|
|
@@ -10088,2816 +9673,137 @@ var generateVideo = async (imageUrl, prompt) => {
|
|
|
10088
9673
|
console.log(666, "任务 id", taskId);
|
|
10089
9674
|
return taskId;
|
|
10090
9675
|
};
|
|
10091
|
-
// src/common/
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
|
|
10101
|
-
|
|
10102
|
-
|
|
10103
|
-
if (!value) {
|
|
10104
|
-
return 0;
|
|
9676
|
+
// src/common/image.ts
|
|
9677
|
+
import axios3 from "axios";
|
|
9678
|
+
async function imageToBase64(url2) {
|
|
9679
|
+
try {
|
|
9680
|
+
const response = await axios3.get(url2, {
|
|
9681
|
+
responseType: "arraybuffer"
|
|
9682
|
+
});
|
|
9683
|
+
const base64String = Buffer.from(response.data).toString("base64");
|
|
9684
|
+
return `data:image/*;base64,${base64String}`;
|
|
9685
|
+
} catch (error) {
|
|
9686
|
+
console.error("Failed to fetch the image:", error);
|
|
9687
|
+
throw error;
|
|
10105
9688
|
}
|
|
10106
|
-
|
|
10107
|
-
|
|
10108
|
-
|
|
10109
|
-
|
|
10110
|
-
|
|
10111
|
-
|
|
9689
|
+
}
|
|
9690
|
+
// src/common/enum.ts
|
|
9691
|
+
class EnumItem {
|
|
9692
|
+
label;
|
|
9693
|
+
value;
|
|
9694
|
+
extra;
|
|
9695
|
+
constructor(config) {
|
|
9696
|
+
this.value = config.value;
|
|
9697
|
+
this.label = config.label;
|
|
9698
|
+
this.extra = config.extra;
|
|
10112
9699
|
}
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
|
|
9700
|
+
}
|
|
9701
|
+
var Enum = {
|
|
9702
|
+
create: (members) => {
|
|
9703
|
+
const usedValues = new Set;
|
|
9704
|
+
const enumObj = {};
|
|
9705
|
+
const map = new Map;
|
|
9706
|
+
const options = [];
|
|
9707
|
+
const extras = new Map;
|
|
9708
|
+
const labels = new Map;
|
|
9709
|
+
const enums = {};
|
|
9710
|
+
for (const key2 in members) {
|
|
9711
|
+
const member = members[key2];
|
|
9712
|
+
if (!member)
|
|
9713
|
+
continue;
|
|
9714
|
+
if (usedValues.has(member.value)) {
|
|
9715
|
+
throw new Error(`Duplicate enum value detected: ${member.value}`);
|
|
9716
|
+
}
|
|
9717
|
+
usedValues.add(member.value);
|
|
9718
|
+
const item = new EnumItem(member);
|
|
9719
|
+
enumObj[key2] = item;
|
|
9720
|
+
map.set(item.value, item);
|
|
9721
|
+
labels.set(item.value, item.label);
|
|
9722
|
+
options.push(item);
|
|
9723
|
+
enums[item.value] = { text: item.label, status: item.extra?.status };
|
|
9724
|
+
if (member.extra !== undefined) {
|
|
9725
|
+
extras.set(item.value, { ...member.extra });
|
|
9726
|
+
}
|
|
9727
|
+
}
|
|
9728
|
+
enumObj.map = map;
|
|
9729
|
+
enumObj.options = options;
|
|
9730
|
+
enumObj.extras = extras;
|
|
9731
|
+
enumObj.source = members;
|
|
9732
|
+
enumObj.labels = labels;
|
|
9733
|
+
enumObj.enums = enums;
|
|
9734
|
+
return enumObj;
|
|
10116
9735
|
}
|
|
10117
|
-
return replaceAll(str, searchValue, replaceValue);
|
|
10118
9736
|
};
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
9737
|
+
// src/common/dayjs.ts
|
|
9738
|
+
import dayjs from "dayjs";
|
|
9739
|
+
import isBetween from "dayjs/plugin/isBetween";
|
|
9740
|
+
import weekday from "dayjs/plugin/weekday";
|
|
9741
|
+
import localeData from "dayjs/plugin/localeData";
|
|
9742
|
+
import isoWeek from "dayjs/plugin/isoWeek";
|
|
9743
|
+
import updateLocale from "dayjs/plugin/updateLocale";
|
|
9744
|
+
import timezone from "dayjs/plugin/timezone";
|
|
9745
|
+
import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
|
|
9746
|
+
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
|
|
9747
|
+
import utc from "dayjs/plugin/utc";
|
|
9748
|
+
import"dayjs/locale/zh-cn";
|
|
9749
|
+
import { Dayjs } from "dayjs";
|
|
9750
|
+
dayjs.extend(utc);
|
|
9751
|
+
dayjs.extend(isBetween);
|
|
9752
|
+
dayjs.extend(weekday);
|
|
9753
|
+
dayjs.extend(localeData);
|
|
9754
|
+
dayjs.extend(isoWeek);
|
|
9755
|
+
dayjs.extend(updateLocale);
|
|
9756
|
+
dayjs.extend(timezone);
|
|
9757
|
+
dayjs.extend(isSameOrAfter);
|
|
9758
|
+
dayjs.extend(isSameOrBefore);
|
|
9759
|
+
var Timezone;
|
|
9760
|
+
((Timezone2) => {
|
|
9761
|
+
Timezone2["AsiaShanghai"] = "Asia/Shanghai";
|
|
9762
|
+
Timezone2["AsiaTokyo"] = "Asia/Tokyo";
|
|
9763
|
+
Timezone2["AmericaNewYork"] = "America/New_York";
|
|
9764
|
+
Timezone2["EuropeLondon"] = "Europe/London";
|
|
9765
|
+
Timezone2["EuropeBerlin"] = "Europe/Berlin";
|
|
9766
|
+
})(Timezone ||= {});
|
|
9767
|
+
var initChinaDayjs = () => {
|
|
9768
|
+
dayjs.locale("zh-cn");
|
|
9769
|
+
dayjs.tz.setDefault("Asia/Shanghai" /* AsiaShanghai */);
|
|
9770
|
+
dayjs.updateLocale("zh-cn", {
|
|
9771
|
+
weekStart: 1
|
|
10122
9772
|
});
|
|
10123
|
-
return
|
|
9773
|
+
return dayjs;
|
|
10124
9774
|
};
|
|
10125
|
-
var
|
|
10126
|
-
|
|
10127
|
-
|
|
9775
|
+
var chinaDayjs = initChinaDayjs();
|
|
9776
|
+
var dayjs_default = dayjs;
|
|
9777
|
+
// src/node/mail.ts
|
|
9778
|
+
import nodemailer from "nodemailer";
|
|
9779
|
+
var authMap = {
|
|
9780
|
+
163: {
|
|
9781
|
+
user: "15835196981@163.com",
|
|
9782
|
+
pass: "KPTVCFBMRXJVTCGW"
|
|
9783
|
+
},
|
|
9784
|
+
gmail: {
|
|
9785
|
+
user: "wangzhenzhen2023@gmail.com",
|
|
9786
|
+
pass: "lkxtorbpdyrjjxjq"
|
|
10128
9787
|
}
|
|
10129
|
-
const regex = /\{\{\s*(\w+)\s*\}\}/g;
|
|
10130
|
-
return prompt.replace(regex, (match, p1) => {
|
|
10131
|
-
return variables[p1] ?? match;
|
|
10132
|
-
});
|
|
10133
|
-
};
|
|
10134
|
-
var getType = (value) => {
|
|
10135
|
-
return Object.prototype.toString.call(value).slice(8, -1);
|
|
10136
|
-
};
|
|
10137
|
-
var amount = (str) => {
|
|
10138
|
-
const reg = /(?=(?!\b)(\d{3})+$)/g;
|
|
10139
|
-
return str.replace(reg, ",");
|
|
10140
9788
|
};
|
|
10141
|
-
var
|
|
10142
|
-
|
|
10143
|
-
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
|
|
10149
|
-
|
|
9789
|
+
var transporter = nodemailer.createTransport({
|
|
9790
|
+
host: "smtp.gmail.com",
|
|
9791
|
+
port: 465,
|
|
9792
|
+
secure: true,
|
|
9793
|
+
auth: authMap.gmail
|
|
9794
|
+
});
|
|
9795
|
+
var sendMail = (config) => {
|
|
9796
|
+
return transporter.sendMail({
|
|
9797
|
+
from: authMap.gmail.user,
|
|
9798
|
+
...config
|
|
9799
|
+
});
|
|
10150
9800
|
};
|
|
10151
|
-
|
|
10152
|
-
|
|
10153
|
-
|
|
10154
|
-
|
|
10155
|
-
|
|
10156
|
-
|
|
10157
|
-
return false;
|
|
10158
|
-
};
|
|
10159
|
-
var toString = (value) => {
|
|
10160
|
-
return Object.prototype.toString.call(value).slice(8, -1) === "object" ? JSON.stringify(value) : String(value);
|
|
10161
|
-
};
|
|
10162
|
-
var getRandomColor = () => {
|
|
10163
|
-
const color = Math.floor(Math.random() * 16777215).toString(16);
|
|
10164
|
-
if (color.length === 6) {
|
|
10165
|
-
return color;
|
|
10166
|
-
} else {
|
|
10167
|
-
return getRandomColor();
|
|
10168
|
-
}
|
|
10169
|
-
};
|
|
10170
|
-
var getRandomString = (length = 4) => {
|
|
10171
|
-
return Math.random().toString(36).substr(2, length);
|
|
10172
|
-
};
|
|
10173
|
-
var getChinese = (str) => {
|
|
10174
|
-
if (str == null || str === "") {
|
|
10175
|
-
return "";
|
|
10176
|
-
}
|
|
10177
|
-
const res = str.match(/[\u4e00-\u9fa5]/g);
|
|
10178
|
-
if (!res) {
|
|
10179
|
-
return "";
|
|
10180
|
-
}
|
|
10181
|
-
return res.join("");
|
|
10182
|
-
};
|
|
10183
|
-
var getSliceStr = (str, before, after) => {
|
|
10184
|
-
return str.slice(str.indexOf(before) + before.length, str.lastIndexOf(after));
|
|
10185
|
-
};
|
|
10186
|
-
var getProxyUrl = (url2) => {
|
|
10187
|
-
const beforeUrl = "https://1141871752167714.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/a.LATEST/proxy/?url=";
|
|
10188
|
-
return beforeUrl + url2;
|
|
10189
|
-
};
|
|
10190
|
-
var getLength = (value) => {
|
|
10191
|
-
const chineseLength = getChinese(value).length;
|
|
10192
|
-
return value.length - chineseLength + chineseLength * 2;
|
|
10193
|
-
};
|
|
10194
|
-
var getCookie = (name) => {
|
|
10195
|
-
const reg = new RegExp(`(^| )${name}=([^;]*)(;|$)`);
|
|
10196
|
-
const arr = document.cookie.match(reg);
|
|
10197
|
-
return arr ? unescape(arr[2]) : null;
|
|
10198
|
-
};
|
|
10199
|
-
var generateAlphabetArray = (n) => {
|
|
10200
|
-
return Array.from({ length: n }, (_, i) => String.fromCharCode(97 + i));
|
|
10201
|
-
};
|
|
10202
|
-
var levenshteinDistance = (a, b) => {
|
|
10203
|
-
const matrix = [];
|
|
10204
|
-
for (let i = 0;i <= b.length; i++) {
|
|
10205
|
-
matrix[i] = [i];
|
|
10206
|
-
}
|
|
10207
|
-
for (let j = 0;j <= a.length; j++) {
|
|
10208
|
-
matrix[0][j] = j;
|
|
10209
|
-
}
|
|
10210
|
-
for (let i = 1;i <= b.length; i++) {
|
|
10211
|
-
for (let j = 1;j <= a.length; j++) {
|
|
10212
|
-
if (b[i - 1] === a[j - 1]) {
|
|
10213
|
-
matrix[i][j] = matrix[i - 1][j - 1];
|
|
10214
|
-
} else {
|
|
10215
|
-
matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j] + 1);
|
|
10216
|
-
}
|
|
10217
|
-
}
|
|
10218
|
-
}
|
|
10219
|
-
return matrix[b.length][a.length];
|
|
10220
|
-
};
|
|
10221
|
-
var generateUniqueFileName = (name) => {
|
|
10222
|
-
const match = name.match(/^(.*?)(\.[^.]*$|$)/);
|
|
10223
|
-
if (match) {
|
|
10224
|
-
const namePart = match[1];
|
|
10225
|
-
const extensionPart = match[2];
|
|
10226
|
-
if (extensionPart) {
|
|
10227
|
-
return `${namePart}_${Date.now()}${extensionPart}`;
|
|
10228
|
-
} else {
|
|
10229
|
-
return `${namePart}_${Date.now()}.dat`;
|
|
10230
|
-
}
|
|
10231
|
-
}
|
|
10232
|
-
throw new Error("Invalid filename format.");
|
|
10233
|
-
};
|
|
10234
|
-
|
|
10235
|
-
// ../../node_modules/decimal.js/decimal.mjs
|
|
10236
|
-
/*!
|
|
10237
|
-
* decimal.js v10.6.0
|
|
10238
|
-
* An arbitrary-precision Decimal type for JavaScript.
|
|
10239
|
-
* https://github.com/MikeMcl/decimal.js
|
|
10240
|
-
* Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
10241
|
-
* MIT Licence
|
|
10242
|
-
*/
|
|
10243
|
-
var EXP_LIMIT = 9000000000000000;
|
|
10244
|
-
var MAX_DIGITS = 1e9;
|
|
10245
|
-
var NUMERALS = "0123456789abcdef";
|
|
10246
|
-
var LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";
|
|
10247
|
-
var PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789";
|
|
10248
|
-
var DEFAULTS = {
|
|
10249
|
-
precision: 20,
|
|
10250
|
-
rounding: 4,
|
|
10251
|
-
modulo: 1,
|
|
10252
|
-
toExpNeg: -7,
|
|
10253
|
-
toExpPos: 21,
|
|
10254
|
-
minE: -EXP_LIMIT,
|
|
10255
|
-
maxE: EXP_LIMIT,
|
|
10256
|
-
crypto: false
|
|
10257
|
-
};
|
|
10258
|
-
var inexact;
|
|
10259
|
-
var quadrant;
|
|
10260
|
-
var external2 = true;
|
|
10261
|
-
var decimalError = "[DecimalError] ";
|
|
10262
|
-
var invalidArgument = decimalError + "Invalid argument: ";
|
|
10263
|
-
var precisionLimitExceeded = decimalError + "Precision limit exceeded";
|
|
10264
|
-
var cryptoUnavailable = decimalError + "crypto unavailable";
|
|
10265
|
-
var tag = "[object Decimal]";
|
|
10266
|
-
var mathfloor = Math.floor;
|
|
10267
|
-
var mathpow = Math.pow;
|
|
10268
|
-
var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
|
|
10269
|
-
var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
|
|
10270
|
-
var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
|
|
10271
|
-
var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
|
|
10272
|
-
var BASE = 1e7;
|
|
10273
|
-
var LOG_BASE = 7;
|
|
10274
|
-
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
10275
|
-
var LN10_PRECISION = LN10.length - 1;
|
|
10276
|
-
var PI_PRECISION = PI.length - 1;
|
|
10277
|
-
var P = { toStringTag: tag };
|
|
10278
|
-
P.absoluteValue = P.abs = function() {
|
|
10279
|
-
var x = new this.constructor(this);
|
|
10280
|
-
if (x.s < 0)
|
|
10281
|
-
x.s = 1;
|
|
10282
|
-
return finalise(x);
|
|
10283
|
-
};
|
|
10284
|
-
P.ceil = function() {
|
|
10285
|
-
return finalise(new this.constructor(this), this.e + 1, 2);
|
|
10286
|
-
};
|
|
10287
|
-
P.clampedTo = P.clamp = function(min, max) {
|
|
10288
|
-
var k, x = this, Ctor = x.constructor;
|
|
10289
|
-
min = new Ctor(min);
|
|
10290
|
-
max = new Ctor(max);
|
|
10291
|
-
if (!min.s || !max.s)
|
|
10292
|
-
return new Ctor(NaN);
|
|
10293
|
-
if (min.gt(max))
|
|
10294
|
-
throw Error(invalidArgument + max);
|
|
10295
|
-
k = x.cmp(min);
|
|
10296
|
-
return k < 0 ? min : x.cmp(max) > 0 ? max : new Ctor(x);
|
|
10297
|
-
};
|
|
10298
|
-
P.comparedTo = P.cmp = function(y) {
|
|
10299
|
-
var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
|
|
10300
|
-
if (!xd || !yd) {
|
|
10301
|
-
return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
|
|
10302
|
-
}
|
|
10303
|
-
if (!xd[0] || !yd[0])
|
|
10304
|
-
return xd[0] ? xs : yd[0] ? -ys : 0;
|
|
10305
|
-
if (xs !== ys)
|
|
10306
|
-
return xs;
|
|
10307
|
-
if (x.e !== y.e)
|
|
10308
|
-
return x.e > y.e ^ xs < 0 ? 1 : -1;
|
|
10309
|
-
xdL = xd.length;
|
|
10310
|
-
ydL = yd.length;
|
|
10311
|
-
for (i = 0, j = xdL < ydL ? xdL : ydL;i < j; ++i) {
|
|
10312
|
-
if (xd[i] !== yd[i])
|
|
10313
|
-
return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
|
|
10314
|
-
}
|
|
10315
|
-
return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
|
|
10316
|
-
};
|
|
10317
|
-
P.cosine = P.cos = function() {
|
|
10318
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
10319
|
-
if (!x.d)
|
|
10320
|
-
return new Ctor(NaN);
|
|
10321
|
-
if (!x.d[0])
|
|
10322
|
-
return new Ctor(1);
|
|
10323
|
-
pr = Ctor.precision;
|
|
10324
|
-
rm = Ctor.rounding;
|
|
10325
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
|
10326
|
-
Ctor.rounding = 1;
|
|
10327
|
-
x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
|
|
10328
|
-
Ctor.precision = pr;
|
|
10329
|
-
Ctor.rounding = rm;
|
|
10330
|
-
return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
|
|
10331
|
-
};
|
|
10332
|
-
P.cubeRoot = P.cbrt = function() {
|
|
10333
|
-
var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
|
|
10334
|
-
if (!x.isFinite() || x.isZero())
|
|
10335
|
-
return new Ctor(x);
|
|
10336
|
-
external2 = false;
|
|
10337
|
-
s = x.s * mathpow(x.s * x, 1 / 3);
|
|
10338
|
-
if (!s || Math.abs(s) == 1 / 0) {
|
|
10339
|
-
n = digitsToString(x.d);
|
|
10340
|
-
e = x.e;
|
|
10341
|
-
if (s = (e - n.length + 1) % 3)
|
|
10342
|
-
n += s == 1 || s == -2 ? "0" : "00";
|
|
10343
|
-
s = mathpow(n, 1 / 3);
|
|
10344
|
-
e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
|
|
10345
|
-
if (s == 1 / 0) {
|
|
10346
|
-
n = "5e" + e;
|
|
10347
|
-
} else {
|
|
10348
|
-
n = s.toExponential();
|
|
10349
|
-
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
10350
|
-
}
|
|
10351
|
-
r = new Ctor(n);
|
|
10352
|
-
r.s = x.s;
|
|
10353
|
-
} else {
|
|
10354
|
-
r = new Ctor(s.toString());
|
|
10355
|
-
}
|
|
10356
|
-
sd = (e = Ctor.precision) + 3;
|
|
10357
|
-
for (;; ) {
|
|
10358
|
-
t = r;
|
|
10359
|
-
t3 = t.times(t).times(t);
|
|
10360
|
-
t3plusx = t3.plus(x);
|
|
10361
|
-
r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
|
|
10362
|
-
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
10363
|
-
n = n.slice(sd - 3, sd + 1);
|
|
10364
|
-
if (n == "9999" || !rep && n == "4999") {
|
|
10365
|
-
if (!rep) {
|
|
10366
|
-
finalise(t, e + 1, 0);
|
|
10367
|
-
if (t.times(t).times(t).eq(x)) {
|
|
10368
|
-
r = t;
|
|
10369
|
-
break;
|
|
10370
|
-
}
|
|
10371
|
-
}
|
|
10372
|
-
sd += 4;
|
|
10373
|
-
rep = 1;
|
|
10374
|
-
} else {
|
|
10375
|
-
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
10376
|
-
finalise(r, e + 1, 1);
|
|
10377
|
-
m = !r.times(r).times(r).eq(x);
|
|
10378
|
-
}
|
|
10379
|
-
break;
|
|
10380
|
-
}
|
|
10381
|
-
}
|
|
10382
|
-
}
|
|
10383
|
-
external2 = true;
|
|
10384
|
-
return finalise(r, e, Ctor.rounding, m);
|
|
10385
|
-
};
|
|
10386
|
-
P.decimalPlaces = P.dp = function() {
|
|
10387
|
-
var w, d = this.d, n = NaN;
|
|
10388
|
-
if (d) {
|
|
10389
|
-
w = d.length - 1;
|
|
10390
|
-
n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
10391
|
-
w = d[w];
|
|
10392
|
-
if (w)
|
|
10393
|
-
for (;w % 10 == 0; w /= 10)
|
|
10394
|
-
n--;
|
|
10395
|
-
if (n < 0)
|
|
10396
|
-
n = 0;
|
|
10397
|
-
}
|
|
10398
|
-
return n;
|
|
10399
|
-
};
|
|
10400
|
-
P.dividedBy = P.div = function(y) {
|
|
10401
|
-
return divide(this, new this.constructor(y));
|
|
10402
|
-
};
|
|
10403
|
-
P.dividedToIntegerBy = P.divToInt = function(y) {
|
|
10404
|
-
var x = this, Ctor = x.constructor;
|
|
10405
|
-
return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
|
|
10406
|
-
};
|
|
10407
|
-
P.equals = P.eq = function(y) {
|
|
10408
|
-
return this.cmp(y) === 0;
|
|
10409
|
-
};
|
|
10410
|
-
P.floor = function() {
|
|
10411
|
-
return finalise(new this.constructor(this), this.e + 1, 3);
|
|
10412
|
-
};
|
|
10413
|
-
P.greaterThan = P.gt = function(y) {
|
|
10414
|
-
return this.cmp(y) > 0;
|
|
10415
|
-
};
|
|
10416
|
-
P.greaterThanOrEqualTo = P.gte = function(y) {
|
|
10417
|
-
var k = this.cmp(y);
|
|
10418
|
-
return k == 1 || k === 0;
|
|
10419
|
-
};
|
|
10420
|
-
P.hyperbolicCosine = P.cosh = function() {
|
|
10421
|
-
var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
|
|
10422
|
-
if (!x.isFinite())
|
|
10423
|
-
return new Ctor(x.s ? 1 / 0 : NaN);
|
|
10424
|
-
if (x.isZero())
|
|
10425
|
-
return one;
|
|
10426
|
-
pr = Ctor.precision;
|
|
10427
|
-
rm = Ctor.rounding;
|
|
10428
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
|
10429
|
-
Ctor.rounding = 1;
|
|
10430
|
-
len = x.d.length;
|
|
10431
|
-
if (len < 32) {
|
|
10432
|
-
k = Math.ceil(len / 3);
|
|
10433
|
-
n = (1 / tinyPow(4, k)).toString();
|
|
10434
|
-
} else {
|
|
10435
|
-
k = 16;
|
|
10436
|
-
n = "2.3283064365386962890625e-10";
|
|
10437
|
-
}
|
|
10438
|
-
x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
|
|
10439
|
-
var cosh2_x, i = k, d8 = new Ctor(8);
|
|
10440
|
-
for (;i--; ) {
|
|
10441
|
-
cosh2_x = x.times(x);
|
|
10442
|
-
x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
|
|
10443
|
-
}
|
|
10444
|
-
return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
|
|
10445
|
-
};
|
|
10446
|
-
P.hyperbolicSine = P.sinh = function() {
|
|
10447
|
-
var k, pr, rm, len, x = this, Ctor = x.constructor;
|
|
10448
|
-
if (!x.isFinite() || x.isZero())
|
|
10449
|
-
return new Ctor(x);
|
|
10450
|
-
pr = Ctor.precision;
|
|
10451
|
-
rm = Ctor.rounding;
|
|
10452
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
|
10453
|
-
Ctor.rounding = 1;
|
|
10454
|
-
len = x.d.length;
|
|
10455
|
-
if (len < 3) {
|
|
10456
|
-
x = taylorSeries(Ctor, 2, x, x, true);
|
|
10457
|
-
} else {
|
|
10458
|
-
k = 1.4 * Math.sqrt(len);
|
|
10459
|
-
k = k > 16 ? 16 : k | 0;
|
|
10460
|
-
x = x.times(1 / tinyPow(5, k));
|
|
10461
|
-
x = taylorSeries(Ctor, 2, x, x, true);
|
|
10462
|
-
var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
10463
|
-
for (;k--; ) {
|
|
10464
|
-
sinh2_x = x.times(x);
|
|
10465
|
-
x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
|
|
10466
|
-
}
|
|
10467
|
-
}
|
|
10468
|
-
Ctor.precision = pr;
|
|
10469
|
-
Ctor.rounding = rm;
|
|
10470
|
-
return finalise(x, pr, rm, true);
|
|
10471
|
-
};
|
|
10472
|
-
P.hyperbolicTangent = P.tanh = function() {
|
|
10473
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
10474
|
-
if (!x.isFinite())
|
|
10475
|
-
return new Ctor(x.s);
|
|
10476
|
-
if (x.isZero())
|
|
10477
|
-
return new Ctor(x);
|
|
10478
|
-
pr = Ctor.precision;
|
|
10479
|
-
rm = Ctor.rounding;
|
|
10480
|
-
Ctor.precision = pr + 7;
|
|
10481
|
-
Ctor.rounding = 1;
|
|
10482
|
-
return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
|
|
10483
|
-
};
|
|
10484
|
-
P.inverseCosine = P.acos = function() {
|
|
10485
|
-
var x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
|
|
10486
|
-
if (k !== -1) {
|
|
10487
|
-
return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
|
|
10488
|
-
}
|
|
10489
|
-
if (x.isZero())
|
|
10490
|
-
return getPi(Ctor, pr + 4, rm).times(0.5);
|
|
10491
|
-
Ctor.precision = pr + 6;
|
|
10492
|
-
Ctor.rounding = 1;
|
|
10493
|
-
x = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
|
|
10494
|
-
Ctor.precision = pr;
|
|
10495
|
-
Ctor.rounding = rm;
|
|
10496
|
-
return x.times(2);
|
|
10497
|
-
};
|
|
10498
|
-
P.inverseHyperbolicCosine = P.acosh = function() {
|
|
10499
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
10500
|
-
if (x.lte(1))
|
|
10501
|
-
return new Ctor(x.eq(1) ? 0 : NaN);
|
|
10502
|
-
if (!x.isFinite())
|
|
10503
|
-
return new Ctor(x);
|
|
10504
|
-
pr = Ctor.precision;
|
|
10505
|
-
rm = Ctor.rounding;
|
|
10506
|
-
Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
|
|
10507
|
-
Ctor.rounding = 1;
|
|
10508
|
-
external2 = false;
|
|
10509
|
-
x = x.times(x).minus(1).sqrt().plus(x);
|
|
10510
|
-
external2 = true;
|
|
10511
|
-
Ctor.precision = pr;
|
|
10512
|
-
Ctor.rounding = rm;
|
|
10513
|
-
return x.ln();
|
|
10514
|
-
};
|
|
10515
|
-
P.inverseHyperbolicSine = P.asinh = function() {
|
|
10516
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
10517
|
-
if (!x.isFinite() || x.isZero())
|
|
10518
|
-
return new Ctor(x);
|
|
10519
|
-
pr = Ctor.precision;
|
|
10520
|
-
rm = Ctor.rounding;
|
|
10521
|
-
Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
|
|
10522
|
-
Ctor.rounding = 1;
|
|
10523
|
-
external2 = false;
|
|
10524
|
-
x = x.times(x).plus(1).sqrt().plus(x);
|
|
10525
|
-
external2 = true;
|
|
10526
|
-
Ctor.precision = pr;
|
|
10527
|
-
Ctor.rounding = rm;
|
|
10528
|
-
return x.ln();
|
|
10529
|
-
};
|
|
10530
|
-
P.inverseHyperbolicTangent = P.atanh = function() {
|
|
10531
|
-
var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
|
|
10532
|
-
if (!x.isFinite())
|
|
10533
|
-
return new Ctor(NaN);
|
|
10534
|
-
if (x.e >= 0)
|
|
10535
|
-
return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
|
|
10536
|
-
pr = Ctor.precision;
|
|
10537
|
-
rm = Ctor.rounding;
|
|
10538
|
-
xsd = x.sd();
|
|
10539
|
-
if (Math.max(xsd, pr) < 2 * -x.e - 1)
|
|
10540
|
-
return finalise(new Ctor(x), pr, rm, true);
|
|
10541
|
-
Ctor.precision = wpr = xsd - x.e;
|
|
10542
|
-
x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
|
|
10543
|
-
Ctor.precision = pr + 4;
|
|
10544
|
-
Ctor.rounding = 1;
|
|
10545
|
-
x = x.ln();
|
|
10546
|
-
Ctor.precision = pr;
|
|
10547
|
-
Ctor.rounding = rm;
|
|
10548
|
-
return x.times(0.5);
|
|
10549
|
-
};
|
|
10550
|
-
P.inverseSine = P.asin = function() {
|
|
10551
|
-
var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
|
|
10552
|
-
if (x.isZero())
|
|
10553
|
-
return new Ctor(x);
|
|
10554
|
-
k = x.abs().cmp(1);
|
|
10555
|
-
pr = Ctor.precision;
|
|
10556
|
-
rm = Ctor.rounding;
|
|
10557
|
-
if (k !== -1) {
|
|
10558
|
-
if (k === 0) {
|
|
10559
|
-
halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
10560
|
-
halfPi.s = x.s;
|
|
10561
|
-
return halfPi;
|
|
10562
|
-
}
|
|
10563
|
-
return new Ctor(NaN);
|
|
10564
|
-
}
|
|
10565
|
-
Ctor.precision = pr + 6;
|
|
10566
|
-
Ctor.rounding = 1;
|
|
10567
|
-
x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
|
|
10568
|
-
Ctor.precision = pr;
|
|
10569
|
-
Ctor.rounding = rm;
|
|
10570
|
-
return x.times(2);
|
|
10571
|
-
};
|
|
10572
|
-
P.inverseTangent = P.atan = function() {
|
|
10573
|
-
var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
|
|
10574
|
-
if (!x.isFinite()) {
|
|
10575
|
-
if (!x.s)
|
|
10576
|
-
return new Ctor(NaN);
|
|
10577
|
-
if (pr + 4 <= PI_PRECISION) {
|
|
10578
|
-
r = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
10579
|
-
r.s = x.s;
|
|
10580
|
-
return r;
|
|
10581
|
-
}
|
|
10582
|
-
} else if (x.isZero()) {
|
|
10583
|
-
return new Ctor(x);
|
|
10584
|
-
} else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
|
|
10585
|
-
r = getPi(Ctor, pr + 4, rm).times(0.25);
|
|
10586
|
-
r.s = x.s;
|
|
10587
|
-
return r;
|
|
10588
|
-
}
|
|
10589
|
-
Ctor.precision = wpr = pr + 10;
|
|
10590
|
-
Ctor.rounding = 1;
|
|
10591
|
-
k = Math.min(28, wpr / LOG_BASE + 2 | 0);
|
|
10592
|
-
for (i = k;i; --i)
|
|
10593
|
-
x = x.div(x.times(x).plus(1).sqrt().plus(1));
|
|
10594
|
-
external2 = false;
|
|
10595
|
-
j = Math.ceil(wpr / LOG_BASE);
|
|
10596
|
-
n = 1;
|
|
10597
|
-
x2 = x.times(x);
|
|
10598
|
-
r = new Ctor(x);
|
|
10599
|
-
px = x;
|
|
10600
|
-
for (;i !== -1; ) {
|
|
10601
|
-
px = px.times(x2);
|
|
10602
|
-
t = r.minus(px.div(n += 2));
|
|
10603
|
-
px = px.times(x2);
|
|
10604
|
-
r = t.plus(px.div(n += 2));
|
|
10605
|
-
if (r.d[j] !== undefined)
|
|
10606
|
-
for (i = j;r.d[i] === t.d[i] && i--; )
|
|
10607
|
-
;
|
|
10608
|
-
}
|
|
10609
|
-
if (k)
|
|
10610
|
-
r = r.times(2 << k - 1);
|
|
10611
|
-
external2 = true;
|
|
10612
|
-
return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
|
|
10613
|
-
};
|
|
10614
|
-
P.isFinite = function() {
|
|
10615
|
-
return !!this.d;
|
|
10616
|
-
};
|
|
10617
|
-
P.isInteger = P.isInt = function() {
|
|
10618
|
-
return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
|
|
10619
|
-
};
|
|
10620
|
-
P.isNaN = function() {
|
|
10621
|
-
return !this.s;
|
|
10622
|
-
};
|
|
10623
|
-
P.isNegative = P.isNeg = function() {
|
|
10624
|
-
return this.s < 0;
|
|
10625
|
-
};
|
|
10626
|
-
P.isPositive = P.isPos = function() {
|
|
10627
|
-
return this.s > 0;
|
|
10628
|
-
};
|
|
10629
|
-
P.isZero = function() {
|
|
10630
|
-
return !!this.d && this.d[0] === 0;
|
|
10631
|
-
};
|
|
10632
|
-
P.lessThan = P.lt = function(y) {
|
|
10633
|
-
return this.cmp(y) < 0;
|
|
10634
|
-
};
|
|
10635
|
-
P.lessThanOrEqualTo = P.lte = function(y) {
|
|
10636
|
-
return this.cmp(y) < 1;
|
|
10637
|
-
};
|
|
10638
|
-
P.logarithm = P.log = function(base) {
|
|
10639
|
-
var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
|
|
10640
|
-
if (base == null) {
|
|
10641
|
-
base = new Ctor(10);
|
|
10642
|
-
isBase10 = true;
|
|
10643
|
-
} else {
|
|
10644
|
-
base = new Ctor(base);
|
|
10645
|
-
d = base.d;
|
|
10646
|
-
if (base.s < 0 || !d || !d[0] || base.eq(1))
|
|
10647
|
-
return new Ctor(NaN);
|
|
10648
|
-
isBase10 = base.eq(10);
|
|
10649
|
-
}
|
|
10650
|
-
d = arg.d;
|
|
10651
|
-
if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
|
|
10652
|
-
return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
|
|
10653
|
-
}
|
|
10654
|
-
if (isBase10) {
|
|
10655
|
-
if (d.length > 1) {
|
|
10656
|
-
inf = true;
|
|
10657
|
-
} else {
|
|
10658
|
-
for (k = d[0];k % 10 === 0; )
|
|
10659
|
-
k /= 10;
|
|
10660
|
-
inf = k !== 1;
|
|
10661
|
-
}
|
|
10662
|
-
}
|
|
10663
|
-
external2 = false;
|
|
10664
|
-
sd = pr + guard;
|
|
10665
|
-
num = naturalLogarithm(arg, sd);
|
|
10666
|
-
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
10667
|
-
r = divide(num, denominator, sd, 1);
|
|
10668
|
-
if (checkRoundingDigits(r.d, k = pr, rm)) {
|
|
10669
|
-
do {
|
|
10670
|
-
sd += 10;
|
|
10671
|
-
num = naturalLogarithm(arg, sd);
|
|
10672
|
-
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
10673
|
-
r = divide(num, denominator, sd, 1);
|
|
10674
|
-
if (!inf) {
|
|
10675
|
-
if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 100000000000000) {
|
|
10676
|
-
r = finalise(r, pr + 1, 0);
|
|
10677
|
-
}
|
|
10678
|
-
break;
|
|
10679
|
-
}
|
|
10680
|
-
} while (checkRoundingDigits(r.d, k += 10, rm));
|
|
10681
|
-
}
|
|
10682
|
-
external2 = true;
|
|
10683
|
-
return finalise(r, pr, rm);
|
|
10684
|
-
};
|
|
10685
|
-
P.minus = P.sub = function(y) {
|
|
10686
|
-
var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
|
|
10687
|
-
y = new Ctor(y);
|
|
10688
|
-
if (!x.d || !y.d) {
|
|
10689
|
-
if (!x.s || !y.s)
|
|
10690
|
-
y = new Ctor(NaN);
|
|
10691
|
-
else if (x.d)
|
|
10692
|
-
y.s = -y.s;
|
|
10693
|
-
else
|
|
10694
|
-
y = new Ctor(y.d || x.s !== y.s ? x : NaN);
|
|
10695
|
-
return y;
|
|
10696
|
-
}
|
|
10697
|
-
if (x.s != y.s) {
|
|
10698
|
-
y.s = -y.s;
|
|
10699
|
-
return x.plus(y);
|
|
10700
|
-
}
|
|
10701
|
-
xd = x.d;
|
|
10702
|
-
yd = y.d;
|
|
10703
|
-
pr = Ctor.precision;
|
|
10704
|
-
rm = Ctor.rounding;
|
|
10705
|
-
if (!xd[0] || !yd[0]) {
|
|
10706
|
-
if (yd[0])
|
|
10707
|
-
y.s = -y.s;
|
|
10708
|
-
else if (xd[0])
|
|
10709
|
-
y = new Ctor(x);
|
|
10710
|
-
else
|
|
10711
|
-
return new Ctor(rm === 3 ? -0 : 0);
|
|
10712
|
-
return external2 ? finalise(y, pr, rm) : y;
|
|
10713
|
-
}
|
|
10714
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
10715
|
-
xe = mathfloor(x.e / LOG_BASE);
|
|
10716
|
-
xd = xd.slice();
|
|
10717
|
-
k = xe - e;
|
|
10718
|
-
if (k) {
|
|
10719
|
-
xLTy = k < 0;
|
|
10720
|
-
if (xLTy) {
|
|
10721
|
-
d = xd;
|
|
10722
|
-
k = -k;
|
|
10723
|
-
len = yd.length;
|
|
10724
|
-
} else {
|
|
10725
|
-
d = yd;
|
|
10726
|
-
e = xe;
|
|
10727
|
-
len = xd.length;
|
|
10728
|
-
}
|
|
10729
|
-
i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
|
|
10730
|
-
if (k > i) {
|
|
10731
|
-
k = i;
|
|
10732
|
-
d.length = 1;
|
|
10733
|
-
}
|
|
10734
|
-
d.reverse();
|
|
10735
|
-
for (i = k;i--; )
|
|
10736
|
-
d.push(0);
|
|
10737
|
-
d.reverse();
|
|
10738
|
-
} else {
|
|
10739
|
-
i = xd.length;
|
|
10740
|
-
len = yd.length;
|
|
10741
|
-
xLTy = i < len;
|
|
10742
|
-
if (xLTy)
|
|
10743
|
-
len = i;
|
|
10744
|
-
for (i = 0;i < len; i++) {
|
|
10745
|
-
if (xd[i] != yd[i]) {
|
|
10746
|
-
xLTy = xd[i] < yd[i];
|
|
10747
|
-
break;
|
|
10748
|
-
}
|
|
10749
|
-
}
|
|
10750
|
-
k = 0;
|
|
10751
|
-
}
|
|
10752
|
-
if (xLTy) {
|
|
10753
|
-
d = xd;
|
|
10754
|
-
xd = yd;
|
|
10755
|
-
yd = d;
|
|
10756
|
-
y.s = -y.s;
|
|
10757
|
-
}
|
|
10758
|
-
len = xd.length;
|
|
10759
|
-
for (i = yd.length - len;i > 0; --i)
|
|
10760
|
-
xd[len++] = 0;
|
|
10761
|
-
for (i = yd.length;i > k; ) {
|
|
10762
|
-
if (xd[--i] < yd[i]) {
|
|
10763
|
-
for (j = i;j && xd[--j] === 0; )
|
|
10764
|
-
xd[j] = BASE - 1;
|
|
10765
|
-
--xd[j];
|
|
10766
|
-
xd[i] += BASE;
|
|
10767
|
-
}
|
|
10768
|
-
xd[i] -= yd[i];
|
|
10769
|
-
}
|
|
10770
|
-
for (;xd[--len] === 0; )
|
|
10771
|
-
xd.pop();
|
|
10772
|
-
for (;xd[0] === 0; xd.shift())
|
|
10773
|
-
--e;
|
|
10774
|
-
if (!xd[0])
|
|
10775
|
-
return new Ctor(rm === 3 ? -0 : 0);
|
|
10776
|
-
y.d = xd;
|
|
10777
|
-
y.e = getBase10Exponent(xd, e);
|
|
10778
|
-
return external2 ? finalise(y, pr, rm) : y;
|
|
10779
|
-
};
|
|
10780
|
-
P.modulo = P.mod = function(y) {
|
|
10781
|
-
var q, x = this, Ctor = x.constructor;
|
|
10782
|
-
y = new Ctor(y);
|
|
10783
|
-
if (!x.d || !y.s || y.d && !y.d[0])
|
|
10784
|
-
return new Ctor(NaN);
|
|
10785
|
-
if (!y.d || x.d && !x.d[0]) {
|
|
10786
|
-
return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
|
|
10787
|
-
}
|
|
10788
|
-
external2 = false;
|
|
10789
|
-
if (Ctor.modulo == 9) {
|
|
10790
|
-
q = divide(x, y.abs(), 0, 3, 1);
|
|
10791
|
-
q.s *= y.s;
|
|
10792
|
-
} else {
|
|
10793
|
-
q = divide(x, y, 0, Ctor.modulo, 1);
|
|
10794
|
-
}
|
|
10795
|
-
q = q.times(y);
|
|
10796
|
-
external2 = true;
|
|
10797
|
-
return x.minus(q);
|
|
10798
|
-
};
|
|
10799
|
-
P.naturalExponential = P.exp = function() {
|
|
10800
|
-
return naturalExponential(this);
|
|
10801
|
-
};
|
|
10802
|
-
P.naturalLogarithm = P.ln = function() {
|
|
10803
|
-
return naturalLogarithm(this);
|
|
10804
|
-
};
|
|
10805
|
-
P.negated = P.neg = function() {
|
|
10806
|
-
var x = new this.constructor(this);
|
|
10807
|
-
x.s = -x.s;
|
|
10808
|
-
return finalise(x);
|
|
10809
|
-
};
|
|
10810
|
-
P.plus = P.add = function(y) {
|
|
10811
|
-
var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
|
|
10812
|
-
y = new Ctor(y);
|
|
10813
|
-
if (!x.d || !y.d) {
|
|
10814
|
-
if (!x.s || !y.s)
|
|
10815
|
-
y = new Ctor(NaN);
|
|
10816
|
-
else if (!x.d)
|
|
10817
|
-
y = new Ctor(y.d || x.s === y.s ? x : NaN);
|
|
10818
|
-
return y;
|
|
10819
|
-
}
|
|
10820
|
-
if (x.s != y.s) {
|
|
10821
|
-
y.s = -y.s;
|
|
10822
|
-
return x.minus(y);
|
|
10823
|
-
}
|
|
10824
|
-
xd = x.d;
|
|
10825
|
-
yd = y.d;
|
|
10826
|
-
pr = Ctor.precision;
|
|
10827
|
-
rm = Ctor.rounding;
|
|
10828
|
-
if (!xd[0] || !yd[0]) {
|
|
10829
|
-
if (!yd[0])
|
|
10830
|
-
y = new Ctor(x);
|
|
10831
|
-
return external2 ? finalise(y, pr, rm) : y;
|
|
10832
|
-
}
|
|
10833
|
-
k = mathfloor(x.e / LOG_BASE);
|
|
10834
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
10835
|
-
xd = xd.slice();
|
|
10836
|
-
i = k - e;
|
|
10837
|
-
if (i) {
|
|
10838
|
-
if (i < 0) {
|
|
10839
|
-
d = xd;
|
|
10840
|
-
i = -i;
|
|
10841
|
-
len = yd.length;
|
|
10842
|
-
} else {
|
|
10843
|
-
d = yd;
|
|
10844
|
-
e = k;
|
|
10845
|
-
len = xd.length;
|
|
10846
|
-
}
|
|
10847
|
-
k = Math.ceil(pr / LOG_BASE);
|
|
10848
|
-
len = k > len ? k + 1 : len + 1;
|
|
10849
|
-
if (i > len) {
|
|
10850
|
-
i = len;
|
|
10851
|
-
d.length = 1;
|
|
10852
|
-
}
|
|
10853
|
-
d.reverse();
|
|
10854
|
-
for (;i--; )
|
|
10855
|
-
d.push(0);
|
|
10856
|
-
d.reverse();
|
|
10857
|
-
}
|
|
10858
|
-
len = xd.length;
|
|
10859
|
-
i = yd.length;
|
|
10860
|
-
if (len - i < 0) {
|
|
10861
|
-
i = len;
|
|
10862
|
-
d = yd;
|
|
10863
|
-
yd = xd;
|
|
10864
|
-
xd = d;
|
|
10865
|
-
}
|
|
10866
|
-
for (carry = 0;i; ) {
|
|
10867
|
-
carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
|
|
10868
|
-
xd[i] %= BASE;
|
|
10869
|
-
}
|
|
10870
|
-
if (carry) {
|
|
10871
|
-
xd.unshift(carry);
|
|
10872
|
-
++e;
|
|
10873
|
-
}
|
|
10874
|
-
for (len = xd.length;xd[--len] == 0; )
|
|
10875
|
-
xd.pop();
|
|
10876
|
-
y.d = xd;
|
|
10877
|
-
y.e = getBase10Exponent(xd, e);
|
|
10878
|
-
return external2 ? finalise(y, pr, rm) : y;
|
|
10879
|
-
};
|
|
10880
|
-
P.precision = P.sd = function(z) {
|
|
10881
|
-
var k, x = this;
|
|
10882
|
-
if (z !== undefined && z !== !!z && z !== 1 && z !== 0)
|
|
10883
|
-
throw Error(invalidArgument + z);
|
|
10884
|
-
if (x.d) {
|
|
10885
|
-
k = getPrecision(x.d);
|
|
10886
|
-
if (z && x.e + 1 > k)
|
|
10887
|
-
k = x.e + 1;
|
|
10888
|
-
} else {
|
|
10889
|
-
k = NaN;
|
|
10890
|
-
}
|
|
10891
|
-
return k;
|
|
10892
|
-
};
|
|
10893
|
-
P.round = function() {
|
|
10894
|
-
var x = this, Ctor = x.constructor;
|
|
10895
|
-
return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
|
|
10896
|
-
};
|
|
10897
|
-
P.sine = P.sin = function() {
|
|
10898
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
10899
|
-
if (!x.isFinite())
|
|
10900
|
-
return new Ctor(NaN);
|
|
10901
|
-
if (x.isZero())
|
|
10902
|
-
return new Ctor(x);
|
|
10903
|
-
pr = Ctor.precision;
|
|
10904
|
-
rm = Ctor.rounding;
|
|
10905
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
|
10906
|
-
Ctor.rounding = 1;
|
|
10907
|
-
x = sine(Ctor, toLessThanHalfPi(Ctor, x));
|
|
10908
|
-
Ctor.precision = pr;
|
|
10909
|
-
Ctor.rounding = rm;
|
|
10910
|
-
return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
|
|
10911
|
-
};
|
|
10912
|
-
P.squareRoot = P.sqrt = function() {
|
|
10913
|
-
var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
|
|
10914
|
-
if (s !== 1 || !d || !d[0]) {
|
|
10915
|
-
return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
|
|
10916
|
-
}
|
|
10917
|
-
external2 = false;
|
|
10918
|
-
s = Math.sqrt(+x);
|
|
10919
|
-
if (s == 0 || s == 1 / 0) {
|
|
10920
|
-
n = digitsToString(d);
|
|
10921
|
-
if ((n.length + e) % 2 == 0)
|
|
10922
|
-
n += "0";
|
|
10923
|
-
s = Math.sqrt(n);
|
|
10924
|
-
e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
10925
|
-
if (s == 1 / 0) {
|
|
10926
|
-
n = "5e" + e;
|
|
10927
|
-
} else {
|
|
10928
|
-
n = s.toExponential();
|
|
10929
|
-
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
10930
|
-
}
|
|
10931
|
-
r = new Ctor(n);
|
|
10932
|
-
} else {
|
|
10933
|
-
r = new Ctor(s.toString());
|
|
10934
|
-
}
|
|
10935
|
-
sd = (e = Ctor.precision) + 3;
|
|
10936
|
-
for (;; ) {
|
|
10937
|
-
t = r;
|
|
10938
|
-
r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
|
|
10939
|
-
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
10940
|
-
n = n.slice(sd - 3, sd + 1);
|
|
10941
|
-
if (n == "9999" || !rep && n == "4999") {
|
|
10942
|
-
if (!rep) {
|
|
10943
|
-
finalise(t, e + 1, 0);
|
|
10944
|
-
if (t.times(t).eq(x)) {
|
|
10945
|
-
r = t;
|
|
10946
|
-
break;
|
|
10947
|
-
}
|
|
10948
|
-
}
|
|
10949
|
-
sd += 4;
|
|
10950
|
-
rep = 1;
|
|
10951
|
-
} else {
|
|
10952
|
-
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
10953
|
-
finalise(r, e + 1, 1);
|
|
10954
|
-
m = !r.times(r).eq(x);
|
|
10955
|
-
}
|
|
10956
|
-
break;
|
|
10957
|
-
}
|
|
10958
|
-
}
|
|
10959
|
-
}
|
|
10960
|
-
external2 = true;
|
|
10961
|
-
return finalise(r, e, Ctor.rounding, m);
|
|
10962
|
-
};
|
|
10963
|
-
P.tangent = P.tan = function() {
|
|
10964
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
10965
|
-
if (!x.isFinite())
|
|
10966
|
-
return new Ctor(NaN);
|
|
10967
|
-
if (x.isZero())
|
|
10968
|
-
return new Ctor(x);
|
|
10969
|
-
pr = Ctor.precision;
|
|
10970
|
-
rm = Ctor.rounding;
|
|
10971
|
-
Ctor.precision = pr + 10;
|
|
10972
|
-
Ctor.rounding = 1;
|
|
10973
|
-
x = x.sin();
|
|
10974
|
-
x.s = 1;
|
|
10975
|
-
x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
|
|
10976
|
-
Ctor.precision = pr;
|
|
10977
|
-
Ctor.rounding = rm;
|
|
10978
|
-
return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
|
|
10979
|
-
};
|
|
10980
|
-
P.times = P.mul = function(y) {
|
|
10981
|
-
var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
|
|
10982
|
-
y.s *= x.s;
|
|
10983
|
-
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
10984
|
-
return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
|
|
10985
|
-
}
|
|
10986
|
-
e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
|
|
10987
|
-
xdL = xd.length;
|
|
10988
|
-
ydL = yd.length;
|
|
10989
|
-
if (xdL < ydL) {
|
|
10990
|
-
r = xd;
|
|
10991
|
-
xd = yd;
|
|
10992
|
-
yd = r;
|
|
10993
|
-
rL = xdL;
|
|
10994
|
-
xdL = ydL;
|
|
10995
|
-
ydL = rL;
|
|
10996
|
-
}
|
|
10997
|
-
r = [];
|
|
10998
|
-
rL = xdL + ydL;
|
|
10999
|
-
for (i = rL;i--; )
|
|
11000
|
-
r.push(0);
|
|
11001
|
-
for (i = ydL;--i >= 0; ) {
|
|
11002
|
-
carry = 0;
|
|
11003
|
-
for (k = xdL + i;k > i; ) {
|
|
11004
|
-
t = r[k] + yd[i] * xd[k - i - 1] + carry;
|
|
11005
|
-
r[k--] = t % BASE | 0;
|
|
11006
|
-
carry = t / BASE | 0;
|
|
11007
|
-
}
|
|
11008
|
-
r[k] = (r[k] + carry) % BASE | 0;
|
|
11009
|
-
}
|
|
11010
|
-
for (;!r[--rL]; )
|
|
11011
|
-
r.pop();
|
|
11012
|
-
if (carry)
|
|
11013
|
-
++e;
|
|
11014
|
-
else
|
|
11015
|
-
r.shift();
|
|
11016
|
-
y.d = r;
|
|
11017
|
-
y.e = getBase10Exponent(r, e);
|
|
11018
|
-
return external2 ? finalise(y, Ctor.precision, Ctor.rounding) : y;
|
|
11019
|
-
};
|
|
11020
|
-
P.toBinary = function(sd, rm) {
|
|
11021
|
-
return toStringBinary(this, 2, sd, rm);
|
|
11022
|
-
};
|
|
11023
|
-
P.toDecimalPlaces = P.toDP = function(dp, rm) {
|
|
11024
|
-
var x = this, Ctor = x.constructor;
|
|
11025
|
-
x = new Ctor(x);
|
|
11026
|
-
if (dp === undefined)
|
|
11027
|
-
return x;
|
|
11028
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
11029
|
-
if (rm === undefined)
|
|
11030
|
-
rm = Ctor.rounding;
|
|
11031
|
-
else
|
|
11032
|
-
checkInt32(rm, 0, 8);
|
|
11033
|
-
return finalise(x, dp + x.e + 1, rm);
|
|
11034
|
-
};
|
|
11035
|
-
P.toExponential = function(dp, rm) {
|
|
11036
|
-
var str, x = this, Ctor = x.constructor;
|
|
11037
|
-
if (dp === undefined) {
|
|
11038
|
-
str = finiteToString(x, true);
|
|
11039
|
-
} else {
|
|
11040
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
11041
|
-
if (rm === undefined)
|
|
11042
|
-
rm = Ctor.rounding;
|
|
11043
|
-
else
|
|
11044
|
-
checkInt32(rm, 0, 8);
|
|
11045
|
-
x = finalise(new Ctor(x), dp + 1, rm);
|
|
11046
|
-
str = finiteToString(x, true, dp + 1);
|
|
11047
|
-
}
|
|
11048
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
11049
|
-
};
|
|
11050
|
-
P.toFixed = function(dp, rm) {
|
|
11051
|
-
var str, y, x = this, Ctor = x.constructor;
|
|
11052
|
-
if (dp === undefined) {
|
|
11053
|
-
str = finiteToString(x);
|
|
11054
|
-
} else {
|
|
11055
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
11056
|
-
if (rm === undefined)
|
|
11057
|
-
rm = Ctor.rounding;
|
|
11058
|
-
else
|
|
11059
|
-
checkInt32(rm, 0, 8);
|
|
11060
|
-
y = finalise(new Ctor(x), dp + x.e + 1, rm);
|
|
11061
|
-
str = finiteToString(y, false, dp + y.e + 1);
|
|
11062
|
-
}
|
|
11063
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
11064
|
-
};
|
|
11065
|
-
P.toFraction = function(maxD) {
|
|
11066
|
-
var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
|
|
11067
|
-
if (!xd)
|
|
11068
|
-
return new Ctor(x);
|
|
11069
|
-
n1 = d0 = new Ctor(1);
|
|
11070
|
-
d1 = n0 = new Ctor(0);
|
|
11071
|
-
d = new Ctor(d1);
|
|
11072
|
-
e = d.e = getPrecision(xd) - x.e - 1;
|
|
11073
|
-
k = e % LOG_BASE;
|
|
11074
|
-
d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
|
|
11075
|
-
if (maxD == null) {
|
|
11076
|
-
maxD = e > 0 ? d : n1;
|
|
11077
|
-
} else {
|
|
11078
|
-
n = new Ctor(maxD);
|
|
11079
|
-
if (!n.isInt() || n.lt(n1))
|
|
11080
|
-
throw Error(invalidArgument + n);
|
|
11081
|
-
maxD = n.gt(d) ? e > 0 ? d : n1 : n;
|
|
11082
|
-
}
|
|
11083
|
-
external2 = false;
|
|
11084
|
-
n = new Ctor(digitsToString(xd));
|
|
11085
|
-
pr = Ctor.precision;
|
|
11086
|
-
Ctor.precision = e = xd.length * LOG_BASE * 2;
|
|
11087
|
-
for (;; ) {
|
|
11088
|
-
q = divide(n, d, 0, 1, 1);
|
|
11089
|
-
d2 = d0.plus(q.times(d1));
|
|
11090
|
-
if (d2.cmp(maxD) == 1)
|
|
11091
|
-
break;
|
|
11092
|
-
d0 = d1;
|
|
11093
|
-
d1 = d2;
|
|
11094
|
-
d2 = n1;
|
|
11095
|
-
n1 = n0.plus(q.times(d2));
|
|
11096
|
-
n0 = d2;
|
|
11097
|
-
d2 = d;
|
|
11098
|
-
d = n.minus(q.times(d2));
|
|
11099
|
-
n = d2;
|
|
11100
|
-
}
|
|
11101
|
-
d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
|
|
11102
|
-
n0 = n0.plus(d2.times(n1));
|
|
11103
|
-
d0 = d0.plus(d2.times(d1));
|
|
11104
|
-
n0.s = n1.s = x.s;
|
|
11105
|
-
r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
|
|
11106
|
-
Ctor.precision = pr;
|
|
11107
|
-
external2 = true;
|
|
11108
|
-
return r;
|
|
11109
|
-
};
|
|
11110
|
-
P.toHexadecimal = P.toHex = function(sd, rm) {
|
|
11111
|
-
return toStringBinary(this, 16, sd, rm);
|
|
11112
|
-
};
|
|
11113
|
-
P.toNearest = function(y, rm) {
|
|
11114
|
-
var x = this, Ctor = x.constructor;
|
|
11115
|
-
x = new Ctor(x);
|
|
11116
|
-
if (y == null) {
|
|
11117
|
-
if (!x.d)
|
|
11118
|
-
return x;
|
|
11119
|
-
y = new Ctor(1);
|
|
11120
|
-
rm = Ctor.rounding;
|
|
11121
|
-
} else {
|
|
11122
|
-
y = new Ctor(y);
|
|
11123
|
-
if (rm === undefined) {
|
|
11124
|
-
rm = Ctor.rounding;
|
|
11125
|
-
} else {
|
|
11126
|
-
checkInt32(rm, 0, 8);
|
|
11127
|
-
}
|
|
11128
|
-
if (!x.d)
|
|
11129
|
-
return y.s ? x : y;
|
|
11130
|
-
if (!y.d) {
|
|
11131
|
-
if (y.s)
|
|
11132
|
-
y.s = x.s;
|
|
11133
|
-
return y;
|
|
11134
|
-
}
|
|
11135
|
-
}
|
|
11136
|
-
if (y.d[0]) {
|
|
11137
|
-
external2 = false;
|
|
11138
|
-
x = divide(x, y, 0, rm, 1).times(y);
|
|
11139
|
-
external2 = true;
|
|
11140
|
-
finalise(x);
|
|
11141
|
-
} else {
|
|
11142
|
-
y.s = x.s;
|
|
11143
|
-
x = y;
|
|
11144
|
-
}
|
|
11145
|
-
return x;
|
|
11146
|
-
};
|
|
11147
|
-
P.toNumber = function() {
|
|
11148
|
-
return +this;
|
|
11149
|
-
};
|
|
11150
|
-
P.toOctal = function(sd, rm) {
|
|
11151
|
-
return toStringBinary(this, 8, sd, rm);
|
|
11152
|
-
};
|
|
11153
|
-
P.toPower = P.pow = function(y) {
|
|
11154
|
-
var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
|
|
11155
|
-
if (!x.d || !y.d || !x.d[0] || !y.d[0])
|
|
11156
|
-
return new Ctor(mathpow(+x, yn));
|
|
11157
|
-
x = new Ctor(x);
|
|
11158
|
-
if (x.eq(1))
|
|
11159
|
-
return x;
|
|
11160
|
-
pr = Ctor.precision;
|
|
11161
|
-
rm = Ctor.rounding;
|
|
11162
|
-
if (y.eq(1))
|
|
11163
|
-
return finalise(x, pr, rm);
|
|
11164
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
11165
|
-
if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
|
|
11166
|
-
r = intPow(Ctor, x, k, pr);
|
|
11167
|
-
return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
|
|
11168
|
-
}
|
|
11169
|
-
s = x.s;
|
|
11170
|
-
if (s < 0) {
|
|
11171
|
-
if (e < y.d.length - 1)
|
|
11172
|
-
return new Ctor(NaN);
|
|
11173
|
-
if ((y.d[e] & 1) == 0)
|
|
11174
|
-
s = 1;
|
|
11175
|
-
if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
|
|
11176
|
-
x.s = s;
|
|
11177
|
-
return x;
|
|
11178
|
-
}
|
|
11179
|
-
}
|
|
11180
|
-
k = mathpow(+x, yn);
|
|
11181
|
-
e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
|
|
11182
|
-
if (e > Ctor.maxE + 1 || e < Ctor.minE - 1)
|
|
11183
|
-
return new Ctor(e > 0 ? s / 0 : 0);
|
|
11184
|
-
external2 = false;
|
|
11185
|
-
Ctor.rounding = x.s = 1;
|
|
11186
|
-
k = Math.min(12, (e + "").length);
|
|
11187
|
-
r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
|
|
11188
|
-
if (r.d) {
|
|
11189
|
-
r = finalise(r, pr + 5, 1);
|
|
11190
|
-
if (checkRoundingDigits(r.d, pr, rm)) {
|
|
11191
|
-
e = pr + 10;
|
|
11192
|
-
r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
|
|
11193
|
-
if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 100000000000000) {
|
|
11194
|
-
r = finalise(r, pr + 1, 0);
|
|
11195
|
-
}
|
|
11196
|
-
}
|
|
11197
|
-
}
|
|
11198
|
-
r.s = s;
|
|
11199
|
-
external2 = true;
|
|
11200
|
-
Ctor.rounding = rm;
|
|
11201
|
-
return finalise(r, pr, rm);
|
|
11202
|
-
};
|
|
11203
|
-
P.toPrecision = function(sd, rm) {
|
|
11204
|
-
var str, x = this, Ctor = x.constructor;
|
|
11205
|
-
if (sd === undefined) {
|
|
11206
|
-
str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
11207
|
-
} else {
|
|
11208
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
11209
|
-
if (rm === undefined)
|
|
11210
|
-
rm = Ctor.rounding;
|
|
11211
|
-
else
|
|
11212
|
-
checkInt32(rm, 0, 8);
|
|
11213
|
-
x = finalise(new Ctor(x), sd, rm);
|
|
11214
|
-
str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
|
|
11215
|
-
}
|
|
11216
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
11217
|
-
};
|
|
11218
|
-
P.toSignificantDigits = P.toSD = function(sd, rm) {
|
|
11219
|
-
var x = this, Ctor = x.constructor;
|
|
11220
|
-
if (sd === undefined) {
|
|
11221
|
-
sd = Ctor.precision;
|
|
11222
|
-
rm = Ctor.rounding;
|
|
11223
|
-
} else {
|
|
11224
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
11225
|
-
if (rm === undefined)
|
|
11226
|
-
rm = Ctor.rounding;
|
|
11227
|
-
else
|
|
11228
|
-
checkInt32(rm, 0, 8);
|
|
11229
|
-
}
|
|
11230
|
-
return finalise(new Ctor(x), sd, rm);
|
|
11231
|
-
};
|
|
11232
|
-
P.toString = function() {
|
|
11233
|
-
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
11234
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
11235
|
-
};
|
|
11236
|
-
P.truncated = P.trunc = function() {
|
|
11237
|
-
return finalise(new this.constructor(this), this.e + 1, 1);
|
|
11238
|
-
};
|
|
11239
|
-
P.valueOf = P.toJSON = function() {
|
|
11240
|
-
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
11241
|
-
return x.isNeg() ? "-" + str : str;
|
|
11242
|
-
};
|
|
11243
|
-
function digitsToString(d) {
|
|
11244
|
-
var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
|
|
11245
|
-
if (indexOfLastWord > 0) {
|
|
11246
|
-
str += w;
|
|
11247
|
-
for (i = 1;i < indexOfLastWord; i++) {
|
|
11248
|
-
ws = d[i] + "";
|
|
11249
|
-
k = LOG_BASE - ws.length;
|
|
11250
|
-
if (k)
|
|
11251
|
-
str += getZeroString(k);
|
|
11252
|
-
str += ws;
|
|
11253
|
-
}
|
|
11254
|
-
w = d[i];
|
|
11255
|
-
ws = w + "";
|
|
11256
|
-
k = LOG_BASE - ws.length;
|
|
11257
|
-
if (k)
|
|
11258
|
-
str += getZeroString(k);
|
|
11259
|
-
} else if (w === 0) {
|
|
11260
|
-
return "0";
|
|
11261
|
-
}
|
|
11262
|
-
for (;w % 10 === 0; )
|
|
11263
|
-
w /= 10;
|
|
11264
|
-
return str + w;
|
|
11265
|
-
}
|
|
11266
|
-
function checkInt32(i, min, max) {
|
|
11267
|
-
if (i !== ~~i || i < min || i > max) {
|
|
11268
|
-
throw Error(invalidArgument + i);
|
|
11269
|
-
}
|
|
11270
|
-
}
|
|
11271
|
-
function checkRoundingDigits(d, i, rm, repeating) {
|
|
11272
|
-
var di, k, r, rd;
|
|
11273
|
-
for (k = d[0];k >= 10; k /= 10)
|
|
11274
|
-
--i;
|
|
11275
|
-
if (--i < 0) {
|
|
11276
|
-
i += LOG_BASE;
|
|
11277
|
-
di = 0;
|
|
11278
|
-
} else {
|
|
11279
|
-
di = Math.ceil((i + 1) / LOG_BASE);
|
|
11280
|
-
i %= LOG_BASE;
|
|
11281
|
-
}
|
|
11282
|
-
k = mathpow(10, LOG_BASE - i);
|
|
11283
|
-
rd = d[di] % k | 0;
|
|
11284
|
-
if (repeating == null) {
|
|
11285
|
-
if (i < 3) {
|
|
11286
|
-
if (i == 0)
|
|
11287
|
-
rd = rd / 100 | 0;
|
|
11288
|
-
else if (i == 1)
|
|
11289
|
-
rd = rd / 10 | 0;
|
|
11290
|
-
r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 50000 || rd == 0;
|
|
11291
|
-
} else {
|
|
11292
|
-
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;
|
|
11293
|
-
}
|
|
11294
|
-
} else {
|
|
11295
|
-
if (i < 4) {
|
|
11296
|
-
if (i == 0)
|
|
11297
|
-
rd = rd / 1000 | 0;
|
|
11298
|
-
else if (i == 1)
|
|
11299
|
-
rd = rd / 100 | 0;
|
|
11300
|
-
else if (i == 2)
|
|
11301
|
-
rd = rd / 10 | 0;
|
|
11302
|
-
r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
|
|
11303
|
-
} else {
|
|
11304
|
-
r = ((repeating || rm < 4) && rd + 1 == k || !repeating && rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 1000 | 0) == mathpow(10, i - 3) - 1;
|
|
11305
|
-
}
|
|
11306
|
-
}
|
|
11307
|
-
return r;
|
|
11308
|
-
}
|
|
11309
|
-
function convertBase(str, baseIn, baseOut) {
|
|
11310
|
-
var j, arr = [0], arrL, i = 0, strL = str.length;
|
|
11311
|
-
for (;i < strL; ) {
|
|
11312
|
-
for (arrL = arr.length;arrL--; )
|
|
11313
|
-
arr[arrL] *= baseIn;
|
|
11314
|
-
arr[0] += NUMERALS.indexOf(str.charAt(i++));
|
|
11315
|
-
for (j = 0;j < arr.length; j++) {
|
|
11316
|
-
if (arr[j] > baseOut - 1) {
|
|
11317
|
-
if (arr[j + 1] === undefined)
|
|
11318
|
-
arr[j + 1] = 0;
|
|
11319
|
-
arr[j + 1] += arr[j] / baseOut | 0;
|
|
11320
|
-
arr[j] %= baseOut;
|
|
11321
|
-
}
|
|
11322
|
-
}
|
|
11323
|
-
}
|
|
11324
|
-
return arr.reverse();
|
|
11325
|
-
}
|
|
11326
|
-
function cosine(Ctor, x) {
|
|
11327
|
-
var k, len, y;
|
|
11328
|
-
if (x.isZero())
|
|
11329
|
-
return x;
|
|
11330
|
-
len = x.d.length;
|
|
11331
|
-
if (len < 32) {
|
|
11332
|
-
k = Math.ceil(len / 3);
|
|
11333
|
-
y = (1 / tinyPow(4, k)).toString();
|
|
11334
|
-
} else {
|
|
11335
|
-
k = 16;
|
|
11336
|
-
y = "2.3283064365386962890625e-10";
|
|
11337
|
-
}
|
|
11338
|
-
Ctor.precision += k;
|
|
11339
|
-
x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
|
|
11340
|
-
for (var i = k;i--; ) {
|
|
11341
|
-
var cos2x = x.times(x);
|
|
11342
|
-
x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
|
|
11343
|
-
}
|
|
11344
|
-
Ctor.precision -= k;
|
|
11345
|
-
return x;
|
|
11346
|
-
}
|
|
11347
|
-
var divide = function() {
|
|
11348
|
-
function multiplyInteger(x, k, base) {
|
|
11349
|
-
var temp, carry = 0, i = x.length;
|
|
11350
|
-
for (x = x.slice();i--; ) {
|
|
11351
|
-
temp = x[i] * k + carry;
|
|
11352
|
-
x[i] = temp % base | 0;
|
|
11353
|
-
carry = temp / base | 0;
|
|
11354
|
-
}
|
|
11355
|
-
if (carry)
|
|
11356
|
-
x.unshift(carry);
|
|
11357
|
-
return x;
|
|
11358
|
-
}
|
|
11359
|
-
function compare(a, b, aL, bL) {
|
|
11360
|
-
var i, r;
|
|
11361
|
-
if (aL != bL) {
|
|
11362
|
-
r = aL > bL ? 1 : -1;
|
|
11363
|
-
} else {
|
|
11364
|
-
for (i = r = 0;i < aL; i++) {
|
|
11365
|
-
if (a[i] != b[i]) {
|
|
11366
|
-
r = a[i] > b[i] ? 1 : -1;
|
|
11367
|
-
break;
|
|
11368
|
-
}
|
|
11369
|
-
}
|
|
11370
|
-
}
|
|
11371
|
-
return r;
|
|
11372
|
-
}
|
|
11373
|
-
function subtract(a, b, aL, base) {
|
|
11374
|
-
var i = 0;
|
|
11375
|
-
for (;aL--; ) {
|
|
11376
|
-
a[aL] -= i;
|
|
11377
|
-
i = a[aL] < b[aL] ? 1 : 0;
|
|
11378
|
-
a[aL] = i * base + a[aL] - b[aL];
|
|
11379
|
-
}
|
|
11380
|
-
for (;!a[0] && a.length > 1; )
|
|
11381
|
-
a.shift();
|
|
11382
|
-
}
|
|
11383
|
-
return function(x, y, pr, rm, dp, base) {
|
|
11384
|
-
var cmp, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
|
|
11385
|
-
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
11386
|
-
return new Ctor(!x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : xd && xd[0] == 0 || !yd ? sign * 0 : sign / 0);
|
|
11387
|
-
}
|
|
11388
|
-
if (base) {
|
|
11389
|
-
logBase = 1;
|
|
11390
|
-
e = x.e - y.e;
|
|
11391
|
-
} else {
|
|
11392
|
-
base = BASE;
|
|
11393
|
-
logBase = LOG_BASE;
|
|
11394
|
-
e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
|
|
11395
|
-
}
|
|
11396
|
-
yL = yd.length;
|
|
11397
|
-
xL = xd.length;
|
|
11398
|
-
q = new Ctor(sign);
|
|
11399
|
-
qd = q.d = [];
|
|
11400
|
-
for (i = 0;yd[i] == (xd[i] || 0); i++)
|
|
11401
|
-
;
|
|
11402
|
-
if (yd[i] > (xd[i] || 0))
|
|
11403
|
-
e--;
|
|
11404
|
-
if (pr == null) {
|
|
11405
|
-
sd = pr = Ctor.precision;
|
|
11406
|
-
rm = Ctor.rounding;
|
|
11407
|
-
} else if (dp) {
|
|
11408
|
-
sd = pr + (x.e - y.e) + 1;
|
|
11409
|
-
} else {
|
|
11410
|
-
sd = pr;
|
|
11411
|
-
}
|
|
11412
|
-
if (sd < 0) {
|
|
11413
|
-
qd.push(1);
|
|
11414
|
-
more = true;
|
|
11415
|
-
} else {
|
|
11416
|
-
sd = sd / logBase + 2 | 0;
|
|
11417
|
-
i = 0;
|
|
11418
|
-
if (yL == 1) {
|
|
11419
|
-
k = 0;
|
|
11420
|
-
yd = yd[0];
|
|
11421
|
-
sd++;
|
|
11422
|
-
for (;(i < xL || k) && sd--; i++) {
|
|
11423
|
-
t = k * base + (xd[i] || 0);
|
|
11424
|
-
qd[i] = t / yd | 0;
|
|
11425
|
-
k = t % yd | 0;
|
|
11426
|
-
}
|
|
11427
|
-
more = k || i < xL;
|
|
11428
|
-
} else {
|
|
11429
|
-
k = base / (yd[0] + 1) | 0;
|
|
11430
|
-
if (k > 1) {
|
|
11431
|
-
yd = multiplyInteger(yd, k, base);
|
|
11432
|
-
xd = multiplyInteger(xd, k, base);
|
|
11433
|
-
yL = yd.length;
|
|
11434
|
-
xL = xd.length;
|
|
11435
|
-
}
|
|
11436
|
-
xi = yL;
|
|
11437
|
-
rem = xd.slice(0, yL);
|
|
11438
|
-
remL = rem.length;
|
|
11439
|
-
for (;remL < yL; )
|
|
11440
|
-
rem[remL++] = 0;
|
|
11441
|
-
yz = yd.slice();
|
|
11442
|
-
yz.unshift(0);
|
|
11443
|
-
yd0 = yd[0];
|
|
11444
|
-
if (yd[1] >= base / 2)
|
|
11445
|
-
++yd0;
|
|
11446
|
-
do {
|
|
11447
|
-
k = 0;
|
|
11448
|
-
cmp = compare(yd, rem, yL, remL);
|
|
11449
|
-
if (cmp < 0) {
|
|
11450
|
-
rem0 = rem[0];
|
|
11451
|
-
if (yL != remL)
|
|
11452
|
-
rem0 = rem0 * base + (rem[1] || 0);
|
|
11453
|
-
k = rem0 / yd0 | 0;
|
|
11454
|
-
if (k > 1) {
|
|
11455
|
-
if (k >= base)
|
|
11456
|
-
k = base - 1;
|
|
11457
|
-
prod = multiplyInteger(yd, k, base);
|
|
11458
|
-
prodL = prod.length;
|
|
11459
|
-
remL = rem.length;
|
|
11460
|
-
cmp = compare(prod, rem, prodL, remL);
|
|
11461
|
-
if (cmp == 1) {
|
|
11462
|
-
k--;
|
|
11463
|
-
subtract(prod, yL < prodL ? yz : yd, prodL, base);
|
|
11464
|
-
}
|
|
11465
|
-
} else {
|
|
11466
|
-
if (k == 0)
|
|
11467
|
-
cmp = k = 1;
|
|
11468
|
-
prod = yd.slice();
|
|
11469
|
-
}
|
|
11470
|
-
prodL = prod.length;
|
|
11471
|
-
if (prodL < remL)
|
|
11472
|
-
prod.unshift(0);
|
|
11473
|
-
subtract(rem, prod, remL, base);
|
|
11474
|
-
if (cmp == -1) {
|
|
11475
|
-
remL = rem.length;
|
|
11476
|
-
cmp = compare(yd, rem, yL, remL);
|
|
11477
|
-
if (cmp < 1) {
|
|
11478
|
-
k++;
|
|
11479
|
-
subtract(rem, yL < remL ? yz : yd, remL, base);
|
|
11480
|
-
}
|
|
11481
|
-
}
|
|
11482
|
-
remL = rem.length;
|
|
11483
|
-
} else if (cmp === 0) {
|
|
11484
|
-
k++;
|
|
11485
|
-
rem = [0];
|
|
11486
|
-
}
|
|
11487
|
-
qd[i++] = k;
|
|
11488
|
-
if (cmp && rem[0]) {
|
|
11489
|
-
rem[remL++] = xd[xi] || 0;
|
|
11490
|
-
} else {
|
|
11491
|
-
rem = [xd[xi]];
|
|
11492
|
-
remL = 1;
|
|
11493
|
-
}
|
|
11494
|
-
} while ((xi++ < xL || rem[0] !== undefined) && sd--);
|
|
11495
|
-
more = rem[0] !== undefined;
|
|
11496
|
-
}
|
|
11497
|
-
if (!qd[0])
|
|
11498
|
-
qd.shift();
|
|
11499
|
-
}
|
|
11500
|
-
if (logBase == 1) {
|
|
11501
|
-
q.e = e;
|
|
11502
|
-
inexact = more;
|
|
11503
|
-
} else {
|
|
11504
|
-
for (i = 1, k = qd[0];k >= 10; k /= 10)
|
|
11505
|
-
i++;
|
|
11506
|
-
q.e = i + e * logBase - 1;
|
|
11507
|
-
finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
|
|
11508
|
-
}
|
|
11509
|
-
return q;
|
|
11510
|
-
};
|
|
11511
|
-
}();
|
|
11512
|
-
function finalise(x, sd, rm, isTruncated) {
|
|
11513
|
-
var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
|
|
11514
|
-
out:
|
|
11515
|
-
if (sd != null) {
|
|
11516
|
-
xd = x.d;
|
|
11517
|
-
if (!xd)
|
|
11518
|
-
return x;
|
|
11519
|
-
for (digits = 1, k = xd[0];k >= 10; k /= 10)
|
|
11520
|
-
digits++;
|
|
11521
|
-
i = sd - digits;
|
|
11522
|
-
if (i < 0) {
|
|
11523
|
-
i += LOG_BASE;
|
|
11524
|
-
j = sd;
|
|
11525
|
-
w = xd[xdi = 0];
|
|
11526
|
-
rd = w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
11527
|
-
} else {
|
|
11528
|
-
xdi = Math.ceil((i + 1) / LOG_BASE);
|
|
11529
|
-
k = xd.length;
|
|
11530
|
-
if (xdi >= k) {
|
|
11531
|
-
if (isTruncated) {
|
|
11532
|
-
for (;k++ <= xdi; )
|
|
11533
|
-
xd.push(0);
|
|
11534
|
-
w = rd = 0;
|
|
11535
|
-
digits = 1;
|
|
11536
|
-
i %= LOG_BASE;
|
|
11537
|
-
j = i - LOG_BASE + 1;
|
|
11538
|
-
} else {
|
|
11539
|
-
break out;
|
|
11540
|
-
}
|
|
11541
|
-
} else {
|
|
11542
|
-
w = k = xd[xdi];
|
|
11543
|
-
for (digits = 1;k >= 10; k /= 10)
|
|
11544
|
-
digits++;
|
|
11545
|
-
i %= LOG_BASE;
|
|
11546
|
-
j = i - LOG_BASE + digits;
|
|
11547
|
-
rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
11548
|
-
}
|
|
11549
|
-
}
|
|
11550
|
-
isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== undefined || (j < 0 ? w : w % mathpow(10, digits - j - 1));
|
|
11551
|
-
roundUp = rm < 4 ? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 && (i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
11552
|
-
if (sd < 1 || !xd[0]) {
|
|
11553
|
-
xd.length = 0;
|
|
11554
|
-
if (roundUp) {
|
|
11555
|
-
sd -= x.e + 1;
|
|
11556
|
-
xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
|
|
11557
|
-
x.e = -sd || 0;
|
|
11558
|
-
} else {
|
|
11559
|
-
xd[0] = x.e = 0;
|
|
11560
|
-
}
|
|
11561
|
-
return x;
|
|
11562
|
-
}
|
|
11563
|
-
if (i == 0) {
|
|
11564
|
-
xd.length = xdi;
|
|
11565
|
-
k = 1;
|
|
11566
|
-
xdi--;
|
|
11567
|
-
} else {
|
|
11568
|
-
xd.length = xdi + 1;
|
|
11569
|
-
k = mathpow(10, LOG_BASE - i);
|
|
11570
|
-
xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
|
|
11571
|
-
}
|
|
11572
|
-
if (roundUp) {
|
|
11573
|
-
for (;; ) {
|
|
11574
|
-
if (xdi == 0) {
|
|
11575
|
-
for (i = 1, j = xd[0];j >= 10; j /= 10)
|
|
11576
|
-
i++;
|
|
11577
|
-
j = xd[0] += k;
|
|
11578
|
-
for (k = 1;j >= 10; j /= 10)
|
|
11579
|
-
k++;
|
|
11580
|
-
if (i != k) {
|
|
11581
|
-
x.e++;
|
|
11582
|
-
if (xd[0] == BASE)
|
|
11583
|
-
xd[0] = 1;
|
|
11584
|
-
}
|
|
11585
|
-
break;
|
|
11586
|
-
} else {
|
|
11587
|
-
xd[xdi] += k;
|
|
11588
|
-
if (xd[xdi] != BASE)
|
|
11589
|
-
break;
|
|
11590
|
-
xd[xdi--] = 0;
|
|
11591
|
-
k = 1;
|
|
11592
|
-
}
|
|
11593
|
-
}
|
|
11594
|
-
}
|
|
11595
|
-
for (i = xd.length;xd[--i] === 0; )
|
|
11596
|
-
xd.pop();
|
|
11597
|
-
}
|
|
11598
|
-
if (external2) {
|
|
11599
|
-
if (x.e > Ctor.maxE) {
|
|
11600
|
-
x.d = null;
|
|
11601
|
-
x.e = NaN;
|
|
11602
|
-
} else if (x.e < Ctor.minE) {
|
|
11603
|
-
x.e = 0;
|
|
11604
|
-
x.d = [0];
|
|
11605
|
-
}
|
|
11606
|
-
}
|
|
11607
|
-
return x;
|
|
11608
|
-
}
|
|
11609
|
-
function finiteToString(x, isExp, sd) {
|
|
11610
|
-
if (!x.isFinite())
|
|
11611
|
-
return nonFiniteToString(x);
|
|
11612
|
-
var k, e = x.e, str = digitsToString(x.d), len = str.length;
|
|
11613
|
-
if (isExp) {
|
|
11614
|
-
if (sd && (k = sd - len) > 0) {
|
|
11615
|
-
str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
|
|
11616
|
-
} else if (len > 1) {
|
|
11617
|
-
str = str.charAt(0) + "." + str.slice(1);
|
|
11618
|
-
}
|
|
11619
|
-
str = str + (x.e < 0 ? "e" : "e+") + x.e;
|
|
11620
|
-
} else if (e < 0) {
|
|
11621
|
-
str = "0." + getZeroString(-e - 1) + str;
|
|
11622
|
-
if (sd && (k = sd - len) > 0)
|
|
11623
|
-
str += getZeroString(k);
|
|
11624
|
-
} else if (e >= len) {
|
|
11625
|
-
str += getZeroString(e + 1 - len);
|
|
11626
|
-
if (sd && (k = sd - e - 1) > 0)
|
|
11627
|
-
str = str + "." + getZeroString(k);
|
|
11628
|
-
} else {
|
|
11629
|
-
if ((k = e + 1) < len)
|
|
11630
|
-
str = str.slice(0, k) + "." + str.slice(k);
|
|
11631
|
-
if (sd && (k = sd - len) > 0) {
|
|
11632
|
-
if (e + 1 === len)
|
|
11633
|
-
str += ".";
|
|
11634
|
-
str += getZeroString(k);
|
|
11635
|
-
}
|
|
11636
|
-
}
|
|
11637
|
-
return str;
|
|
11638
|
-
}
|
|
11639
|
-
function getBase10Exponent(digits, e) {
|
|
11640
|
-
var w = digits[0];
|
|
11641
|
-
for (e *= LOG_BASE;w >= 10; w /= 10)
|
|
11642
|
-
e++;
|
|
11643
|
-
return e;
|
|
11644
|
-
}
|
|
11645
|
-
function getLn10(Ctor, sd, pr) {
|
|
11646
|
-
if (sd > LN10_PRECISION) {
|
|
11647
|
-
external2 = true;
|
|
11648
|
-
if (pr)
|
|
11649
|
-
Ctor.precision = pr;
|
|
11650
|
-
throw Error(precisionLimitExceeded);
|
|
11651
|
-
}
|
|
11652
|
-
return finalise(new Ctor(LN10), sd, 1, true);
|
|
11653
|
-
}
|
|
11654
|
-
function getPi(Ctor, sd, rm) {
|
|
11655
|
-
if (sd > PI_PRECISION)
|
|
11656
|
-
throw Error(precisionLimitExceeded);
|
|
11657
|
-
return finalise(new Ctor(PI), sd, rm, true);
|
|
11658
|
-
}
|
|
11659
|
-
function getPrecision(digits) {
|
|
11660
|
-
var w = digits.length - 1, len = w * LOG_BASE + 1;
|
|
11661
|
-
w = digits[w];
|
|
11662
|
-
if (w) {
|
|
11663
|
-
for (;w % 10 == 0; w /= 10)
|
|
11664
|
-
len--;
|
|
11665
|
-
for (w = digits[0];w >= 10; w /= 10)
|
|
11666
|
-
len++;
|
|
11667
|
-
}
|
|
11668
|
-
return len;
|
|
11669
|
-
}
|
|
11670
|
-
function getZeroString(k) {
|
|
11671
|
-
var zs = "";
|
|
11672
|
-
for (;k--; )
|
|
11673
|
-
zs += "0";
|
|
11674
|
-
return zs;
|
|
11675
|
-
}
|
|
11676
|
-
function intPow(Ctor, x, n, pr) {
|
|
11677
|
-
var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
|
|
11678
|
-
external2 = false;
|
|
11679
|
-
for (;; ) {
|
|
11680
|
-
if (n % 2) {
|
|
11681
|
-
r = r.times(x);
|
|
11682
|
-
if (truncate(r.d, k))
|
|
11683
|
-
isTruncated = true;
|
|
11684
|
-
}
|
|
11685
|
-
n = mathfloor(n / 2);
|
|
11686
|
-
if (n === 0) {
|
|
11687
|
-
n = r.d.length - 1;
|
|
11688
|
-
if (isTruncated && r.d[n] === 0)
|
|
11689
|
-
++r.d[n];
|
|
11690
|
-
break;
|
|
11691
|
-
}
|
|
11692
|
-
x = x.times(x);
|
|
11693
|
-
truncate(x.d, k);
|
|
11694
|
-
}
|
|
11695
|
-
external2 = true;
|
|
11696
|
-
return r;
|
|
11697
|
-
}
|
|
11698
|
-
function isOdd(n) {
|
|
11699
|
-
return n.d[n.d.length - 1] & 1;
|
|
11700
|
-
}
|
|
11701
|
-
function maxOrMin(Ctor, args, n) {
|
|
11702
|
-
var k, y, x = new Ctor(args[0]), i = 0;
|
|
11703
|
-
for (;++i < args.length; ) {
|
|
11704
|
-
y = new Ctor(args[i]);
|
|
11705
|
-
if (!y.s) {
|
|
11706
|
-
x = y;
|
|
11707
|
-
break;
|
|
11708
|
-
}
|
|
11709
|
-
k = x.cmp(y);
|
|
11710
|
-
if (k === n || k === 0 && x.s === n) {
|
|
11711
|
-
x = y;
|
|
11712
|
-
}
|
|
11713
|
-
}
|
|
11714
|
-
return x;
|
|
11715
|
-
}
|
|
11716
|
-
function naturalExponential(x, sd) {
|
|
11717
|
-
var denominator, guard, j, pow, sum, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
|
11718
|
-
if (!x.d || !x.d[0] || x.e > 17) {
|
|
11719
|
-
return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
|
|
11720
|
-
}
|
|
11721
|
-
if (sd == null) {
|
|
11722
|
-
external2 = false;
|
|
11723
|
-
wpr = pr;
|
|
11724
|
-
} else {
|
|
11725
|
-
wpr = sd;
|
|
11726
|
-
}
|
|
11727
|
-
t = new Ctor(0.03125);
|
|
11728
|
-
while (x.e > -2) {
|
|
11729
|
-
x = x.times(t);
|
|
11730
|
-
k += 5;
|
|
11731
|
-
}
|
|
11732
|
-
guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
|
|
11733
|
-
wpr += guard;
|
|
11734
|
-
denominator = pow = sum = new Ctor(1);
|
|
11735
|
-
Ctor.precision = wpr;
|
|
11736
|
-
for (;; ) {
|
|
11737
|
-
pow = finalise(pow.times(x), wpr, 1);
|
|
11738
|
-
denominator = denominator.times(++i);
|
|
11739
|
-
t = sum.plus(divide(pow, denominator, wpr, 1));
|
|
11740
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
|
|
11741
|
-
j = k;
|
|
11742
|
-
while (j--)
|
|
11743
|
-
sum = finalise(sum.times(sum), wpr, 1);
|
|
11744
|
-
if (sd == null) {
|
|
11745
|
-
if (rep < 3 && checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
|
|
11746
|
-
Ctor.precision = wpr += 10;
|
|
11747
|
-
denominator = pow = t = new Ctor(1);
|
|
11748
|
-
i = 0;
|
|
11749
|
-
rep++;
|
|
11750
|
-
} else {
|
|
11751
|
-
return finalise(sum, Ctor.precision = pr, rm, external2 = true);
|
|
11752
|
-
}
|
|
11753
|
-
} else {
|
|
11754
|
-
Ctor.precision = pr;
|
|
11755
|
-
return sum;
|
|
11756
|
-
}
|
|
11757
|
-
}
|
|
11758
|
-
sum = t;
|
|
11759
|
-
}
|
|
11760
|
-
}
|
|
11761
|
-
function naturalLogarithm(y, sd) {
|
|
11762
|
-
var c, c0, denominator, e, numerator, rep, sum, t, wpr, x1, x2, n = 1, guard = 10, x = y, xd = x.d, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
|
11763
|
-
if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
|
|
11764
|
-
return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
|
|
11765
|
-
}
|
|
11766
|
-
if (sd == null) {
|
|
11767
|
-
external2 = false;
|
|
11768
|
-
wpr = pr;
|
|
11769
|
-
} else {
|
|
11770
|
-
wpr = sd;
|
|
11771
|
-
}
|
|
11772
|
-
Ctor.precision = wpr += guard;
|
|
11773
|
-
c = digitsToString(xd);
|
|
11774
|
-
c0 = c.charAt(0);
|
|
11775
|
-
if (Math.abs(e = x.e) < 1500000000000000) {
|
|
11776
|
-
while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
|
|
11777
|
-
x = x.times(y);
|
|
11778
|
-
c = digitsToString(x.d);
|
|
11779
|
-
c0 = c.charAt(0);
|
|
11780
|
-
n++;
|
|
11781
|
-
}
|
|
11782
|
-
e = x.e;
|
|
11783
|
-
if (c0 > 1) {
|
|
11784
|
-
x = new Ctor("0." + c);
|
|
11785
|
-
e++;
|
|
11786
|
-
} else {
|
|
11787
|
-
x = new Ctor(c0 + "." + c.slice(1));
|
|
11788
|
-
}
|
|
11789
|
-
} else {
|
|
11790
|
-
t = getLn10(Ctor, wpr + 2, pr).times(e + "");
|
|
11791
|
-
x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
|
|
11792
|
-
Ctor.precision = pr;
|
|
11793
|
-
return sd == null ? finalise(x, pr, rm, external2 = true) : x;
|
|
11794
|
-
}
|
|
11795
|
-
x1 = x;
|
|
11796
|
-
sum = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
|
|
11797
|
-
x2 = finalise(x.times(x), wpr, 1);
|
|
11798
|
-
denominator = 3;
|
|
11799
|
-
for (;; ) {
|
|
11800
|
-
numerator = finalise(numerator.times(x2), wpr, 1);
|
|
11801
|
-
t = sum.plus(divide(numerator, new Ctor(denominator), wpr, 1));
|
|
11802
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
|
|
11803
|
-
sum = sum.times(2);
|
|
11804
|
-
if (e !== 0)
|
|
11805
|
-
sum = sum.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
|
|
11806
|
-
sum = divide(sum, new Ctor(n), wpr, 1);
|
|
11807
|
-
if (sd == null) {
|
|
11808
|
-
if (checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
|
|
11809
|
-
Ctor.precision = wpr += guard;
|
|
11810
|
-
t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
|
|
11811
|
-
x2 = finalise(x.times(x), wpr, 1);
|
|
11812
|
-
denominator = rep = 1;
|
|
11813
|
-
} else {
|
|
11814
|
-
return finalise(sum, Ctor.precision = pr, rm, external2 = true);
|
|
11815
|
-
}
|
|
11816
|
-
} else {
|
|
11817
|
-
Ctor.precision = pr;
|
|
11818
|
-
return sum;
|
|
11819
|
-
}
|
|
11820
|
-
}
|
|
11821
|
-
sum = t;
|
|
11822
|
-
denominator += 2;
|
|
11823
|
-
}
|
|
11824
|
-
}
|
|
11825
|
-
function nonFiniteToString(x) {
|
|
11826
|
-
return String(x.s * x.s / 0);
|
|
11827
|
-
}
|
|
11828
|
-
function parseDecimal(x, str) {
|
|
11829
|
-
var e, i, len;
|
|
11830
|
-
if ((e = str.indexOf(".")) > -1)
|
|
11831
|
-
str = str.replace(".", "");
|
|
11832
|
-
if ((i = str.search(/e/i)) > 0) {
|
|
11833
|
-
if (e < 0)
|
|
11834
|
-
e = i;
|
|
11835
|
-
e += +str.slice(i + 1);
|
|
11836
|
-
str = str.substring(0, i);
|
|
11837
|
-
} else if (e < 0) {
|
|
11838
|
-
e = str.length;
|
|
11839
|
-
}
|
|
11840
|
-
for (i = 0;str.charCodeAt(i) === 48; i++)
|
|
11841
|
-
;
|
|
11842
|
-
for (len = str.length;str.charCodeAt(len - 1) === 48; --len)
|
|
11843
|
-
;
|
|
11844
|
-
str = str.slice(i, len);
|
|
11845
|
-
if (str) {
|
|
11846
|
-
len -= i;
|
|
11847
|
-
x.e = e = e - i - 1;
|
|
11848
|
-
x.d = [];
|
|
11849
|
-
i = (e + 1) % LOG_BASE;
|
|
11850
|
-
if (e < 0)
|
|
11851
|
-
i += LOG_BASE;
|
|
11852
|
-
if (i < len) {
|
|
11853
|
-
if (i)
|
|
11854
|
-
x.d.push(+str.slice(0, i));
|
|
11855
|
-
for (len -= LOG_BASE;i < len; )
|
|
11856
|
-
x.d.push(+str.slice(i, i += LOG_BASE));
|
|
11857
|
-
str = str.slice(i);
|
|
11858
|
-
i = LOG_BASE - str.length;
|
|
11859
|
-
} else {
|
|
11860
|
-
i -= len;
|
|
11861
|
-
}
|
|
11862
|
-
for (;i--; )
|
|
11863
|
-
str += "0";
|
|
11864
|
-
x.d.push(+str);
|
|
11865
|
-
if (external2) {
|
|
11866
|
-
if (x.e > x.constructor.maxE) {
|
|
11867
|
-
x.d = null;
|
|
11868
|
-
x.e = NaN;
|
|
11869
|
-
} else if (x.e < x.constructor.minE) {
|
|
11870
|
-
x.e = 0;
|
|
11871
|
-
x.d = [0];
|
|
11872
|
-
}
|
|
11873
|
-
}
|
|
11874
|
-
} else {
|
|
11875
|
-
x.e = 0;
|
|
11876
|
-
x.d = [0];
|
|
11877
|
-
}
|
|
11878
|
-
return x;
|
|
11879
|
-
}
|
|
11880
|
-
function parseOther(x, str) {
|
|
11881
|
-
var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
|
|
11882
|
-
if (str.indexOf("_") > -1) {
|
|
11883
|
-
str = str.replace(/(\d)_(?=\d)/g, "$1");
|
|
11884
|
-
if (isDecimal.test(str))
|
|
11885
|
-
return parseDecimal(x, str);
|
|
11886
|
-
} else if (str === "Infinity" || str === "NaN") {
|
|
11887
|
-
if (!+str)
|
|
11888
|
-
x.s = NaN;
|
|
11889
|
-
x.e = NaN;
|
|
11890
|
-
x.d = null;
|
|
11891
|
-
return x;
|
|
11892
|
-
}
|
|
11893
|
-
if (isHex.test(str)) {
|
|
11894
|
-
base = 16;
|
|
11895
|
-
str = str.toLowerCase();
|
|
11896
|
-
} else if (isBinary.test(str)) {
|
|
11897
|
-
base = 2;
|
|
11898
|
-
} else if (isOctal.test(str)) {
|
|
11899
|
-
base = 8;
|
|
11900
|
-
} else {
|
|
11901
|
-
throw Error(invalidArgument + str);
|
|
11902
|
-
}
|
|
11903
|
-
i = str.search(/p/i);
|
|
11904
|
-
if (i > 0) {
|
|
11905
|
-
p = +str.slice(i + 1);
|
|
11906
|
-
str = str.substring(2, i);
|
|
11907
|
-
} else {
|
|
11908
|
-
str = str.slice(2);
|
|
11909
|
-
}
|
|
11910
|
-
i = str.indexOf(".");
|
|
11911
|
-
isFloat = i >= 0;
|
|
11912
|
-
Ctor = x.constructor;
|
|
11913
|
-
if (isFloat) {
|
|
11914
|
-
str = str.replace(".", "");
|
|
11915
|
-
len = str.length;
|
|
11916
|
-
i = len - i;
|
|
11917
|
-
divisor = intPow(Ctor, new Ctor(base), i, i * 2);
|
|
11918
|
-
}
|
|
11919
|
-
xd = convertBase(str, base, BASE);
|
|
11920
|
-
xe = xd.length - 1;
|
|
11921
|
-
for (i = xe;xd[i] === 0; --i)
|
|
11922
|
-
xd.pop();
|
|
11923
|
-
if (i < 0)
|
|
11924
|
-
return new Ctor(x.s * 0);
|
|
11925
|
-
x.e = getBase10Exponent(xd, xe);
|
|
11926
|
-
x.d = xd;
|
|
11927
|
-
external2 = false;
|
|
11928
|
-
if (isFloat)
|
|
11929
|
-
x = divide(x, divisor, len * 4);
|
|
11930
|
-
if (p)
|
|
11931
|
-
x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
|
|
11932
|
-
external2 = true;
|
|
11933
|
-
return x;
|
|
11934
|
-
}
|
|
11935
|
-
function sine(Ctor, x) {
|
|
11936
|
-
var k, len = x.d.length;
|
|
11937
|
-
if (len < 3) {
|
|
11938
|
-
return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
|
|
11939
|
-
}
|
|
11940
|
-
k = 1.4 * Math.sqrt(len);
|
|
11941
|
-
k = k > 16 ? 16 : k | 0;
|
|
11942
|
-
x = x.times(1 / tinyPow(5, k));
|
|
11943
|
-
x = taylorSeries(Ctor, 2, x, x);
|
|
11944
|
-
var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
11945
|
-
for (;k--; ) {
|
|
11946
|
-
sin2_x = x.times(x);
|
|
11947
|
-
x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
|
|
11948
|
-
}
|
|
11949
|
-
return x;
|
|
11950
|
-
}
|
|
11951
|
-
function taylorSeries(Ctor, n, x, y, isHyperbolic) {
|
|
11952
|
-
var j, t, u, x2, i = 1, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
|
|
11953
|
-
external2 = false;
|
|
11954
|
-
x2 = x.times(x);
|
|
11955
|
-
u = new Ctor(y);
|
|
11956
|
-
for (;; ) {
|
|
11957
|
-
t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
|
|
11958
|
-
u = isHyperbolic ? y.plus(t) : y.minus(t);
|
|
11959
|
-
y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
|
|
11960
|
-
t = u.plus(y);
|
|
11961
|
-
if (t.d[k] !== undefined) {
|
|
11962
|
-
for (j = k;t.d[j] === u.d[j] && j--; )
|
|
11963
|
-
;
|
|
11964
|
-
if (j == -1)
|
|
11965
|
-
break;
|
|
11966
|
-
}
|
|
11967
|
-
j = u;
|
|
11968
|
-
u = y;
|
|
11969
|
-
y = t;
|
|
11970
|
-
t = j;
|
|
11971
|
-
i++;
|
|
11972
|
-
}
|
|
11973
|
-
external2 = true;
|
|
11974
|
-
t.d.length = k + 1;
|
|
11975
|
-
return t;
|
|
11976
|
-
}
|
|
11977
|
-
function tinyPow(b, e) {
|
|
11978
|
-
var n = b;
|
|
11979
|
-
while (--e)
|
|
11980
|
-
n *= b;
|
|
11981
|
-
return n;
|
|
11982
|
-
}
|
|
11983
|
-
function toLessThanHalfPi(Ctor, x) {
|
|
11984
|
-
var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
|
|
11985
|
-
x = x.abs();
|
|
11986
|
-
if (x.lte(halfPi)) {
|
|
11987
|
-
quadrant = isNeg ? 4 : 1;
|
|
11988
|
-
return x;
|
|
11989
|
-
}
|
|
11990
|
-
t = x.divToInt(pi);
|
|
11991
|
-
if (t.isZero()) {
|
|
11992
|
-
quadrant = isNeg ? 3 : 2;
|
|
11993
|
-
} else {
|
|
11994
|
-
x = x.minus(t.times(pi));
|
|
11995
|
-
if (x.lte(halfPi)) {
|
|
11996
|
-
quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
|
|
11997
|
-
return x;
|
|
11998
|
-
}
|
|
11999
|
-
quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
|
|
12000
|
-
}
|
|
12001
|
-
return x.minus(pi).abs();
|
|
12002
|
-
}
|
|
12003
|
-
function toStringBinary(x, baseOut, sd, rm) {
|
|
12004
|
-
var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== undefined;
|
|
12005
|
-
if (isExp) {
|
|
12006
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
12007
|
-
if (rm === undefined)
|
|
12008
|
-
rm = Ctor.rounding;
|
|
12009
|
-
else
|
|
12010
|
-
checkInt32(rm, 0, 8);
|
|
12011
|
-
} else {
|
|
12012
|
-
sd = Ctor.precision;
|
|
12013
|
-
rm = Ctor.rounding;
|
|
12014
|
-
}
|
|
12015
|
-
if (!x.isFinite()) {
|
|
12016
|
-
str = nonFiniteToString(x);
|
|
12017
|
-
} else {
|
|
12018
|
-
str = finiteToString(x);
|
|
12019
|
-
i = str.indexOf(".");
|
|
12020
|
-
if (isExp) {
|
|
12021
|
-
base = 2;
|
|
12022
|
-
if (baseOut == 16) {
|
|
12023
|
-
sd = sd * 4 - 3;
|
|
12024
|
-
} else if (baseOut == 8) {
|
|
12025
|
-
sd = sd * 3 - 2;
|
|
12026
|
-
}
|
|
12027
|
-
} else {
|
|
12028
|
-
base = baseOut;
|
|
12029
|
-
}
|
|
12030
|
-
if (i >= 0) {
|
|
12031
|
-
str = str.replace(".", "");
|
|
12032
|
-
y = new Ctor(1);
|
|
12033
|
-
y.e = str.length - i;
|
|
12034
|
-
y.d = convertBase(finiteToString(y), 10, base);
|
|
12035
|
-
y.e = y.d.length;
|
|
12036
|
-
}
|
|
12037
|
-
xd = convertBase(str, 10, base);
|
|
12038
|
-
e = len = xd.length;
|
|
12039
|
-
for (;xd[--len] == 0; )
|
|
12040
|
-
xd.pop();
|
|
12041
|
-
if (!xd[0]) {
|
|
12042
|
-
str = isExp ? "0p+0" : "0";
|
|
12043
|
-
} else {
|
|
12044
|
-
if (i < 0) {
|
|
12045
|
-
e--;
|
|
12046
|
-
} else {
|
|
12047
|
-
x = new Ctor(x);
|
|
12048
|
-
x.d = xd;
|
|
12049
|
-
x.e = e;
|
|
12050
|
-
x = divide(x, y, sd, rm, 0, base);
|
|
12051
|
-
xd = x.d;
|
|
12052
|
-
e = x.e;
|
|
12053
|
-
roundUp = inexact;
|
|
12054
|
-
}
|
|
12055
|
-
i = xd[sd];
|
|
12056
|
-
k = base / 2;
|
|
12057
|
-
roundUp = roundUp || xd[sd + 1] !== undefined;
|
|
12058
|
-
roundUp = rm < 4 ? (i !== undefined || 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));
|
|
12059
|
-
xd.length = sd;
|
|
12060
|
-
if (roundUp) {
|
|
12061
|
-
for (;++xd[--sd] > base - 1; ) {
|
|
12062
|
-
xd[sd] = 0;
|
|
12063
|
-
if (!sd) {
|
|
12064
|
-
++e;
|
|
12065
|
-
xd.unshift(1);
|
|
12066
|
-
}
|
|
12067
|
-
}
|
|
12068
|
-
}
|
|
12069
|
-
for (len = xd.length;!xd[len - 1]; --len)
|
|
12070
|
-
;
|
|
12071
|
-
for (i = 0, str = "";i < len; i++)
|
|
12072
|
-
str += NUMERALS.charAt(xd[i]);
|
|
12073
|
-
if (isExp) {
|
|
12074
|
-
if (len > 1) {
|
|
12075
|
-
if (baseOut == 16 || baseOut == 8) {
|
|
12076
|
-
i = baseOut == 16 ? 4 : 3;
|
|
12077
|
-
for (--len;len % i; len++)
|
|
12078
|
-
str += "0";
|
|
12079
|
-
xd = convertBase(str, base, baseOut);
|
|
12080
|
-
for (len = xd.length;!xd[len - 1]; --len)
|
|
12081
|
-
;
|
|
12082
|
-
for (i = 1, str = "1.";i < len; i++)
|
|
12083
|
-
str += NUMERALS.charAt(xd[i]);
|
|
12084
|
-
} else {
|
|
12085
|
-
str = str.charAt(0) + "." + str.slice(1);
|
|
12086
|
-
}
|
|
12087
|
-
}
|
|
12088
|
-
str = str + (e < 0 ? "p" : "p+") + e;
|
|
12089
|
-
} else if (e < 0) {
|
|
12090
|
-
for (;++e; )
|
|
12091
|
-
str = "0" + str;
|
|
12092
|
-
str = "0." + str;
|
|
12093
|
-
} else {
|
|
12094
|
-
if (++e > len)
|
|
12095
|
-
for (e -= len;e--; )
|
|
12096
|
-
str += "0";
|
|
12097
|
-
else if (e < len)
|
|
12098
|
-
str = str.slice(0, e) + "." + str.slice(e);
|
|
12099
|
-
}
|
|
12100
|
-
}
|
|
12101
|
-
str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
|
|
12102
|
-
}
|
|
12103
|
-
return x.s < 0 ? "-" + str : str;
|
|
12104
|
-
}
|
|
12105
|
-
function truncate(arr, len) {
|
|
12106
|
-
if (arr.length > len) {
|
|
12107
|
-
arr.length = len;
|
|
12108
|
-
return true;
|
|
12109
|
-
}
|
|
12110
|
-
}
|
|
12111
|
-
function abs(x) {
|
|
12112
|
-
return new this(x).abs();
|
|
12113
|
-
}
|
|
12114
|
-
function acos(x) {
|
|
12115
|
-
return new this(x).acos();
|
|
12116
|
-
}
|
|
12117
|
-
function acosh(x) {
|
|
12118
|
-
return new this(x).acosh();
|
|
12119
|
-
}
|
|
12120
|
-
function add(x, y) {
|
|
12121
|
-
return new this(x).plus(y);
|
|
12122
|
-
}
|
|
12123
|
-
function asin(x) {
|
|
12124
|
-
return new this(x).asin();
|
|
12125
|
-
}
|
|
12126
|
-
function asinh(x) {
|
|
12127
|
-
return new this(x).asinh();
|
|
12128
|
-
}
|
|
12129
|
-
function atan(x) {
|
|
12130
|
-
return new this(x).atan();
|
|
12131
|
-
}
|
|
12132
|
-
function atanh(x) {
|
|
12133
|
-
return new this(x).atanh();
|
|
12134
|
-
}
|
|
12135
|
-
function atan2(y, x) {
|
|
12136
|
-
y = new this(y);
|
|
12137
|
-
x = new this(x);
|
|
12138
|
-
var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
|
|
12139
|
-
if (!y.s || !x.s) {
|
|
12140
|
-
r = new this(NaN);
|
|
12141
|
-
} else if (!y.d && !x.d) {
|
|
12142
|
-
r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
|
|
12143
|
-
r.s = y.s;
|
|
12144
|
-
} else if (!x.d || y.isZero()) {
|
|
12145
|
-
r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
|
|
12146
|
-
r.s = y.s;
|
|
12147
|
-
} else if (!y.d || x.isZero()) {
|
|
12148
|
-
r = getPi(this, wpr, 1).times(0.5);
|
|
12149
|
-
r.s = y.s;
|
|
12150
|
-
} else if (x.s < 0) {
|
|
12151
|
-
this.precision = wpr;
|
|
12152
|
-
this.rounding = 1;
|
|
12153
|
-
r = this.atan(divide(y, x, wpr, 1));
|
|
12154
|
-
x = getPi(this, wpr, 1);
|
|
12155
|
-
this.precision = pr;
|
|
12156
|
-
this.rounding = rm;
|
|
12157
|
-
r = y.s < 0 ? r.minus(x) : r.plus(x);
|
|
12158
|
-
} else {
|
|
12159
|
-
r = this.atan(divide(y, x, wpr, 1));
|
|
12160
|
-
}
|
|
12161
|
-
return r;
|
|
12162
|
-
}
|
|
12163
|
-
function cbrt(x) {
|
|
12164
|
-
return new this(x).cbrt();
|
|
12165
|
-
}
|
|
12166
|
-
function ceil(x) {
|
|
12167
|
-
return finalise(x = new this(x), x.e + 1, 2);
|
|
12168
|
-
}
|
|
12169
|
-
function clamp(x, min, max) {
|
|
12170
|
-
return new this(x).clamp(min, max);
|
|
12171
|
-
}
|
|
12172
|
-
function config(obj) {
|
|
12173
|
-
if (!obj || typeof obj !== "object")
|
|
12174
|
-
throw Error(decimalError + "Object expected");
|
|
12175
|
-
var i, p, v, useDefaults = obj.defaults === true, ps = [
|
|
12176
|
-
"precision",
|
|
12177
|
-
1,
|
|
12178
|
-
MAX_DIGITS,
|
|
12179
|
-
"rounding",
|
|
12180
|
-
0,
|
|
12181
|
-
8,
|
|
12182
|
-
"toExpNeg",
|
|
12183
|
-
-EXP_LIMIT,
|
|
12184
|
-
0,
|
|
12185
|
-
"toExpPos",
|
|
12186
|
-
0,
|
|
12187
|
-
EXP_LIMIT,
|
|
12188
|
-
"maxE",
|
|
12189
|
-
0,
|
|
12190
|
-
EXP_LIMIT,
|
|
12191
|
-
"minE",
|
|
12192
|
-
-EXP_LIMIT,
|
|
12193
|
-
0,
|
|
12194
|
-
"modulo",
|
|
12195
|
-
0,
|
|
12196
|
-
9
|
|
12197
|
-
];
|
|
12198
|
-
for (i = 0;i < ps.length; i += 3) {
|
|
12199
|
-
if (p = ps[i], useDefaults)
|
|
12200
|
-
this[p] = DEFAULTS[p];
|
|
12201
|
-
if ((v = obj[p]) !== undefined) {
|
|
12202
|
-
if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
|
|
12203
|
-
this[p] = v;
|
|
12204
|
-
else
|
|
12205
|
-
throw Error(invalidArgument + p + ": " + v);
|
|
12206
|
-
}
|
|
12207
|
-
}
|
|
12208
|
-
if (p = "crypto", useDefaults)
|
|
12209
|
-
this[p] = DEFAULTS[p];
|
|
12210
|
-
if ((v = obj[p]) !== undefined) {
|
|
12211
|
-
if (v === true || v === false || v === 0 || v === 1) {
|
|
12212
|
-
if (v) {
|
|
12213
|
-
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
|
12214
|
-
this[p] = true;
|
|
12215
|
-
} else {
|
|
12216
|
-
throw Error(cryptoUnavailable);
|
|
12217
|
-
}
|
|
12218
|
-
} else {
|
|
12219
|
-
this[p] = false;
|
|
12220
|
-
}
|
|
12221
|
-
} else {
|
|
12222
|
-
throw Error(invalidArgument + p + ": " + v);
|
|
12223
|
-
}
|
|
12224
|
-
}
|
|
12225
|
-
return this;
|
|
12226
|
-
}
|
|
12227
|
-
function cos(x) {
|
|
12228
|
-
return new this(x).cos();
|
|
12229
|
-
}
|
|
12230
|
-
function cosh(x) {
|
|
12231
|
-
return new this(x).cosh();
|
|
12232
|
-
}
|
|
12233
|
-
function clone(obj) {
|
|
12234
|
-
var i, p, ps;
|
|
12235
|
-
function Decimal(v) {
|
|
12236
|
-
var e, i2, t, x = this;
|
|
12237
|
-
if (!(x instanceof Decimal))
|
|
12238
|
-
return new Decimal(v);
|
|
12239
|
-
x.constructor = Decimal;
|
|
12240
|
-
if (isDecimalInstance(v)) {
|
|
12241
|
-
x.s = v.s;
|
|
12242
|
-
if (external2) {
|
|
12243
|
-
if (!v.d || v.e > Decimal.maxE) {
|
|
12244
|
-
x.e = NaN;
|
|
12245
|
-
x.d = null;
|
|
12246
|
-
} else if (v.e < Decimal.minE) {
|
|
12247
|
-
x.e = 0;
|
|
12248
|
-
x.d = [0];
|
|
12249
|
-
} else {
|
|
12250
|
-
x.e = v.e;
|
|
12251
|
-
x.d = v.d.slice();
|
|
12252
|
-
}
|
|
12253
|
-
} else {
|
|
12254
|
-
x.e = v.e;
|
|
12255
|
-
x.d = v.d ? v.d.slice() : v.d;
|
|
12256
|
-
}
|
|
12257
|
-
return;
|
|
12258
|
-
}
|
|
12259
|
-
t = typeof v;
|
|
12260
|
-
if (t === "number") {
|
|
12261
|
-
if (v === 0) {
|
|
12262
|
-
x.s = 1 / v < 0 ? -1 : 1;
|
|
12263
|
-
x.e = 0;
|
|
12264
|
-
x.d = [0];
|
|
12265
|
-
return;
|
|
12266
|
-
}
|
|
12267
|
-
if (v < 0) {
|
|
12268
|
-
v = -v;
|
|
12269
|
-
x.s = -1;
|
|
12270
|
-
} else {
|
|
12271
|
-
x.s = 1;
|
|
12272
|
-
}
|
|
12273
|
-
if (v === ~~v && v < 1e7) {
|
|
12274
|
-
for (e = 0, i2 = v;i2 >= 10; i2 /= 10)
|
|
12275
|
-
e++;
|
|
12276
|
-
if (external2) {
|
|
12277
|
-
if (e > Decimal.maxE) {
|
|
12278
|
-
x.e = NaN;
|
|
12279
|
-
x.d = null;
|
|
12280
|
-
} else if (e < Decimal.minE) {
|
|
12281
|
-
x.e = 0;
|
|
12282
|
-
x.d = [0];
|
|
12283
|
-
} else {
|
|
12284
|
-
x.e = e;
|
|
12285
|
-
x.d = [v];
|
|
12286
|
-
}
|
|
12287
|
-
} else {
|
|
12288
|
-
x.e = e;
|
|
12289
|
-
x.d = [v];
|
|
12290
|
-
}
|
|
12291
|
-
return;
|
|
12292
|
-
}
|
|
12293
|
-
if (v * 0 !== 0) {
|
|
12294
|
-
if (!v)
|
|
12295
|
-
x.s = NaN;
|
|
12296
|
-
x.e = NaN;
|
|
12297
|
-
x.d = null;
|
|
12298
|
-
return;
|
|
12299
|
-
}
|
|
12300
|
-
return parseDecimal(x, v.toString());
|
|
12301
|
-
}
|
|
12302
|
-
if (t === "string") {
|
|
12303
|
-
if ((i2 = v.charCodeAt(0)) === 45) {
|
|
12304
|
-
v = v.slice(1);
|
|
12305
|
-
x.s = -1;
|
|
12306
|
-
} else {
|
|
12307
|
-
if (i2 === 43)
|
|
12308
|
-
v = v.slice(1);
|
|
12309
|
-
x.s = 1;
|
|
12310
|
-
}
|
|
12311
|
-
return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
|
|
12312
|
-
}
|
|
12313
|
-
if (t === "bigint") {
|
|
12314
|
-
if (v < 0) {
|
|
12315
|
-
v = -v;
|
|
12316
|
-
x.s = -1;
|
|
12317
|
-
} else {
|
|
12318
|
-
x.s = 1;
|
|
12319
|
-
}
|
|
12320
|
-
return parseDecimal(x, v.toString());
|
|
12321
|
-
}
|
|
12322
|
-
throw Error(invalidArgument + v);
|
|
12323
|
-
}
|
|
12324
|
-
Decimal.prototype = P;
|
|
12325
|
-
Decimal.ROUND_UP = 0;
|
|
12326
|
-
Decimal.ROUND_DOWN = 1;
|
|
12327
|
-
Decimal.ROUND_CEIL = 2;
|
|
12328
|
-
Decimal.ROUND_FLOOR = 3;
|
|
12329
|
-
Decimal.ROUND_HALF_UP = 4;
|
|
12330
|
-
Decimal.ROUND_HALF_DOWN = 5;
|
|
12331
|
-
Decimal.ROUND_HALF_EVEN = 6;
|
|
12332
|
-
Decimal.ROUND_HALF_CEIL = 7;
|
|
12333
|
-
Decimal.ROUND_HALF_FLOOR = 8;
|
|
12334
|
-
Decimal.EUCLID = 9;
|
|
12335
|
-
Decimal.config = Decimal.set = config;
|
|
12336
|
-
Decimal.clone = clone;
|
|
12337
|
-
Decimal.isDecimal = isDecimalInstance;
|
|
12338
|
-
Decimal.abs = abs;
|
|
12339
|
-
Decimal.acos = acos;
|
|
12340
|
-
Decimal.acosh = acosh;
|
|
12341
|
-
Decimal.add = add;
|
|
12342
|
-
Decimal.asin = asin;
|
|
12343
|
-
Decimal.asinh = asinh;
|
|
12344
|
-
Decimal.atan = atan;
|
|
12345
|
-
Decimal.atanh = atanh;
|
|
12346
|
-
Decimal.atan2 = atan2;
|
|
12347
|
-
Decimal.cbrt = cbrt;
|
|
12348
|
-
Decimal.ceil = ceil;
|
|
12349
|
-
Decimal.clamp = clamp;
|
|
12350
|
-
Decimal.cos = cos;
|
|
12351
|
-
Decimal.cosh = cosh;
|
|
12352
|
-
Decimal.div = div;
|
|
12353
|
-
Decimal.exp = exp;
|
|
12354
|
-
Decimal.floor = floor;
|
|
12355
|
-
Decimal.hypot = hypot;
|
|
12356
|
-
Decimal.ln = ln;
|
|
12357
|
-
Decimal.log = log;
|
|
12358
|
-
Decimal.log10 = log10;
|
|
12359
|
-
Decimal.log2 = log2;
|
|
12360
|
-
Decimal.max = max;
|
|
12361
|
-
Decimal.min = min;
|
|
12362
|
-
Decimal.mod = mod;
|
|
12363
|
-
Decimal.mul = mul;
|
|
12364
|
-
Decimal.pow = pow;
|
|
12365
|
-
Decimal.random = random;
|
|
12366
|
-
Decimal.round = round;
|
|
12367
|
-
Decimal.sign = sign;
|
|
12368
|
-
Decimal.sin = sin;
|
|
12369
|
-
Decimal.sinh = sinh;
|
|
12370
|
-
Decimal.sqrt = sqrt;
|
|
12371
|
-
Decimal.sub = sub;
|
|
12372
|
-
Decimal.sum = sum;
|
|
12373
|
-
Decimal.tan = tan;
|
|
12374
|
-
Decimal.tanh = tanh;
|
|
12375
|
-
Decimal.trunc = trunc;
|
|
12376
|
-
if (obj === undefined)
|
|
12377
|
-
obj = {};
|
|
12378
|
-
if (obj) {
|
|
12379
|
-
if (obj.defaults !== true) {
|
|
12380
|
-
ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
|
|
12381
|
-
for (i = 0;i < ps.length; )
|
|
12382
|
-
if (!obj.hasOwnProperty(p = ps[i++]))
|
|
12383
|
-
obj[p] = this[p];
|
|
12384
|
-
}
|
|
12385
|
-
}
|
|
12386
|
-
Decimal.config(obj);
|
|
12387
|
-
return Decimal;
|
|
12388
|
-
}
|
|
12389
|
-
function div(x, y) {
|
|
12390
|
-
return new this(x).div(y);
|
|
12391
|
-
}
|
|
12392
|
-
function exp(x) {
|
|
12393
|
-
return new this(x).exp();
|
|
12394
|
-
}
|
|
12395
|
-
function floor(x) {
|
|
12396
|
-
return finalise(x = new this(x), x.e + 1, 3);
|
|
12397
|
-
}
|
|
12398
|
-
function hypot() {
|
|
12399
|
-
var i, n, t = new this(0);
|
|
12400
|
-
external2 = false;
|
|
12401
|
-
for (i = 0;i < arguments.length; ) {
|
|
12402
|
-
n = new this(arguments[i++]);
|
|
12403
|
-
if (!n.d) {
|
|
12404
|
-
if (n.s) {
|
|
12405
|
-
external2 = true;
|
|
12406
|
-
return new this(1 / 0);
|
|
12407
|
-
}
|
|
12408
|
-
t = n;
|
|
12409
|
-
} else if (t.d) {
|
|
12410
|
-
t = t.plus(n.times(n));
|
|
12411
|
-
}
|
|
12412
|
-
}
|
|
12413
|
-
external2 = true;
|
|
12414
|
-
return t.sqrt();
|
|
12415
|
-
}
|
|
12416
|
-
function isDecimalInstance(obj) {
|
|
12417
|
-
return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
|
|
12418
|
-
}
|
|
12419
|
-
function ln(x) {
|
|
12420
|
-
return new this(x).ln();
|
|
12421
|
-
}
|
|
12422
|
-
function log(x, y) {
|
|
12423
|
-
return new this(x).log(y);
|
|
12424
|
-
}
|
|
12425
|
-
function log2(x) {
|
|
12426
|
-
return new this(x).log(2);
|
|
12427
|
-
}
|
|
12428
|
-
function log10(x) {
|
|
12429
|
-
return new this(x).log(10);
|
|
12430
|
-
}
|
|
12431
|
-
function max() {
|
|
12432
|
-
return maxOrMin(this, arguments, -1);
|
|
12433
|
-
}
|
|
12434
|
-
function min() {
|
|
12435
|
-
return maxOrMin(this, arguments, 1);
|
|
12436
|
-
}
|
|
12437
|
-
function mod(x, y) {
|
|
12438
|
-
return new this(x).mod(y);
|
|
12439
|
-
}
|
|
12440
|
-
function mul(x, y) {
|
|
12441
|
-
return new this(x).mul(y);
|
|
12442
|
-
}
|
|
12443
|
-
function pow(x, y) {
|
|
12444
|
-
return new this(x).pow(y);
|
|
12445
|
-
}
|
|
12446
|
-
function random(sd) {
|
|
12447
|
-
var d, e, k, n, i = 0, r = new this(1), rd = [];
|
|
12448
|
-
if (sd === undefined)
|
|
12449
|
-
sd = this.precision;
|
|
12450
|
-
else
|
|
12451
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
12452
|
-
k = Math.ceil(sd / LOG_BASE);
|
|
12453
|
-
if (!this.crypto) {
|
|
12454
|
-
for (;i < k; )
|
|
12455
|
-
rd[i++] = Math.random() * 1e7 | 0;
|
|
12456
|
-
} else if (crypto.getRandomValues) {
|
|
12457
|
-
d = crypto.getRandomValues(new Uint32Array(k));
|
|
12458
|
-
for (;i < k; ) {
|
|
12459
|
-
n = d[i];
|
|
12460
|
-
if (n >= 4290000000) {
|
|
12461
|
-
d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
|
|
12462
|
-
} else {
|
|
12463
|
-
rd[i++] = n % 1e7;
|
|
12464
|
-
}
|
|
12465
|
-
}
|
|
12466
|
-
} else if (crypto.randomBytes) {
|
|
12467
|
-
d = crypto.randomBytes(k *= 4);
|
|
12468
|
-
for (;i < k; ) {
|
|
12469
|
-
n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
|
|
12470
|
-
if (n >= 2140000000) {
|
|
12471
|
-
crypto.randomBytes(4).copy(d, i);
|
|
12472
|
-
} else {
|
|
12473
|
-
rd.push(n % 1e7);
|
|
12474
|
-
i += 4;
|
|
12475
|
-
}
|
|
12476
|
-
}
|
|
12477
|
-
i = k / 4;
|
|
12478
|
-
} else {
|
|
12479
|
-
throw Error(cryptoUnavailable);
|
|
12480
|
-
}
|
|
12481
|
-
k = rd[--i];
|
|
12482
|
-
sd %= LOG_BASE;
|
|
12483
|
-
if (k && sd) {
|
|
12484
|
-
n = mathpow(10, LOG_BASE - sd);
|
|
12485
|
-
rd[i] = (k / n | 0) * n;
|
|
12486
|
-
}
|
|
12487
|
-
for (;rd[i] === 0; i--)
|
|
12488
|
-
rd.pop();
|
|
12489
|
-
if (i < 0) {
|
|
12490
|
-
e = 0;
|
|
12491
|
-
rd = [0];
|
|
12492
|
-
} else {
|
|
12493
|
-
e = -1;
|
|
12494
|
-
for (;rd[0] === 0; e -= LOG_BASE)
|
|
12495
|
-
rd.shift();
|
|
12496
|
-
for (k = 1, n = rd[0];n >= 10; n /= 10)
|
|
12497
|
-
k++;
|
|
12498
|
-
if (k < LOG_BASE)
|
|
12499
|
-
e -= LOG_BASE - k;
|
|
12500
|
-
}
|
|
12501
|
-
r.e = e;
|
|
12502
|
-
r.d = rd;
|
|
12503
|
-
return r;
|
|
12504
|
-
}
|
|
12505
|
-
function round(x) {
|
|
12506
|
-
return finalise(x = new this(x), x.e + 1, this.rounding);
|
|
12507
|
-
}
|
|
12508
|
-
function sign(x) {
|
|
12509
|
-
x = new this(x);
|
|
12510
|
-
return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
|
|
12511
|
-
}
|
|
12512
|
-
function sin(x) {
|
|
12513
|
-
return new this(x).sin();
|
|
12514
|
-
}
|
|
12515
|
-
function sinh(x) {
|
|
12516
|
-
return new this(x).sinh();
|
|
12517
|
-
}
|
|
12518
|
-
function sqrt(x) {
|
|
12519
|
-
return new this(x).sqrt();
|
|
12520
|
-
}
|
|
12521
|
-
function sub(x, y) {
|
|
12522
|
-
return new this(x).sub(y);
|
|
12523
|
-
}
|
|
12524
|
-
function sum() {
|
|
12525
|
-
var i = 0, args = arguments, x = new this(args[i]);
|
|
12526
|
-
external2 = false;
|
|
12527
|
-
for (;x.s && ++i < args.length; )
|
|
12528
|
-
x = x.plus(args[i]);
|
|
12529
|
-
external2 = true;
|
|
12530
|
-
return finalise(x, this.precision, this.rounding);
|
|
12531
|
-
}
|
|
12532
|
-
function tan(x) {
|
|
12533
|
-
return new this(x).tan();
|
|
12534
|
-
}
|
|
12535
|
-
function tanh(x) {
|
|
12536
|
-
return new this(x).tanh();
|
|
12537
|
-
}
|
|
12538
|
-
function trunc(x) {
|
|
12539
|
-
return finalise(x = new this(x), x.e + 1, 1);
|
|
12540
|
-
}
|
|
12541
|
-
P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
|
|
12542
|
-
P[Symbol.toStringTag] = "Decimal";
|
|
12543
|
-
var Decimal = P.constructor = clone(DEFAULTS);
|
|
12544
|
-
LN10 = new Decimal(LN10);
|
|
12545
|
-
PI = new Decimal(PI);
|
|
12546
|
-
var decimal_default = Decimal;
|
|
12547
|
-
|
|
12548
|
-
// src/common/base/other.ts
|
|
12549
|
-
var delay = (time = 1000) => {
|
|
12550
|
-
return new Promise((resolve) => setTimeout(resolve, time));
|
|
12551
|
-
};
|
|
12552
|
-
var calcJsText = (expr, context) => {
|
|
12553
|
-
const keys = Object.keys(context);
|
|
12554
|
-
const values = keys.map((key2) => context[key2]);
|
|
12555
|
-
return Function(...keys, `return (${expr})`)(...values);
|
|
12556
|
-
};
|
|
12557
|
-
var optionsToEnum = (options, text, key2) => {
|
|
12558
|
-
return options.reduce((acc, cur) => {
|
|
12559
|
-
acc[cur[key2]] = {
|
|
12560
|
-
text: cur[text]
|
|
12561
|
-
};
|
|
12562
|
-
return acc;
|
|
12563
|
-
}, {});
|
|
12564
|
-
};
|
|
12565
|
-
var performDecimalOperation = (num1, num2, operator) => {
|
|
12566
|
-
if (num1 === undefined || num2 === undefined || !operator) {
|
|
12567
|
-
return;
|
|
12568
|
-
}
|
|
12569
|
-
const decimalNum1 = new decimal_default(Number(num1));
|
|
12570
|
-
const decimalNum2 = new decimal_default(Number(num2));
|
|
12571
|
-
switch (operator) {
|
|
12572
|
-
case "+":
|
|
12573
|
-
return decimalNum1.plus(decimalNum2).toNumber();
|
|
12574
|
-
case "-":
|
|
12575
|
-
return decimalNum1.minus(decimalNum2).toNumber();
|
|
12576
|
-
case "*":
|
|
12577
|
-
return decimalNum1.times(decimalNum2).toNumber();
|
|
12578
|
-
case "/":
|
|
12579
|
-
if (num2 !== 0) {
|
|
12580
|
-
return decimalNum1.dividedBy(decimalNum2).toNumber();
|
|
12581
|
-
} else {
|
|
12582
|
-
console.error("Division by zero is not allowed.");
|
|
12583
|
-
return NaN;
|
|
12584
|
-
}
|
|
12585
|
-
default:
|
|
12586
|
-
console.error("Invalid operator:", operator);
|
|
12587
|
-
return NaN;
|
|
12588
|
-
}
|
|
12589
|
-
};
|
|
12590
|
-
var printConsoleLog = (type, path2, params, response) => {
|
|
12591
|
-
const styles = {
|
|
12592
|
-
header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
|
|
12593
|
-
value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
|
|
12594
|
-
separator: "color: #409EFF; margin: 0 4px;"
|
|
12595
|
-
};
|
|
12596
|
-
console.groupCollapsed(`666 %c${type}%c${path2}`, styles.header, styles.value);
|
|
12597
|
-
if (params) {
|
|
12598
|
-
console.table(params);
|
|
12599
|
-
}
|
|
12600
|
-
if (response) {
|
|
12601
|
-
console.table(response);
|
|
12602
|
-
}
|
|
12603
|
-
console.groupEnd();
|
|
12604
|
-
};
|
|
12605
|
-
|
|
12606
|
-
// src/common/base/array.ts
|
|
12607
|
-
var shuffleArray = (array) => {
|
|
12608
|
-
const shuffledArray = [...array];
|
|
12609
|
-
for (let i = shuffledArray.length - 1;i > 0; i--) {
|
|
12610
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
12611
|
-
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
|
|
12612
|
-
}
|
|
12613
|
-
return shuffledArray;
|
|
12614
|
-
};
|
|
12615
|
-
var removeSimilarDuplicates = (arr, threshold, isLog) => {
|
|
12616
|
-
const uniqueArray = [];
|
|
12617
|
-
const similarPairs = [];
|
|
12618
|
-
for (const str of arr) {
|
|
12619
|
-
const isSimilar = uniqueArray.some((uniqueStr) => {
|
|
12620
|
-
const distance = levenshteinDistance(str, uniqueStr);
|
|
12621
|
-
if (distance <= threshold) {
|
|
12622
|
-
similarPairs.push([str, uniqueStr]);
|
|
12623
|
-
return true;
|
|
12624
|
-
}
|
|
12625
|
-
return false;
|
|
12626
|
-
});
|
|
12627
|
-
if (!isSimilar) {
|
|
12628
|
-
uniqueArray.push(str);
|
|
12629
|
-
}
|
|
12630
|
-
}
|
|
12631
|
-
if (isLog) {
|
|
12632
|
-
if (similarPairs.length > 0) {
|
|
12633
|
-
similarPairs.forEach((pair) => {
|
|
12634
|
-
console.log(pair[0]);
|
|
12635
|
-
console.log(pair[1]);
|
|
12636
|
-
console.log();
|
|
12637
|
-
});
|
|
12638
|
-
} else {
|
|
12639
|
-
console.log("没有找到类似的字符串");
|
|
12640
|
-
}
|
|
12641
|
-
}
|
|
12642
|
-
return uniqueArray;
|
|
12643
|
-
};
|
|
12644
|
-
var getTotal = (arr, key2) => {
|
|
12645
|
-
if (!Array.isArray(arr) || !key2) {
|
|
12646
|
-
return 0;
|
|
12647
|
-
}
|
|
12648
|
-
return arr.reduce((total, item) => {
|
|
12649
|
-
const itemValue = Number(item[key2]);
|
|
12650
|
-
if (!isNaN(itemValue)) {
|
|
12651
|
-
return performDecimalOperation(total, itemValue, "+");
|
|
12652
|
-
}
|
|
12653
|
-
return total;
|
|
12654
|
-
}, 0);
|
|
12655
|
-
};
|
|
12656
|
-
|
|
12657
|
-
// src/common/base/number.ts
|
|
12658
|
-
var getRandomNum = (min2, max2) => {
|
|
12659
|
-
return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
|
|
12660
|
-
};
|
|
12661
|
-
var limitDecimals = (v, num = 2, isForce) => {
|
|
12662
|
-
let value = parseFloat(v);
|
|
12663
|
-
if (isNaN(value)) {
|
|
12664
|
-
if (isForce) {
|
|
12665
|
-
value = 0;
|
|
12666
|
-
} else {
|
|
12667
|
-
return "";
|
|
12668
|
-
}
|
|
12669
|
-
}
|
|
12670
|
-
return value.toFixed(num).toString();
|
|
12671
|
-
};
|
|
12672
|
-
var getFileSize = (size) => {
|
|
12673
|
-
let d = "G";
|
|
12674
|
-
let s = size / 1024 / 1024 / 1024;
|
|
12675
|
-
if (s < 1) {
|
|
12676
|
-
d = "M";
|
|
12677
|
-
s *= 1024;
|
|
12678
|
-
}
|
|
12679
|
-
return `${(s.toFixed(1) / 1).toString()}${d}`;
|
|
12680
|
-
};
|
|
12681
|
-
var isValidNumber = (value) => {
|
|
12682
|
-
if (typeof value !== "number") {
|
|
12683
|
-
return false;
|
|
12684
|
-
}
|
|
12685
|
-
if (isNaN(value)) {
|
|
12686
|
-
return false;
|
|
12687
|
-
}
|
|
12688
|
-
if (value === Infinity || value === -Infinity) {
|
|
12689
|
-
return false;
|
|
12690
|
-
}
|
|
12691
|
-
return true;
|
|
12692
|
-
};
|
|
12693
|
-
var numberWithCommas = (x) => {
|
|
12694
|
-
if (x === undefined || x === null) {
|
|
12695
|
-
return "";
|
|
12696
|
-
}
|
|
12697
|
-
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
12698
|
-
};
|
|
12699
|
-
|
|
12700
|
-
// src/common/base/object.ts
|
|
12701
|
-
var findItem = (list, attr, value) => {
|
|
12702
|
-
return list.find((item) => value === undefined ? item[attr] : item[attr] === value);
|
|
12703
|
-
};
|
|
12704
|
-
var filterParams = (params, deep = false) => {
|
|
12705
|
-
const clean = (value) => {
|
|
12706
|
-
if (value === undefined || value === null) {
|
|
12707
|
-
return;
|
|
12708
|
-
}
|
|
12709
|
-
if (!deep) {
|
|
12710
|
-
return value;
|
|
12711
|
-
}
|
|
12712
|
-
if (Array.isArray(value)) {
|
|
12713
|
-
return value.map((v) => clean(v)).filter((v) => v !== undefined);
|
|
12714
|
-
}
|
|
12715
|
-
if (typeof value === "object") {
|
|
12716
|
-
return Object.entries(value).reduce((acc, [k, v]) => {
|
|
12717
|
-
const cleaned = clean(v);
|
|
12718
|
-
if (cleaned !== undefined)
|
|
12719
|
-
acc[k] = cleaned;
|
|
12720
|
-
return acc;
|
|
12721
|
-
}, {});
|
|
12722
|
-
}
|
|
12723
|
-
return value;
|
|
12724
|
-
};
|
|
12725
|
-
return clean(params);
|
|
12726
|
-
};
|
|
12727
|
-
var watch = {
|
|
12728
|
-
observe(obj, key2, watchFun) {
|
|
12729
|
-
const val = obj[key2];
|
|
12730
|
-
Object.defineProperty(obj, key2, {
|
|
12731
|
-
configurable: true,
|
|
12732
|
-
enumerable: true,
|
|
12733
|
-
set(value) {
|
|
12734
|
-
obj[key2] = value;
|
|
12735
|
-
watchFun(value, val);
|
|
12736
|
-
},
|
|
12737
|
-
get() {
|
|
12738
|
-
return val;
|
|
12739
|
-
}
|
|
12740
|
-
});
|
|
12741
|
-
},
|
|
12742
|
-
setWatcher(data = {}, watch2 = {}) {
|
|
12743
|
-
Object.keys(watch2).forEach((v) => {
|
|
12744
|
-
this.observe(data, v, watch2[v]);
|
|
12745
|
-
});
|
|
12746
|
-
}
|
|
12747
|
-
};
|
|
12748
|
-
|
|
12749
|
-
// src/common/base/promise.ts
|
|
12750
|
-
var executePromise = async (promise) => {
|
|
12751
|
-
const start = Date.now();
|
|
12752
|
-
const result = await promise;
|
|
12753
|
-
const time = Date.now() - start;
|
|
12754
|
-
return {
|
|
12755
|
-
result,
|
|
12756
|
-
time
|
|
12757
|
-
};
|
|
12758
|
-
};
|
|
12759
|
-
var retryPromise = async (promiseFn, retryInterval = 1000, retryCount = 3) => {
|
|
12760
|
-
try {
|
|
12761
|
-
return await promiseFn();
|
|
12762
|
-
} catch (error) {
|
|
12763
|
-
if (retryCount <= 0) {
|
|
12764
|
-
throw error;
|
|
12765
|
-
}
|
|
12766
|
-
await new Promise((resolve) => setTimeout(resolve, retryInterval));
|
|
12767
|
-
return retryPromise(promiseFn, retryCount - 1, retryInterval);
|
|
12768
|
-
}
|
|
12769
|
-
};
|
|
12770
|
-
// src/common/enum.ts
|
|
12771
|
-
class EnumItem {
|
|
12772
|
-
label;
|
|
12773
|
-
value;
|
|
12774
|
-
extra;
|
|
12775
|
-
constructor(config2) {
|
|
12776
|
-
this.value = config2.value;
|
|
12777
|
-
this.label = config2.label;
|
|
12778
|
-
this.extra = config2.extra;
|
|
12779
|
-
}
|
|
12780
|
-
}
|
|
12781
|
-
var Enum = {
|
|
12782
|
-
create: (members) => {
|
|
12783
|
-
const usedValues = new Set;
|
|
12784
|
-
const enumObj = {};
|
|
12785
|
-
const map = new Map;
|
|
12786
|
-
const options = [];
|
|
12787
|
-
const extras = new Map;
|
|
12788
|
-
const labels = new Map;
|
|
12789
|
-
const enums = {};
|
|
12790
|
-
for (const key2 in members) {
|
|
12791
|
-
const member = members[key2];
|
|
12792
|
-
if (!member)
|
|
12793
|
-
continue;
|
|
12794
|
-
if (usedValues.has(member.value)) {
|
|
12795
|
-
throw new Error(`Duplicate enum value detected: ${member.value}`);
|
|
12796
|
-
}
|
|
12797
|
-
usedValues.add(member.value);
|
|
12798
|
-
const item = new EnumItem(member);
|
|
12799
|
-
enumObj[key2] = item;
|
|
12800
|
-
map.set(item.value, item);
|
|
12801
|
-
labels.set(item.value, item.label);
|
|
12802
|
-
options.push(item);
|
|
12803
|
-
enums[item.value] = { text: item.label, status: item.extra?.status };
|
|
12804
|
-
if (member.extra !== undefined) {
|
|
12805
|
-
extras.set(item.value, { ...member.extra });
|
|
12806
|
-
}
|
|
12807
|
-
}
|
|
12808
|
-
enumObj.map = map;
|
|
12809
|
-
enumObj.options = options;
|
|
12810
|
-
enumObj.extras = extras;
|
|
12811
|
-
enumObj.source = members;
|
|
12812
|
-
enumObj.labels = labels;
|
|
12813
|
-
enumObj.enums = enums;
|
|
12814
|
-
return enumObj;
|
|
12815
|
-
}
|
|
12816
|
-
};
|
|
12817
|
-
// src/common/image.ts
|
|
12818
|
-
import axios5 from "axios";
|
|
12819
|
-
async function imageToBase64(url2) {
|
|
12820
|
-
try {
|
|
12821
|
-
const response = await axios5.get(url2, {
|
|
12822
|
-
responseType: "arraybuffer"
|
|
12823
|
-
});
|
|
12824
|
-
const base64String = Buffer.from(response.data).toString("base64");
|
|
12825
|
-
return `data:image/*;base64,${base64String}`;
|
|
12826
|
-
} catch (error) {
|
|
12827
|
-
console.error("Failed to fetch the image:", error);
|
|
12828
|
-
throw error;
|
|
12829
|
-
}
|
|
12830
|
-
}
|
|
12831
|
-
// src/common/dayjs.ts
|
|
12832
|
-
import dayjs from "dayjs";
|
|
12833
|
-
import isBetween from "dayjs/plugin/isBetween";
|
|
12834
|
-
import weekday from "dayjs/plugin/weekday";
|
|
12835
|
-
import localeData from "dayjs/plugin/localeData";
|
|
12836
|
-
import isoWeek from "dayjs/plugin/isoWeek";
|
|
12837
|
-
import updateLocale from "dayjs/plugin/updateLocale";
|
|
12838
|
-
import timezone from "dayjs/plugin/timezone";
|
|
12839
|
-
import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
|
|
12840
|
-
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
|
|
12841
|
-
import utc from "dayjs/plugin/utc";
|
|
12842
|
-
import"dayjs/locale/zh-cn";
|
|
12843
|
-
import { Dayjs } from "dayjs";
|
|
12844
|
-
dayjs.extend(utc);
|
|
12845
|
-
dayjs.extend(isBetween);
|
|
12846
|
-
dayjs.extend(weekday);
|
|
12847
|
-
dayjs.extend(localeData);
|
|
12848
|
-
dayjs.extend(isoWeek);
|
|
12849
|
-
dayjs.extend(updateLocale);
|
|
12850
|
-
dayjs.extend(timezone);
|
|
12851
|
-
dayjs.extend(isSameOrAfter);
|
|
12852
|
-
dayjs.extend(isSameOrBefore);
|
|
12853
|
-
var Timezone;
|
|
12854
|
-
((Timezone2) => {
|
|
12855
|
-
Timezone2["AsiaShanghai"] = "Asia/Shanghai";
|
|
12856
|
-
Timezone2["AsiaTokyo"] = "Asia/Tokyo";
|
|
12857
|
-
Timezone2["AmericaNewYork"] = "America/New_York";
|
|
12858
|
-
Timezone2["EuropeLondon"] = "Europe/London";
|
|
12859
|
-
Timezone2["EuropeBerlin"] = "Europe/Berlin";
|
|
12860
|
-
})(Timezone ||= {});
|
|
12861
|
-
var initChinaDayjs = () => {
|
|
12862
|
-
dayjs.locale("zh-cn");
|
|
12863
|
-
dayjs.tz.setDefault("Asia/Shanghai" /* AsiaShanghai */);
|
|
12864
|
-
dayjs.updateLocale("zh-cn", {
|
|
12865
|
-
weekStart: 1
|
|
12866
|
-
});
|
|
12867
|
-
return dayjs;
|
|
12868
|
-
};
|
|
12869
|
-
var chinaDayjs = initChinaDayjs();
|
|
12870
|
-
var dayjs_default = dayjs;
|
|
12871
|
-
// src/node/mail.ts
|
|
12872
|
-
import nodemailer from "nodemailer";
|
|
12873
|
-
var authMap = {
|
|
12874
|
-
163: {
|
|
12875
|
-
user: "15835196981@163.com",
|
|
12876
|
-
pass: "KPTVCFBMRXJVTCGW"
|
|
12877
|
-
},
|
|
12878
|
-
gmail: {
|
|
12879
|
-
user: "wangzhenzhen2023@gmail.com",
|
|
12880
|
-
pass: "lkxtorbpdyrjjxjq"
|
|
12881
|
-
}
|
|
12882
|
-
};
|
|
12883
|
-
var transporter = nodemailer.createTransport({
|
|
12884
|
-
host: "smtp.gmail.com",
|
|
12885
|
-
port: 465,
|
|
12886
|
-
secure: true,
|
|
12887
|
-
auth: authMap.gmail
|
|
12888
|
-
});
|
|
12889
|
-
var sendMail = (config2) => {
|
|
12890
|
-
return transporter.sendMail({
|
|
12891
|
-
from: authMap.gmail.user,
|
|
12892
|
-
...config2
|
|
12893
|
-
});
|
|
12894
|
-
};
|
|
12895
|
-
// src/node/file.ts
|
|
12896
|
-
import fs from "fs-extra";
|
|
12897
|
-
import axios6 from "axios";
|
|
12898
|
-
import url2 from "url";
|
|
12899
|
-
import * as path2 from "path";
|
|
12900
|
-
var replaceContentInFile = async (filePath, targetContent, replacement) => {
|
|
9801
|
+
// src/node/file.ts
|
|
9802
|
+
import fs from "fs-extra";
|
|
9803
|
+
import axios4 from "axios";
|
|
9804
|
+
import url2 from "url";
|
|
9805
|
+
import * as path2 from "path";
|
|
9806
|
+
var replaceContentInFile = async (filePath, targetContent, replacement) => {
|
|
12901
9807
|
try {
|
|
12902
9808
|
const data = await fs.readFile(filePath, "utf8");
|
|
12903
9809
|
if (replacement && data.includes(replacement)) {
|
|
@@ -12926,7 +9832,7 @@ var downloadFile = async (httpUrl, outputPath) => {
|
|
|
12926
9832
|
}
|
|
12927
9833
|
outputPath = ".tmp/" + decodeURIComponent(fileName);
|
|
12928
9834
|
}
|
|
12929
|
-
const response = await
|
|
9835
|
+
const response = await axios4({
|
|
12930
9836
|
url: httpUrl,
|
|
12931
9837
|
method: "get",
|
|
12932
9838
|
responseType: "stream"
|
|
@@ -12945,7 +9851,7 @@ var downloadFile = async (httpUrl, outputPath) => {
|
|
|
12945
9851
|
};
|
|
12946
9852
|
// src/node/oss.ts
|
|
12947
9853
|
import OSS from "ali-oss";
|
|
12948
|
-
import
|
|
9854
|
+
import axios5 from "axios";
|
|
12949
9855
|
import fs2 from "fs-extra";
|
|
12950
9856
|
import * as path3 from "path";
|
|
12951
9857
|
var oss = new OSS({
|
|
@@ -12960,7 +9866,7 @@ async function uploadFile(file, filename) {
|
|
|
12960
9866
|
if (typeof file === "string") {
|
|
12961
9867
|
if (/^https?:\/\//.test(file)) {
|
|
12962
9868
|
try {
|
|
12963
|
-
const response = await
|
|
9869
|
+
const response = await axios5.get(file, { responseType: "arraybuffer" });
|
|
12964
9870
|
buffer = Buffer.from(response.data);
|
|
12965
9871
|
} catch (error) {
|
|
12966
9872
|
throw new Error(`无法从 URL 下载文件: ${error}`);
|
|
@@ -13026,7 +9932,6 @@ var export__ = import_lodash.default;
|
|
|
13026
9932
|
|
|
13027
9933
|
export {
|
|
13028
9934
|
exports_external as z,
|
|
13029
|
-
watch,
|
|
13030
9935
|
voidType as void,
|
|
13031
9936
|
util,
|
|
13032
9937
|
uploadFile,
|
|
@@ -13035,36 +9940,26 @@ export {
|
|
|
13035
9940
|
undefinedType as undefined,
|
|
13036
9941
|
tupleType as tuple,
|
|
13037
9942
|
effectsType as transformer,
|
|
13038
|
-
toString,
|
|
13039
9943
|
symbolType as symbol,
|
|
13040
9944
|
stringType as string,
|
|
13041
9945
|
strictObjectType as strictObject,
|
|
13042
|
-
shuffleArray,
|
|
13043
9946
|
setErrorMap,
|
|
9947
|
+
setCookie,
|
|
13044
9948
|
setType as set,
|
|
13045
9949
|
sendMail,
|
|
13046
9950
|
schedule,
|
|
13047
|
-
retryPromise,
|
|
13048
9951
|
replaceContentInFile,
|
|
13049
|
-
replaceByVariables,
|
|
13050
|
-
replaceByRules,
|
|
13051
|
-
replaceAll,
|
|
13052
|
-
removeSimilarDuplicates,
|
|
13053
9952
|
recordType as record,
|
|
13054
9953
|
quotelessJson,
|
|
13055
9954
|
promiseType as promise,
|
|
13056
|
-
printConsoleLog,
|
|
13057
9955
|
preprocessType as preprocess,
|
|
13058
9956
|
pipelineType as pipeline,
|
|
13059
|
-
performDecimalOperation,
|
|
13060
9957
|
ostring,
|
|
13061
|
-
optionsToEnum,
|
|
13062
9958
|
optionalType as optional,
|
|
13063
9959
|
onumber,
|
|
13064
9960
|
oboolean,
|
|
13065
9961
|
objectUtil,
|
|
13066
9962
|
objectType as object,
|
|
13067
|
-
numberWithCommas,
|
|
13068
9963
|
numberType as number,
|
|
13069
9964
|
nullableType as nullable,
|
|
13070
9965
|
nullType as null,
|
|
@@ -13074,16 +9969,10 @@ export {
|
|
|
13074
9969
|
mapType as map,
|
|
13075
9970
|
makeIssue,
|
|
13076
9971
|
literalType as literal,
|
|
13077
|
-
limitDecimals,
|
|
13078
|
-
levenshteinDistance,
|
|
13079
9972
|
lazyType as lazy,
|
|
13080
9973
|
late,
|
|
13081
|
-
exports_keling as keling,
|
|
13082
|
-
jsonParse,
|
|
13083
9974
|
default5 as json5,
|
|
13084
|
-
isValidNumber,
|
|
13085
9975
|
isValid,
|
|
13086
|
-
isJson,
|
|
13087
9976
|
isDirty,
|
|
13088
9977
|
isAsync,
|
|
13089
9978
|
isAborted,
|
|
@@ -13092,33 +9981,15 @@ export {
|
|
|
13092
9981
|
instanceOfType as instanceof,
|
|
13093
9982
|
initChinaDayjs,
|
|
13094
9983
|
imageToBase64,
|
|
13095
|
-
|
|
13096
|
-
getTotal,
|
|
13097
|
-
getStrLength,
|
|
13098
|
-
getSliceStr,
|
|
13099
|
-
getRandomString,
|
|
13100
|
-
getRandomNum,
|
|
13101
|
-
getRandomColor,
|
|
13102
|
-
getProxyUrl,
|
|
9984
|
+
getVideoStatus,
|
|
13103
9985
|
getParsedType,
|
|
13104
|
-
getLength,
|
|
13105
|
-
getFileSize,
|
|
13106
9986
|
getErrorMap,
|
|
13107
|
-
|
|
13108
|
-
getChineseByStr,
|
|
13109
|
-
getChinese,
|
|
13110
|
-
generateUniqueFileName,
|
|
13111
|
-
generateAlphabetArray,
|
|
9987
|
+
generateVideo,
|
|
13112
9988
|
functionType as function,
|
|
13113
|
-
findItem,
|
|
13114
|
-
filterParams,
|
|
13115
|
-
executePromise,
|
|
13116
9989
|
enumType as enum,
|
|
13117
9990
|
effectsType as effect,
|
|
13118
9991
|
downloadFile,
|
|
13119
|
-
exports_doubao2 as doubao,
|
|
13120
9992
|
discriminatedUnionType as discriminatedUnion,
|
|
13121
|
-
delay,
|
|
13122
9993
|
en_default as defaultErrorMap,
|
|
13123
9994
|
dayjs_default as dayjs,
|
|
13124
9995
|
datetimeRegex,
|
|
@@ -13128,14 +9999,12 @@ export {
|
|
|
13128
9999
|
coerce,
|
|
13129
10000
|
chinaDayjs,
|
|
13130
10001
|
cheerio,
|
|
13131
|
-
|
|
10002
|
+
chat,
|
|
13132
10003
|
booleanType as boolean,
|
|
13133
10004
|
bigIntType as bigint,
|
|
13134
10005
|
default4 as axios,
|
|
13135
10006
|
arrayType as array,
|
|
13136
10007
|
anyType as any,
|
|
13137
|
-
amount,
|
|
13138
|
-
exports_302 as ai302,
|
|
13139
10008
|
addIssueToContext,
|
|
13140
10009
|
export__ as _,
|
|
13141
10010
|
ZodVoid,
|