@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/web.cjs.js
CHANGED
|
@@ -6621,7 +6621,7 @@ var require_lodash = __commonJS((exports2, module2) => {
|
|
|
6621
6621
|
var tag = baseGetTag(value);
|
|
6622
6622
|
return tag == errorTag || tag == domExcTag || typeof value.message == "string" && typeof value.name == "string" && !isPlainObject(value);
|
|
6623
6623
|
}
|
|
6624
|
-
function
|
|
6624
|
+
function isFinite(value) {
|
|
6625
6625
|
return typeof value == "number" && nativeIsFinite(value);
|
|
6626
6626
|
}
|
|
6627
6627
|
function isFunction(value) {
|
|
@@ -7735,7 +7735,7 @@ __p += '`;
|
|
|
7735
7735
|
lodash.isEqual = isEqual;
|
|
7736
7736
|
lodash.isEqualWith = isEqualWith;
|
|
7737
7737
|
lodash.isError = isError;
|
|
7738
|
-
lodash.isFinite =
|
|
7738
|
+
lodash.isFinite = isFinite;
|
|
7739
7739
|
lodash.isFunction = isFunction;
|
|
7740
7740
|
lodash.isInteger = isInteger;
|
|
7741
7741
|
lodash.isLength = isLength;
|
|
@@ -10292,7 +10292,6 @@ var require_zh_cn = __commonJS((exports2, module2) => {
|
|
|
10292
10292
|
var exports_web = {};
|
|
10293
10293
|
__export(exports_web, {
|
|
10294
10294
|
z: () => exports_external,
|
|
10295
|
-
watch: () => watch,
|
|
10296
10295
|
void: () => voidType,
|
|
10297
10296
|
util: () => util,
|
|
10298
10297
|
urlGetPath: () => urlGetPath,
|
|
@@ -10302,37 +10301,27 @@ __export(exports_web, {
|
|
|
10302
10301
|
undefined: () => undefinedType,
|
|
10303
10302
|
tuple: () => tupleType,
|
|
10304
10303
|
transformer: () => effectsType,
|
|
10305
|
-
toString: () => toString3,
|
|
10306
10304
|
symbol: () => symbolType,
|
|
10307
10305
|
string: () => stringType,
|
|
10308
10306
|
strictObject: () => strictObjectType,
|
|
10309
|
-
shuffleArray: () => shuffleArray,
|
|
10310
10307
|
setUrlParams: () => setUrlParams,
|
|
10311
10308
|
setErrorMap: () => setErrorMap,
|
|
10309
|
+
setCookie: () => setCookie,
|
|
10312
10310
|
set: () => setType,
|
|
10313
10311
|
scrollIntoView: () => scrollIntoView,
|
|
10314
|
-
retryPromise: () => retryPromise,
|
|
10315
|
-
replaceByVariables: () => replaceByVariables,
|
|
10316
|
-
replaceByRules: () => replaceByRules,
|
|
10317
|
-
replaceAll: () => replaceAll,
|
|
10318
|
-
removeSimilarDuplicates: () => removeSimilarDuplicates,
|
|
10319
10312
|
record: () => recordType,
|
|
10320
10313
|
readClipboard: () => readClipboard,
|
|
10321
10314
|
quotelessJson: () => quotelessJson,
|
|
10322
10315
|
promise: () => promiseType,
|
|
10323
|
-
printConsoleLog: () => printConsoleLog,
|
|
10324
10316
|
preprocess: () => preprocessType,
|
|
10325
10317
|
pipeline: () => pipelineType,
|
|
10326
|
-
performDecimalOperation: () => performDecimalOperation,
|
|
10327
10318
|
params2Url: () => params2Url,
|
|
10328
10319
|
ostring: () => ostring,
|
|
10329
|
-
optionsToEnum: () => optionsToEnum,
|
|
10330
10320
|
optional: () => optionalType,
|
|
10331
10321
|
onumber: () => onumber,
|
|
10332
10322
|
oboolean: () => oboolean,
|
|
10333
10323
|
objectUtil: () => objectUtil,
|
|
10334
10324
|
object: () => objectType,
|
|
10335
|
-
numberWithCommas: () => numberWithCommas,
|
|
10336
10325
|
number: () => numberType,
|
|
10337
10326
|
nullable: () => nullableType,
|
|
10338
10327
|
null: () => nullType,
|
|
@@ -10344,16 +10333,10 @@ __export(exports_web, {
|
|
|
10344
10333
|
makeIssue: () => makeIssue,
|
|
10345
10334
|
localforage: () => import_localforage.default,
|
|
10346
10335
|
literal: () => literalType,
|
|
10347
|
-
limitDecimals: () => limitDecimals,
|
|
10348
|
-
levenshteinDistance: () => levenshteinDistance,
|
|
10349
10336
|
lazy: () => lazyType,
|
|
10350
10337
|
late: () => late,
|
|
10351
|
-
keling: () => exports_keling,
|
|
10352
|
-
jsonParse: () => jsonParse,
|
|
10353
10338
|
json5: () => import_json52.default,
|
|
10354
|
-
isValidNumber: () => isValidNumber,
|
|
10355
10339
|
isValid: () => isValid,
|
|
10356
|
-
isJson: () => isJson,
|
|
10357
10340
|
isElementInViewport: () => isElementInViewport,
|
|
10358
10341
|
isDirty: () => isDirty,
|
|
10359
10342
|
isAsync: () => isAsync,
|
|
@@ -10363,35 +10346,17 @@ __export(exports_web, {
|
|
|
10363
10346
|
initChinaDayjs: () => initChinaDayjs,
|
|
10364
10347
|
imageToBase64: () => imageToBase64,
|
|
10365
10348
|
hexToRgba: () => hexToRgba2,
|
|
10366
|
-
|
|
10367
|
-
getTotal: () => getTotal,
|
|
10368
|
-
getStrLength: () => getStrLength,
|
|
10369
|
-
getSliceStr: () => getSliceStr,
|
|
10370
|
-
getRandomString: () => getRandomString,
|
|
10371
|
-
getRandomNum: () => getRandomNum,
|
|
10372
|
-
getRandomColor: () => getRandomColor,
|
|
10373
|
-
getProxyUrl: () => getProxyUrl,
|
|
10349
|
+
getVideoStatus: () => getVideoStatus,
|
|
10374
10350
|
getParsedType: () => getParsedType,
|
|
10375
|
-
getLength: () => getLength,
|
|
10376
|
-
getFileSize: () => getFileSize,
|
|
10377
10351
|
getErrorMap: () => getErrorMap,
|
|
10378
10352
|
getElement: () => getElement,
|
|
10379
|
-
|
|
10380
|
-
getChineseByStr: () => getChineseByStr,
|
|
10381
|
-
getChinese: () => getChinese,
|
|
10382
|
-
generateUniqueFileName: () => generateUniqueFileName,
|
|
10383
|
-
generateAlphabetArray: () => generateAlphabetArray,
|
|
10353
|
+
generateVideo: () => generateVideo,
|
|
10384
10354
|
function: () => functionType,
|
|
10385
10355
|
flashBorder: () => flashBorder,
|
|
10386
10356
|
flashBackground: () => flashBackground,
|
|
10387
|
-
findItem: () => findItem,
|
|
10388
|
-
filterParams: () => filterParams,
|
|
10389
|
-
executePromise: () => executePromise,
|
|
10390
10357
|
enum: () => enumType,
|
|
10391
10358
|
effect: () => effectsType,
|
|
10392
|
-
doubao: () => exports_doubao2,
|
|
10393
10359
|
discriminatedUnion: () => discriminatedUnionType,
|
|
10394
|
-
delay: () => delay,
|
|
10395
10360
|
defaultErrorMap: () => en_default,
|
|
10396
10361
|
dayjs: () => dayjs_default,
|
|
10397
10362
|
datetimeRegex: () => datetimeRegex,
|
|
@@ -10402,15 +10367,13 @@ __export(exports_web, {
|
|
|
10402
10367
|
coerce: () => coerce,
|
|
10403
10368
|
classnames: () => import_classnames.default,
|
|
10404
10369
|
chinaDayjs: () => chinaDayjs,
|
|
10405
|
-
|
|
10370
|
+
chat: () => chat,
|
|
10406
10371
|
boolean: () => booleanType,
|
|
10407
10372
|
bigint: () => bigIntType,
|
|
10408
10373
|
axios: () => axios_default,
|
|
10409
10374
|
array: () => arrayType,
|
|
10410
10375
|
any: () => anyType,
|
|
10411
10376
|
anime: () => anime_es_default,
|
|
10412
|
-
amount: () => amount,
|
|
10413
|
-
ai302: () => exports_302,
|
|
10414
10377
|
addIssueToContext: () => addIssueToContext,
|
|
10415
10378
|
_: () => import_lodash2.default,
|
|
10416
10379
|
ZodVoid: () => ZodVoid,
|
|
@@ -13600,7 +13563,7 @@ var globalFetchAPI = (({ Request, Response }) => ({
|
|
|
13600
13563
|
}))(utils_default.global);
|
|
13601
13564
|
var {
|
|
13602
13565
|
ReadableStream: ReadableStream2,
|
|
13603
|
-
TextEncoder
|
|
13566
|
+
TextEncoder
|
|
13604
13567
|
} = utils_default.global;
|
|
13605
13568
|
var test = (fn, ...args) => {
|
|
13606
13569
|
try {
|
|
@@ -13621,7 +13584,7 @@ var factory = (env) => {
|
|
|
13621
13584
|
return false;
|
|
13622
13585
|
}
|
|
13623
13586
|
const isReadableStreamSupported = isFetchSupported && isFunction2(ReadableStream2);
|
|
13624
|
-
const encodeText = isFetchSupported && (typeof
|
|
13587
|
+
const encodeText = isFetchSupported && (typeof TextEncoder === "function" ? ((encoder) => (str) => encoder.encode(str))(new TextEncoder) : async (str) => new Uint8Array(await new Request(str).arrayBuffer()));
|
|
13625
13588
|
const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
|
|
13626
13589
|
let duplexAccessed = false;
|
|
13627
13590
|
const hasContentType = new Request(platform_default.origin, {
|
|
@@ -18270,14 +18233,6 @@ var coerce = {
|
|
|
18270
18233
|
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
18271
18234
|
};
|
|
18272
18235
|
var NEVER = INVALID;
|
|
18273
|
-
// src/common/ai/302/index.ts
|
|
18274
|
-
var exports_302 = {};
|
|
18275
|
-
__export(exports_302, {
|
|
18276
|
-
image: () => exports_image,
|
|
18277
|
-
chat: () => chat,
|
|
18278
|
-
audio: () => exports_audio
|
|
18279
|
-
});
|
|
18280
|
-
|
|
18281
18236
|
// src/common/ai/302/axios.ts
|
|
18282
18237
|
var key = process.env.AI_302_KEY || process.env.NEXT_PUBLIC_AI_302_KEY;
|
|
18283
18238
|
var axios2 = axios_default.create({
|
|
@@ -18300,7 +18255,7 @@ var chat = async (message, model = "gpt-4.1", isParse = true) => {
|
|
|
18300
18255
|
message
|
|
18301
18256
|
}
|
|
18302
18257
|
});
|
|
18303
|
-
console.log(666,
|
|
18258
|
+
console.log(666, typeof data, data);
|
|
18304
18259
|
const output = typeof data === "string" ? import_json5.default.parse(data)?.output : data?.output;
|
|
18305
18260
|
if (isParse) {
|
|
18306
18261
|
const match = /```(json)?(.*)```/s.exec(output);
|
|
@@ -18312,414 +18267,9 @@ var chat = async (message, model = "gpt-4.1", isParse = true) => {
|
|
|
18312
18267
|
}
|
|
18313
18268
|
return output;
|
|
18314
18269
|
} catch (error) {
|
|
18315
|
-
|
|
18316
|
-
const message2 = responseData?.error?.message_cn || responseData?.error?.message || responseData?.message || error?.response?.statusText || error?.message || "未知原因";
|
|
18317
|
-
throw new Error(message2);
|
|
18318
|
-
}
|
|
18319
|
-
};
|
|
18320
|
-
// src/common/ai/302/audio/index.ts
|
|
18321
|
-
var exports_audio = {};
|
|
18322
|
-
__export(exports_audio, {
|
|
18323
|
-
tts: () => exports_tts,
|
|
18324
|
-
doubao: () => exports_doubao
|
|
18325
|
-
});
|
|
18326
|
-
|
|
18327
|
-
// src/common/ai/302/audio/tts.ts
|
|
18328
|
-
var exports_tts = {};
|
|
18329
|
-
__export(exports_tts, {
|
|
18330
|
-
textToSpeech: () => textToSpeech,
|
|
18331
|
-
fetchTask: () => fetchTask,
|
|
18332
|
-
fetchProviders: () => fetchProviders
|
|
18333
|
-
});
|
|
18334
|
-
var fetchProviders = async () => {
|
|
18335
|
-
try {
|
|
18336
|
-
const { data } = await axios2({
|
|
18337
|
-
url: "/302/tts/provider",
|
|
18338
|
-
method: "get"
|
|
18339
|
-
});
|
|
18340
|
-
return data;
|
|
18341
|
-
} catch (error) {
|
|
18342
|
-
throw error;
|
|
18343
|
-
}
|
|
18344
|
-
};
|
|
18345
|
-
var textToSpeech = async (request) => {
|
|
18346
|
-
try {
|
|
18347
|
-
const { webhook, run_async, ...body } = request;
|
|
18348
|
-
const { data } = await axios2({
|
|
18349
|
-
url: "/302/v2/audio/tts",
|
|
18350
|
-
method: "post",
|
|
18351
|
-
params: {
|
|
18352
|
-
webhook,
|
|
18353
|
-
run_async
|
|
18354
|
-
},
|
|
18355
|
-
data: {
|
|
18356
|
-
...body,
|
|
18357
|
-
speed: body.speed ?? 1,
|
|
18358
|
-
volume: body.volume ?? 1,
|
|
18359
|
-
timeout: body.timeout ?? 180
|
|
18360
|
-
}
|
|
18361
|
-
});
|
|
18362
|
-
return data;
|
|
18363
|
-
} catch (error) {
|
|
18364
|
-
throw error;
|
|
18365
|
-
}
|
|
18366
|
-
};
|
|
18367
|
-
var fetchTask = async (taskId) => {
|
|
18368
|
-
if (!taskId) {
|
|
18369
|
-
throw new Error("taskId 不能为空");
|
|
18370
|
-
}
|
|
18371
|
-
try {
|
|
18372
|
-
const { data } = await axios2({
|
|
18373
|
-
url: `/302/v2/audio/fetch/${encodeURIComponent(taskId)}`,
|
|
18374
|
-
method: "get"
|
|
18375
|
-
});
|
|
18376
|
-
return data;
|
|
18377
|
-
} catch (error) {
|
|
18378
|
-
throw error;
|
|
18379
|
-
}
|
|
18380
|
-
};
|
|
18381
|
-
// src/common/ai/302/audio/doubao.ts
|
|
18382
|
-
var exports_doubao = {};
|
|
18383
|
-
__export(exports_doubao, {
|
|
18384
|
-
ttsHd: () => ttsHd
|
|
18385
|
-
});
|
|
18386
|
-
var createReqid = () => {
|
|
18387
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
18388
|
-
return crypto.randomUUID();
|
|
18389
|
-
}
|
|
18390
|
-
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
18391
|
-
};
|
|
18392
|
-
var getUtf8ByteLength = (value) => {
|
|
18393
|
-
return new TextEncoder().encode(value).length;
|
|
18394
|
-
};
|
|
18395
|
-
var assertNonEmptyString = (value, label) => {
|
|
18396
|
-
if (typeof value !== "string" || !value.trim()) {
|
|
18397
|
-
throw new Error(`${label} 不能为空`);
|
|
18398
|
-
}
|
|
18399
|
-
};
|
|
18400
|
-
var assertSpeedRatio = (value) => {
|
|
18401
|
-
if (value === undefined)
|
|
18402
|
-
return;
|
|
18403
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
18404
|
-
throw new Error("speed_ratio 必须为数字");
|
|
18405
|
-
}
|
|
18406
|
-
if (value < 0.8 || value > 2) {
|
|
18407
|
-
throw new Error("speed_ratio 取值范围为 [0.8, 2]");
|
|
18408
|
-
}
|
|
18409
|
-
};
|
|
18410
|
-
var ttsHd = async (payload) => {
|
|
18411
|
-
const { audio, request } = payload;
|
|
18412
|
-
const { voice_type, encoding, speed_ratio } = audio;
|
|
18413
|
-
const { text, reqid: rawReqid, operation } = request;
|
|
18414
|
-
assertNonEmptyString(voice_type, "voice_type");
|
|
18415
|
-
assertNonEmptyString(text, "text");
|
|
18416
|
-
assertSpeedRatio(speed_ratio);
|
|
18417
|
-
const textByteLength = getUtf8ByteLength(text);
|
|
18418
|
-
if (textByteLength > 1024) {
|
|
18419
|
-
throw new Error(`text 超出长度限制:${textByteLength}/1024 字节`);
|
|
18420
|
-
}
|
|
18421
|
-
const reqid = rawReqid?.trim() || createReqid();
|
|
18422
|
-
const { data } = await axios2({
|
|
18423
|
-
url: "/doubao/tts_hd",
|
|
18424
|
-
method: "post",
|
|
18425
|
-
data: {
|
|
18426
|
-
audio: {
|
|
18427
|
-
voice_type,
|
|
18428
|
-
encoding: encoding ?? "pcm",
|
|
18429
|
-
speed_ratio: speed_ratio ?? 1
|
|
18430
|
-
},
|
|
18431
|
-
request: {
|
|
18432
|
-
reqid,
|
|
18433
|
-
text,
|
|
18434
|
-
operation: operation ?? "query"
|
|
18435
|
-
}
|
|
18436
|
-
}
|
|
18437
|
-
});
|
|
18438
|
-
return data;
|
|
18439
|
-
};
|
|
18440
|
-
// src/common/ai/302/image/index.ts
|
|
18441
|
-
var exports_image = {};
|
|
18442
|
-
__export(exports_image, {
|
|
18443
|
-
midjourney: () => exports_midjourney,
|
|
18444
|
-
gpt: () => exports_gpt
|
|
18445
|
-
});
|
|
18446
|
-
|
|
18447
|
-
// src/common/ai/302/image/midjourney.ts
|
|
18448
|
-
var exports_midjourney = {};
|
|
18449
|
-
__export(exports_midjourney, {
|
|
18450
|
-
getImageStatus: () => getImageStatus,
|
|
18451
|
-
generateImage: () => generateImage
|
|
18452
|
-
});
|
|
18453
|
-
var generateImage = async (prompt, base64Array) => {
|
|
18454
|
-
try {
|
|
18455
|
-
const { data } = await axios2({
|
|
18456
|
-
url: "/mj/submit/imagine",
|
|
18457
|
-
method: "post",
|
|
18458
|
-
data: {
|
|
18459
|
-
prompt,
|
|
18460
|
-
base64Array,
|
|
18461
|
-
botType: "MID_JOURNEY",
|
|
18462
|
-
notifyHook: "",
|
|
18463
|
-
state: ""
|
|
18464
|
-
}
|
|
18465
|
-
});
|
|
18466
|
-
return data;
|
|
18467
|
-
} catch (error) {
|
|
18468
|
-
throw error;
|
|
18469
|
-
}
|
|
18470
|
-
};
|
|
18471
|
-
var getImageStatus = async (taskId) => {
|
|
18472
|
-
try {
|
|
18473
|
-
const { data } = await axios2({
|
|
18474
|
-
url: `/mj/task/${taskId}/fetch`,
|
|
18475
|
-
method: "get"
|
|
18476
|
-
});
|
|
18477
|
-
return data;
|
|
18478
|
-
} catch (error) {
|
|
18479
|
-
throw error;
|
|
18480
|
-
}
|
|
18481
|
-
};
|
|
18482
|
-
// src/common/ai/302/image/gpt.ts
|
|
18483
|
-
var exports_gpt = {};
|
|
18484
|
-
__export(exports_gpt, {
|
|
18485
|
-
generateImage: () => generateImage2
|
|
18486
|
-
});
|
|
18487
|
-
var generateImage2 = async (params) => {
|
|
18488
|
-
if (params.model === "gpt-4o-plus") {
|
|
18489
|
-
const { data: data2 } = await axios2.post("/v1/chat/completions", {
|
|
18490
|
-
model: params.model,
|
|
18491
|
-
messages: [{ role: "user", content: params.prompt }]
|
|
18492
|
-
});
|
|
18493
|
-
const content = data2?.choices?.[0]?.message?.content || "";
|
|
18494
|
-
const urlMatch = content.match(/!\[.*?\]\((.*?)\)/) || content.match(/(https?:\/\/[^\s]+)/);
|
|
18495
|
-
const url = urlMatch ? urlMatch[1] : content;
|
|
18496
|
-
return {
|
|
18497
|
-
background: "",
|
|
18498
|
-
created: data2.created,
|
|
18499
|
-
data: [{ url }],
|
|
18500
|
-
output_format: "",
|
|
18501
|
-
quality: "",
|
|
18502
|
-
size: "",
|
|
18503
|
-
usage: {
|
|
18504
|
-
input_tokens: data2.usage?.prompt_tokens || 0,
|
|
18505
|
-
input_tokens_details: {
|
|
18506
|
-
image_tokens: data2.usage?.prompt_tokens_details?.image_tokens || 0,
|
|
18507
|
-
text_tokens: data2.usage?.prompt_tokens_details?.text_tokens || 0
|
|
18508
|
-
},
|
|
18509
|
-
output_tokens: data2.usage?.completion_tokens || 0,
|
|
18510
|
-
output_tokens_details: {
|
|
18511
|
-
image_tokens: data2.usage?.completion_tokens_details?.image_tokens || 0,
|
|
18512
|
-
text_tokens: data2.usage?.completion_tokens_details?.content_tokens || 0
|
|
18513
|
-
},
|
|
18514
|
-
total_tokens: data2.usage?.total_tokens || 0
|
|
18515
|
-
}
|
|
18516
|
-
};
|
|
18517
|
-
}
|
|
18518
|
-
const { data } = await axios2.post("/v1/images/generations", params);
|
|
18519
|
-
return data;
|
|
18520
|
-
};
|
|
18521
|
-
// src/common/ai/doubao/index.ts
|
|
18522
|
-
var exports_doubao2 = {};
|
|
18523
|
-
__export(exports_doubao2, {
|
|
18524
|
-
vc: () => vc,
|
|
18525
|
-
tts: () => tts
|
|
18526
|
-
});
|
|
18527
|
-
|
|
18528
|
-
// src/common/ai/doubao/tts.ts
|
|
18529
|
-
var createReqid2 = () => {
|
|
18530
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
18531
|
-
return crypto.randomUUID();
|
|
18532
|
-
}
|
|
18533
|
-
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
18534
|
-
};
|
|
18535
|
-
var decodeBase64ToArrayBuffer = (value) => {
|
|
18536
|
-
if (typeof window !== "undefined" && typeof window.atob === "function") {
|
|
18537
|
-
const binary = window.atob(value);
|
|
18538
|
-
const bytes = new Uint8Array(binary.length);
|
|
18539
|
-
for (let i = 0;i < binary.length; i++) {
|
|
18540
|
-
bytes[i] = binary.charCodeAt(i);
|
|
18541
|
-
}
|
|
18542
|
-
return bytes.buffer;
|
|
18543
|
-
}
|
|
18544
|
-
const buf = Buffer.from(value, "base64");
|
|
18545
|
-
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
18546
|
-
};
|
|
18547
|
-
var tts = async (params) => {
|
|
18548
|
-
const { app, user, audio, request } = params;
|
|
18549
|
-
const url = "https://openspeech.bytedance.com/api/v3/tts/unidirectional";
|
|
18550
|
-
const reqid = request.reqid || createReqid2();
|
|
18551
|
-
const speechRate = audio.speed_ratio ? Math.round((audio.speed_ratio - 1) * 100) : 0;
|
|
18552
|
-
const loudnessRate = audio.volume_ratio ? Math.round((audio.volume_ratio - 1) * 100) : 0;
|
|
18553
|
-
const headers = {
|
|
18554
|
-
"X-Api-App-Id": app.appid || "",
|
|
18555
|
-
"X-Api-Access-Key": app.accessToken || "",
|
|
18556
|
-
"Content-Type": "application/json",
|
|
18557
|
-
"X-Api-Resource-Id": app.resourceId || "seed-tts-2.0",
|
|
18558
|
-
"X-Api-Request-Id": reqid
|
|
18559
|
-
};
|
|
18560
|
-
const payload = {
|
|
18561
|
-
user: {
|
|
18562
|
-
uid: user?.uid || "uid"
|
|
18563
|
-
},
|
|
18564
|
-
req_params: {
|
|
18565
|
-
text: request.text,
|
|
18566
|
-
speaker: audio.voice_type,
|
|
18567
|
-
audio_params: {
|
|
18568
|
-
format: audio.encoding || "pcm",
|
|
18569
|
-
sample_rate: 24000,
|
|
18570
|
-
speech_rate: speechRate,
|
|
18571
|
-
loudness_rate: loudnessRate,
|
|
18572
|
-
emotion: audio.emotion,
|
|
18573
|
-
emotion_scale: audio.emotion_scale
|
|
18574
|
-
}
|
|
18575
|
-
}
|
|
18576
|
-
};
|
|
18577
|
-
if (audio.context_texts) {
|
|
18578
|
-
payload.req_params.additions = JSON.stringify({
|
|
18579
|
-
context_texts: audio.context_texts
|
|
18580
|
-
});
|
|
18581
|
-
}
|
|
18582
|
-
try {
|
|
18583
|
-
const response = await axios_default.post(url, payload, {
|
|
18584
|
-
headers,
|
|
18585
|
-
responseType: "arraybuffer"
|
|
18586
|
-
});
|
|
18587
|
-
const responseText = new TextDecoder().decode(response.data);
|
|
18588
|
-
const jsonObjects = [];
|
|
18589
|
-
let depth = 0;
|
|
18590
|
-
let start = 0;
|
|
18591
|
-
for (let i = 0;i < responseText.length; i++) {
|
|
18592
|
-
if (responseText[i] === "{") {
|
|
18593
|
-
if (depth === 0)
|
|
18594
|
-
start = i;
|
|
18595
|
-
depth++;
|
|
18596
|
-
} else if (responseText[i] === "}") {
|
|
18597
|
-
depth--;
|
|
18598
|
-
if (depth === 0) {
|
|
18599
|
-
try {
|
|
18600
|
-
const jsonStr = responseText.substring(start, i + 1);
|
|
18601
|
-
const jsonObj = JSON.parse(jsonStr);
|
|
18602
|
-
jsonObjects.push(jsonObj);
|
|
18603
|
-
} catch (e) {
|
|
18604
|
-
console.warn("Failed to parse JSON chunk", e);
|
|
18605
|
-
}
|
|
18606
|
-
}
|
|
18607
|
-
}
|
|
18608
|
-
}
|
|
18609
|
-
if (jsonObjects.length === 0) {
|
|
18610
|
-
try {
|
|
18611
|
-
jsonObjects.push(JSON.parse(responseText));
|
|
18612
|
-
} catch (e) {
|
|
18613
|
-
console.error("Doubao TTS Response Parse Error:", responseText);
|
|
18614
|
-
throw new Error("Invalid response format");
|
|
18615
|
-
}
|
|
18616
|
-
}
|
|
18617
|
-
const audioChunks = [];
|
|
18618
|
-
let totalLength = 0;
|
|
18619
|
-
for (const data of jsonObjects) {
|
|
18620
|
-
const code = data.code;
|
|
18621
|
-
const message = data.message;
|
|
18622
|
-
if (typeof code === "number" && code !== 0 && code !== 20000000) {
|
|
18623
|
-
console.error("Doubao TTS Error Response:", JSON.stringify(data, null, 2));
|
|
18624
|
-
const err = new Error(`豆包语音合成失败: ${message} (code: ${code})`);
|
|
18625
|
-
err.code = code;
|
|
18626
|
-
err.reqid = data.reqid;
|
|
18627
|
-
throw err;
|
|
18628
|
-
}
|
|
18629
|
-
if (data.data) {
|
|
18630
|
-
const chunkBuffer = decodeBase64ToArrayBuffer(data.data);
|
|
18631
|
-
audioChunks.push(chunkBuffer);
|
|
18632
|
-
totalLength += chunkBuffer.byteLength;
|
|
18633
|
-
}
|
|
18634
|
-
}
|
|
18635
|
-
if (totalLength === 0) {
|
|
18636
|
-
throw new Error("豆包语音合成失败:未返回音频数据");
|
|
18637
|
-
}
|
|
18638
|
-
const resultBuffer = new Uint8Array(totalLength);
|
|
18639
|
-
let offset = 0;
|
|
18640
|
-
for (const chunk of audioChunks) {
|
|
18641
|
-
resultBuffer.set(new Uint8Array(chunk), offset);
|
|
18642
|
-
offset += chunk.byteLength;
|
|
18643
|
-
}
|
|
18644
|
-
return resultBuffer.buffer;
|
|
18645
|
-
} catch (error) {
|
|
18646
|
-
if (error.response) {
|
|
18647
|
-
try {
|
|
18648
|
-
let errorData = error.response.data;
|
|
18649
|
-
if (errorData instanceof ArrayBuffer || typeof Buffer !== "undefined" && Buffer.isBuffer(errorData)) {
|
|
18650
|
-
errorData = new TextDecoder().decode(errorData);
|
|
18651
|
-
} else if (typeof errorData === "object") {
|
|
18652
|
-
errorData = JSON.stringify(errorData);
|
|
18653
|
-
}
|
|
18654
|
-
throw new Error(`Doubao TTS Error: ${error.response.status} - ${errorData}`);
|
|
18655
|
-
} catch (e) {
|
|
18656
|
-
if (e.message && e.message.startsWith("Doubao TTS Error")) {
|
|
18657
|
-
throw e;
|
|
18658
|
-
}
|
|
18659
|
-
throw new Error(`Doubao TTS Error: ${error.response.status} ${error.message}`);
|
|
18660
|
-
}
|
|
18661
|
-
}
|
|
18662
|
-
throw error;
|
|
18663
|
-
}
|
|
18664
|
-
};
|
|
18665
|
-
// src/common/ai/doubao/vc.ts
|
|
18666
|
-
var getHeaders = (accessToken, contentType) => {
|
|
18667
|
-
const headers = {
|
|
18668
|
-
Authorization: `Bearer; ${accessToken}`
|
|
18669
|
-
};
|
|
18670
|
-
if (contentType) {
|
|
18671
|
-
headers["content-type"] = contentType;
|
|
18672
|
-
}
|
|
18673
|
-
return headers;
|
|
18674
|
-
};
|
|
18675
|
-
var handleResponse = (data) => {
|
|
18676
|
-
if (data instanceof ArrayBuffer) {
|
|
18677
|
-
return data;
|
|
18678
|
-
}
|
|
18679
|
-
if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
|
|
18680
|
-
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
18681
|
-
}
|
|
18682
|
-
return data;
|
|
18683
|
-
};
|
|
18684
|
-
var vc = {
|
|
18685
|
-
submit: async (params) => {
|
|
18686
|
-
const { app, audio, options = {} } = params;
|
|
18687
|
-
const url = new URL("https://openspeech.bytedance.com/api/v1/vc/submit");
|
|
18688
|
-
url.searchParams.set("appid", app.appid);
|
|
18689
|
-
Object.entries(options).forEach(([key2, value]) => {
|
|
18690
|
-
if (value !== undefined && value !== null) {
|
|
18691
|
-
url.searchParams.set(key2, String(value));
|
|
18692
|
-
}
|
|
18693
|
-
});
|
|
18694
|
-
const response = await axios_default.post(url.toString(), audio.data, {
|
|
18695
|
-
headers: getHeaders(app.accessToken, audio.contentType || "audio/wav"),
|
|
18696
|
-
responseType: "arraybuffer"
|
|
18697
|
-
});
|
|
18698
|
-
return handleResponse(response.data);
|
|
18699
|
-
},
|
|
18700
|
-
query: async (params) => {
|
|
18701
|
-
const { app, id, blocking } = params;
|
|
18702
|
-
const url = new URL("https://openspeech.bytedance.com/api/v1/vc/query");
|
|
18703
|
-
url.searchParams.set("appid", app.appid);
|
|
18704
|
-
url.searchParams.set("id", id);
|
|
18705
|
-
if (blocking !== undefined) {
|
|
18706
|
-
url.searchParams.set("blocking", String(blocking));
|
|
18707
|
-
}
|
|
18708
|
-
const response = await axios_default.get(url.toString(), {
|
|
18709
|
-
headers: getHeaders(app.accessToken),
|
|
18710
|
-
responseType: "arraybuffer"
|
|
18711
|
-
});
|
|
18712
|
-
return handleResponse(response.data);
|
|
18270
|
+
throw new Error(error?.response?.statusText || error?.message || "未知原因");
|
|
18713
18271
|
}
|
|
18714
18272
|
};
|
|
18715
|
-
// src/common/ai/keling/index.ts
|
|
18716
|
-
var exports_keling = {};
|
|
18717
|
-
__export(exports_keling, {
|
|
18718
|
-
setCookie: () => setCookie,
|
|
18719
|
-
getVideoStatus: () => getVideoStatus,
|
|
18720
|
-
generateVideo: () => generateVideo
|
|
18721
|
-
});
|
|
18722
|
-
|
|
18723
18273
|
// node:url
|
|
18724
18274
|
var { URL: J, URLSearchParams: X } = globalThis;
|
|
18725
18275
|
function F(s) {
|
|
@@ -19340,2791 +18890,112 @@ var generateVideo = async (imageUrl, prompt) => {
|
|
|
19340
18890
|
console.log(666, "任务 id", taskId);
|
|
19341
18891
|
return taskId;
|
|
19342
18892
|
};
|
|
19343
|
-
// src/common/
|
|
19344
|
-
|
|
19345
|
-
|
|
19346
|
-
|
|
19347
|
-
|
|
19348
|
-
|
|
19349
|
-
|
|
19350
|
-
return
|
|
19351
|
-
}
|
|
19352
|
-
|
|
19353
|
-
|
|
19354
|
-
var getStrLength = (value) => {
|
|
19355
|
-
if (!value) {
|
|
19356
|
-
return 0;
|
|
18893
|
+
// src/common/image.ts
|
|
18894
|
+
async function imageToBase64(url) {
|
|
18895
|
+
try {
|
|
18896
|
+
const response = await axios_default.get(url, {
|
|
18897
|
+
responseType: "arraybuffer"
|
|
18898
|
+
});
|
|
18899
|
+
const base64String = Buffer.from(response.data).toString("base64");
|
|
18900
|
+
return `data:image/*;base64,${base64String}`;
|
|
18901
|
+
} catch (error) {
|
|
18902
|
+
console.error("Failed to fetch the image:", error);
|
|
18903
|
+
throw error;
|
|
19357
18904
|
}
|
|
19358
|
-
|
|
19359
|
-
|
|
19360
|
-
|
|
19361
|
-
|
|
19362
|
-
|
|
19363
|
-
|
|
18905
|
+
}
|
|
18906
|
+
// src/common/enum.ts
|
|
18907
|
+
class EnumItem {
|
|
18908
|
+
label;
|
|
18909
|
+
value;
|
|
18910
|
+
extra;
|
|
18911
|
+
constructor(config) {
|
|
18912
|
+
this.value = config.value;
|
|
18913
|
+
this.label = config.label;
|
|
18914
|
+
this.extra = config.extra;
|
|
19364
18915
|
}
|
|
19365
|
-
|
|
19366
|
-
|
|
19367
|
-
|
|
18916
|
+
}
|
|
18917
|
+
var Enum = {
|
|
18918
|
+
create: (members) => {
|
|
18919
|
+
const usedValues = new Set;
|
|
18920
|
+
const enumObj = {};
|
|
18921
|
+
const map = new Map;
|
|
18922
|
+
const options = [];
|
|
18923
|
+
const extras = new Map;
|
|
18924
|
+
const labels = new Map;
|
|
18925
|
+
const enums = {};
|
|
18926
|
+
for (const key2 in members) {
|
|
18927
|
+
const member = members[key2];
|
|
18928
|
+
if (!member)
|
|
18929
|
+
continue;
|
|
18930
|
+
if (usedValues.has(member.value)) {
|
|
18931
|
+
throw new Error(`Duplicate enum value detected: ${member.value}`);
|
|
18932
|
+
}
|
|
18933
|
+
usedValues.add(member.value);
|
|
18934
|
+
const item = new EnumItem(member);
|
|
18935
|
+
enumObj[key2] = item;
|
|
18936
|
+
map.set(item.value, item);
|
|
18937
|
+
labels.set(item.value, item.label);
|
|
18938
|
+
options.push(item);
|
|
18939
|
+
enums[item.value] = { text: item.label, status: item.extra?.status };
|
|
18940
|
+
if (member.extra !== undefined) {
|
|
18941
|
+
extras.set(item.value, { ...member.extra });
|
|
18942
|
+
}
|
|
18943
|
+
}
|
|
18944
|
+
enumObj.map = map;
|
|
18945
|
+
enumObj.options = options;
|
|
18946
|
+
enumObj.extras = extras;
|
|
18947
|
+
enumObj.source = members;
|
|
18948
|
+
enumObj.labels = labels;
|
|
18949
|
+
enumObj.enums = enums;
|
|
18950
|
+
return enumObj;
|
|
19368
18951
|
}
|
|
19369
|
-
return replaceAll(str, searchValue, replaceValue);
|
|
19370
18952
|
};
|
|
19371
|
-
|
|
19372
|
-
|
|
19373
|
-
|
|
18953
|
+
// src/common/dayjs.ts
|
|
18954
|
+
var import_dayjs = __toESM(require_dayjs_min());
|
|
18955
|
+
var import_isBetween = __toESM(require_isBetween());
|
|
18956
|
+
var import_weekday = __toESM(require_weekday());
|
|
18957
|
+
var import_localeData = __toESM(require_localeData());
|
|
18958
|
+
var import_isoWeek = __toESM(require_isoWeek());
|
|
18959
|
+
var import_updateLocale = __toESM(require_updateLocale());
|
|
18960
|
+
var import_timezone = __toESM(require_timezone());
|
|
18961
|
+
var import_isSameOrAfter = __toESM(require_isSameOrAfter());
|
|
18962
|
+
var import_isSameOrBefore = __toESM(require_isSameOrBefore());
|
|
18963
|
+
var import_utc = __toESM(require_utc());
|
|
18964
|
+
var import_zh_cn = __toESM(require_zh_cn());
|
|
18965
|
+
var import_dayjs2 = __toESM(require_dayjs_min());
|
|
18966
|
+
import_dayjs.default.extend(import_utc.default);
|
|
18967
|
+
import_dayjs.default.extend(import_isBetween.default);
|
|
18968
|
+
import_dayjs.default.extend(import_weekday.default);
|
|
18969
|
+
import_dayjs.default.extend(import_localeData.default);
|
|
18970
|
+
import_dayjs.default.extend(import_isoWeek.default);
|
|
18971
|
+
import_dayjs.default.extend(import_updateLocale.default);
|
|
18972
|
+
import_dayjs.default.extend(import_timezone.default);
|
|
18973
|
+
import_dayjs.default.extend(import_isSameOrAfter.default);
|
|
18974
|
+
import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
18975
|
+
var Timezone;
|
|
18976
|
+
((Timezone2) => {
|
|
18977
|
+
Timezone2["AsiaShanghai"] = "Asia/Shanghai";
|
|
18978
|
+
Timezone2["AsiaTokyo"] = "Asia/Tokyo";
|
|
18979
|
+
Timezone2["AmericaNewYork"] = "America/New_York";
|
|
18980
|
+
Timezone2["EuropeLondon"] = "Europe/London";
|
|
18981
|
+
Timezone2["EuropeBerlin"] = "Europe/Berlin";
|
|
18982
|
+
})(Timezone ||= {});
|
|
18983
|
+
var initChinaDayjs = () => {
|
|
18984
|
+
import_dayjs.default.locale("zh-cn");
|
|
18985
|
+
import_dayjs.default.tz.setDefault("Asia/Shanghai" /* AsiaShanghai */);
|
|
18986
|
+
import_dayjs.default.updateLocale("zh-cn", {
|
|
18987
|
+
weekStart: 1
|
|
19374
18988
|
});
|
|
19375
|
-
return
|
|
18989
|
+
return import_dayjs.default;
|
|
19376
18990
|
};
|
|
19377
|
-
var
|
|
19378
|
-
|
|
19379
|
-
|
|
18991
|
+
var chinaDayjs = initChinaDayjs();
|
|
18992
|
+
var dayjs_default = import_dayjs.default;
|
|
18993
|
+
// src/web/element.ts
|
|
18994
|
+
var scrollIntoView = (el, option) => {
|
|
18995
|
+
if (!el) {
|
|
18996
|
+
return;
|
|
19380
18997
|
}
|
|
19381
|
-
|
|
19382
|
-
return prompt.replace(regex, (match, p1) => {
|
|
19383
|
-
return variables[p1] ?? match;
|
|
19384
|
-
});
|
|
19385
|
-
};
|
|
19386
|
-
var getType = (value) => {
|
|
19387
|
-
return Object.prototype.toString.call(value).slice(8, -1);
|
|
19388
|
-
};
|
|
19389
|
-
var amount = (str) => {
|
|
19390
|
-
const reg = /(?=(?!\b)(\d{3})+$)/g;
|
|
19391
|
-
return str.replace(reg, ",");
|
|
19392
|
-
};
|
|
19393
|
-
var jsonParse = (value) => {
|
|
19394
|
-
if (typeof value === "object") {
|
|
19395
|
-
return value;
|
|
19396
|
-
}
|
|
19397
|
-
try {
|
|
19398
|
-
return JSON.parse(value);
|
|
19399
|
-
} catch (err) {
|
|
19400
|
-
return {};
|
|
19401
|
-
}
|
|
19402
|
-
};
|
|
19403
|
-
var isJson = (str) => {
|
|
19404
|
-
try {
|
|
19405
|
-
if (getType(JSON.parse(str)) === "Object") {
|
|
19406
|
-
return true;
|
|
19407
|
-
}
|
|
19408
|
-
} catch (e) {}
|
|
19409
|
-
return false;
|
|
19410
|
-
};
|
|
19411
|
-
var toString3 = (value) => {
|
|
19412
|
-
return Object.prototype.toString.call(value).slice(8, -1) === "object" ? JSON.stringify(value) : String(value);
|
|
19413
|
-
};
|
|
19414
|
-
var getRandomColor = () => {
|
|
19415
|
-
const color = Math.floor(Math.random() * 16777215).toString(16);
|
|
19416
|
-
if (color.length === 6) {
|
|
19417
|
-
return color;
|
|
19418
|
-
} else {
|
|
19419
|
-
return getRandomColor();
|
|
19420
|
-
}
|
|
19421
|
-
};
|
|
19422
|
-
var getRandomString = (length = 4) => {
|
|
19423
|
-
return Math.random().toString(36).substr(2, length);
|
|
19424
|
-
};
|
|
19425
|
-
var getChinese = (str) => {
|
|
19426
|
-
if (str == null || str === "") {
|
|
19427
|
-
return "";
|
|
19428
|
-
}
|
|
19429
|
-
const res = str.match(/[\u4e00-\u9fa5]/g);
|
|
19430
|
-
if (!res) {
|
|
19431
|
-
return "";
|
|
19432
|
-
}
|
|
19433
|
-
return res.join("");
|
|
19434
|
-
};
|
|
19435
|
-
var getSliceStr = (str, before, after) => {
|
|
19436
|
-
return str.slice(str.indexOf(before) + before.length, str.lastIndexOf(after));
|
|
19437
|
-
};
|
|
19438
|
-
var getProxyUrl = (url) => {
|
|
19439
|
-
const beforeUrl = "https://1141871752167714.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/a.LATEST/proxy/?url=";
|
|
19440
|
-
return beforeUrl + url;
|
|
19441
|
-
};
|
|
19442
|
-
var getLength = (value) => {
|
|
19443
|
-
const chineseLength = getChinese(value).length;
|
|
19444
|
-
return value.length - chineseLength + chineseLength * 2;
|
|
19445
|
-
};
|
|
19446
|
-
var getCookie = (name) => {
|
|
19447
|
-
const reg = new RegExp(`(^| )${name}=([^;]*)(;|$)`);
|
|
19448
|
-
const arr = document.cookie.match(reg);
|
|
19449
|
-
return arr ? unescape(arr[2]) : null;
|
|
19450
|
-
};
|
|
19451
|
-
var generateAlphabetArray = (n) => {
|
|
19452
|
-
return Array.from({ length: n }, (_2, i) => String.fromCharCode(97 + i));
|
|
19453
|
-
};
|
|
19454
|
-
var levenshteinDistance = (a, b) => {
|
|
19455
|
-
const matrix = [];
|
|
19456
|
-
for (let i = 0;i <= b.length; i++) {
|
|
19457
|
-
matrix[i] = [i];
|
|
19458
|
-
}
|
|
19459
|
-
for (let j3 = 0;j3 <= a.length; j3++) {
|
|
19460
|
-
matrix[0][j3] = j3;
|
|
19461
|
-
}
|
|
19462
|
-
for (let i = 1;i <= b.length; i++) {
|
|
19463
|
-
for (let j3 = 1;j3 <= a.length; j3++) {
|
|
19464
|
-
if (b[i - 1] === a[j3 - 1]) {
|
|
19465
|
-
matrix[i][j3] = matrix[i - 1][j3 - 1];
|
|
19466
|
-
} else {
|
|
19467
|
-
matrix[i][j3] = Math.min(matrix[i - 1][j3 - 1] + 1, matrix[i][j3 - 1] + 1, matrix[i - 1][j3] + 1);
|
|
19468
|
-
}
|
|
19469
|
-
}
|
|
19470
|
-
}
|
|
19471
|
-
return matrix[b.length][a.length];
|
|
19472
|
-
};
|
|
19473
|
-
var generateUniqueFileName = (name) => {
|
|
19474
|
-
const match = name.match(/^(.*?)(\.[^.]*$|$)/);
|
|
19475
|
-
if (match) {
|
|
19476
|
-
const namePart = match[1];
|
|
19477
|
-
const extensionPart = match[2];
|
|
19478
|
-
if (extensionPart) {
|
|
19479
|
-
return `${namePart}_${Date.now()}${extensionPart}`;
|
|
19480
|
-
} else {
|
|
19481
|
-
return `${namePart}_${Date.now()}.dat`;
|
|
19482
|
-
}
|
|
19483
|
-
}
|
|
19484
|
-
throw new Error("Invalid filename format.");
|
|
19485
|
-
};
|
|
19486
|
-
|
|
19487
|
-
// ../../node_modules/decimal.js/decimal.mjs
|
|
19488
|
-
/*!
|
|
19489
|
-
* decimal.js v10.6.0
|
|
19490
|
-
* An arbitrary-precision Decimal type for JavaScript.
|
|
19491
|
-
* https://github.com/MikeMcl/decimal.js
|
|
19492
|
-
* Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
19493
|
-
* MIT Licence
|
|
19494
|
-
*/
|
|
19495
|
-
var EXP_LIMIT = 9000000000000000;
|
|
19496
|
-
var MAX_DIGITS = 1e9;
|
|
19497
|
-
var NUMERALS = "0123456789abcdef";
|
|
19498
|
-
var LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";
|
|
19499
|
-
var PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789";
|
|
19500
|
-
var DEFAULTS = {
|
|
19501
|
-
precision: 20,
|
|
19502
|
-
rounding: 4,
|
|
19503
|
-
modulo: 1,
|
|
19504
|
-
toExpNeg: -7,
|
|
19505
|
-
toExpPos: 21,
|
|
19506
|
-
minE: -EXP_LIMIT,
|
|
19507
|
-
maxE: EXP_LIMIT,
|
|
19508
|
-
crypto: false
|
|
19509
|
-
};
|
|
19510
|
-
var inexact;
|
|
19511
|
-
var quadrant;
|
|
19512
|
-
var external2 = true;
|
|
19513
|
-
var decimalError = "[DecimalError] ";
|
|
19514
|
-
var invalidArgument = decimalError + "Invalid argument: ";
|
|
19515
|
-
var precisionLimitExceeded = decimalError + "Precision limit exceeded";
|
|
19516
|
-
var cryptoUnavailable = decimalError + "crypto unavailable";
|
|
19517
|
-
var tag = "[object Decimal]";
|
|
19518
|
-
var mathfloor = Math.floor;
|
|
19519
|
-
var mathpow = Math.pow;
|
|
19520
|
-
var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
|
|
19521
|
-
var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
|
|
19522
|
-
var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
|
|
19523
|
-
var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
|
|
19524
|
-
var BASE = 1e7;
|
|
19525
|
-
var LOG_BASE = 7;
|
|
19526
|
-
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
19527
|
-
var LN10_PRECISION = LN10.length - 1;
|
|
19528
|
-
var PI_PRECISION = PI.length - 1;
|
|
19529
|
-
var P2 = { toStringTag: tag };
|
|
19530
|
-
P2.absoluteValue = P2.abs = function() {
|
|
19531
|
-
var x2 = new this.constructor(this);
|
|
19532
|
-
if (x2.s < 0)
|
|
19533
|
-
x2.s = 1;
|
|
19534
|
-
return finalise(x2);
|
|
19535
|
-
};
|
|
19536
|
-
P2.ceil = function() {
|
|
19537
|
-
return finalise(new this.constructor(this), this.e + 1, 2);
|
|
19538
|
-
};
|
|
19539
|
-
P2.clampedTo = P2.clamp = function(min, max) {
|
|
19540
|
-
var k3, x2 = this, Ctor = x2.constructor;
|
|
19541
|
-
min = new Ctor(min);
|
|
19542
|
-
max = new Ctor(max);
|
|
19543
|
-
if (!min.s || !max.s)
|
|
19544
|
-
return new Ctor(NaN);
|
|
19545
|
-
if (min.gt(max))
|
|
19546
|
-
throw Error(invalidArgument + max);
|
|
19547
|
-
k3 = x2.cmp(min);
|
|
19548
|
-
return k3 < 0 ? min : x2.cmp(max) > 0 ? max : new Ctor(x2);
|
|
19549
|
-
};
|
|
19550
|
-
P2.comparedTo = P2.cmp = function(y2) {
|
|
19551
|
-
var i, j3, xdL, ydL, x2 = this, xd = x2.d, yd = (y2 = new x2.constructor(y2)).d, xs = x2.s, ys = y2.s;
|
|
19552
|
-
if (!xd || !yd) {
|
|
19553
|
-
return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
|
|
19554
|
-
}
|
|
19555
|
-
if (!xd[0] || !yd[0])
|
|
19556
|
-
return xd[0] ? xs : yd[0] ? -ys : 0;
|
|
19557
|
-
if (xs !== ys)
|
|
19558
|
-
return xs;
|
|
19559
|
-
if (x2.e !== y2.e)
|
|
19560
|
-
return x2.e > y2.e ^ xs < 0 ? 1 : -1;
|
|
19561
|
-
xdL = xd.length;
|
|
19562
|
-
ydL = yd.length;
|
|
19563
|
-
for (i = 0, j3 = xdL < ydL ? xdL : ydL;i < j3; ++i) {
|
|
19564
|
-
if (xd[i] !== yd[i])
|
|
19565
|
-
return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
|
|
19566
|
-
}
|
|
19567
|
-
return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
|
|
19568
|
-
};
|
|
19569
|
-
P2.cosine = P2.cos = function() {
|
|
19570
|
-
var pr, rm, x2 = this, Ctor = x2.constructor;
|
|
19571
|
-
if (!x2.d)
|
|
19572
|
-
return new Ctor(NaN);
|
|
19573
|
-
if (!x2.d[0])
|
|
19574
|
-
return new Ctor(1);
|
|
19575
|
-
pr = Ctor.precision;
|
|
19576
|
-
rm = Ctor.rounding;
|
|
19577
|
-
Ctor.precision = pr + Math.max(x2.e, x2.sd()) + LOG_BASE;
|
|
19578
|
-
Ctor.rounding = 1;
|
|
19579
|
-
x2 = cosine(Ctor, toLessThanHalfPi(Ctor, x2));
|
|
19580
|
-
Ctor.precision = pr;
|
|
19581
|
-
Ctor.rounding = rm;
|
|
19582
|
-
return finalise(quadrant == 2 || quadrant == 3 ? x2.neg() : x2, pr, rm, true);
|
|
19583
|
-
};
|
|
19584
|
-
P2.cubeRoot = P2.cbrt = function() {
|
|
19585
|
-
var e, m2, n, r, rep, s, sd, t, t3, t3plusx, x2 = this, Ctor = x2.constructor;
|
|
19586
|
-
if (!x2.isFinite() || x2.isZero())
|
|
19587
|
-
return new Ctor(x2);
|
|
19588
|
-
external2 = false;
|
|
19589
|
-
s = x2.s * mathpow(x2.s * x2, 1 / 3);
|
|
19590
|
-
if (!s || Math.abs(s) == 1 / 0) {
|
|
19591
|
-
n = digitsToString(x2.d);
|
|
19592
|
-
e = x2.e;
|
|
19593
|
-
if (s = (e - n.length + 1) % 3)
|
|
19594
|
-
n += s == 1 || s == -2 ? "0" : "00";
|
|
19595
|
-
s = mathpow(n, 1 / 3);
|
|
19596
|
-
e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
|
|
19597
|
-
if (s == 1 / 0) {
|
|
19598
|
-
n = "5e" + e;
|
|
19599
|
-
} else {
|
|
19600
|
-
n = s.toExponential();
|
|
19601
|
-
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
19602
|
-
}
|
|
19603
|
-
r = new Ctor(n);
|
|
19604
|
-
r.s = x2.s;
|
|
19605
|
-
} else {
|
|
19606
|
-
r = new Ctor(s.toString());
|
|
19607
|
-
}
|
|
19608
|
-
sd = (e = Ctor.precision) + 3;
|
|
19609
|
-
for (;; ) {
|
|
19610
|
-
t = r;
|
|
19611
|
-
t3 = t.times(t).times(t);
|
|
19612
|
-
t3plusx = t3.plus(x2);
|
|
19613
|
-
r = divide(t3plusx.plus(x2).times(t), t3plusx.plus(t3), sd + 2, 1);
|
|
19614
|
-
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
19615
|
-
n = n.slice(sd - 3, sd + 1);
|
|
19616
|
-
if (n == "9999" || !rep && n == "4999") {
|
|
19617
|
-
if (!rep) {
|
|
19618
|
-
finalise(t, e + 1, 0);
|
|
19619
|
-
if (t.times(t).times(t).eq(x2)) {
|
|
19620
|
-
r = t;
|
|
19621
|
-
break;
|
|
19622
|
-
}
|
|
19623
|
-
}
|
|
19624
|
-
sd += 4;
|
|
19625
|
-
rep = 1;
|
|
19626
|
-
} else {
|
|
19627
|
-
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
19628
|
-
finalise(r, e + 1, 1);
|
|
19629
|
-
m2 = !r.times(r).times(r).eq(x2);
|
|
19630
|
-
}
|
|
19631
|
-
break;
|
|
19632
|
-
}
|
|
19633
|
-
}
|
|
19634
|
-
}
|
|
19635
|
-
external2 = true;
|
|
19636
|
-
return finalise(r, e, Ctor.rounding, m2);
|
|
19637
|
-
};
|
|
19638
|
-
P2.decimalPlaces = P2.dp = function() {
|
|
19639
|
-
var w2, d = this.d, n = NaN;
|
|
19640
|
-
if (d) {
|
|
19641
|
-
w2 = d.length - 1;
|
|
19642
|
-
n = (w2 - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
19643
|
-
w2 = d[w2];
|
|
19644
|
-
if (w2)
|
|
19645
|
-
for (;w2 % 10 == 0; w2 /= 10)
|
|
19646
|
-
n--;
|
|
19647
|
-
if (n < 0)
|
|
19648
|
-
n = 0;
|
|
19649
|
-
}
|
|
19650
|
-
return n;
|
|
19651
|
-
};
|
|
19652
|
-
P2.dividedBy = P2.div = function(y2) {
|
|
19653
|
-
return divide(this, new this.constructor(y2));
|
|
19654
|
-
};
|
|
19655
|
-
P2.dividedToIntegerBy = P2.divToInt = function(y2) {
|
|
19656
|
-
var x2 = this, Ctor = x2.constructor;
|
|
19657
|
-
return finalise(divide(x2, new Ctor(y2), 0, 1, 1), Ctor.precision, Ctor.rounding);
|
|
19658
|
-
};
|
|
19659
|
-
P2.equals = P2.eq = function(y2) {
|
|
19660
|
-
return this.cmp(y2) === 0;
|
|
19661
|
-
};
|
|
19662
|
-
P2.floor = function() {
|
|
19663
|
-
return finalise(new this.constructor(this), this.e + 1, 3);
|
|
19664
|
-
};
|
|
19665
|
-
P2.greaterThan = P2.gt = function(y2) {
|
|
19666
|
-
return this.cmp(y2) > 0;
|
|
19667
|
-
};
|
|
19668
|
-
P2.greaterThanOrEqualTo = P2.gte = function(y2) {
|
|
19669
|
-
var k3 = this.cmp(y2);
|
|
19670
|
-
return k3 == 1 || k3 === 0;
|
|
19671
|
-
};
|
|
19672
|
-
P2.hyperbolicCosine = P2.cosh = function() {
|
|
19673
|
-
var k3, n, pr, rm, len, x2 = this, Ctor = x2.constructor, one = new Ctor(1);
|
|
19674
|
-
if (!x2.isFinite())
|
|
19675
|
-
return new Ctor(x2.s ? 1 / 0 : NaN);
|
|
19676
|
-
if (x2.isZero())
|
|
19677
|
-
return one;
|
|
19678
|
-
pr = Ctor.precision;
|
|
19679
|
-
rm = Ctor.rounding;
|
|
19680
|
-
Ctor.precision = pr + Math.max(x2.e, x2.sd()) + 4;
|
|
19681
|
-
Ctor.rounding = 1;
|
|
19682
|
-
len = x2.d.length;
|
|
19683
|
-
if (len < 32) {
|
|
19684
|
-
k3 = Math.ceil(len / 3);
|
|
19685
|
-
n = (1 / tinyPow(4, k3)).toString();
|
|
19686
|
-
} else {
|
|
19687
|
-
k3 = 16;
|
|
19688
|
-
n = "2.3283064365386962890625e-10";
|
|
19689
|
-
}
|
|
19690
|
-
x2 = taylorSeries(Ctor, 1, x2.times(n), new Ctor(1), true);
|
|
19691
|
-
var cosh2_x, i = k3, d8 = new Ctor(8);
|
|
19692
|
-
for (;i--; ) {
|
|
19693
|
-
cosh2_x = x2.times(x2);
|
|
19694
|
-
x2 = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
|
|
19695
|
-
}
|
|
19696
|
-
return finalise(x2, Ctor.precision = pr, Ctor.rounding = rm, true);
|
|
19697
|
-
};
|
|
19698
|
-
P2.hyperbolicSine = P2.sinh = function() {
|
|
19699
|
-
var k3, pr, rm, len, x2 = this, Ctor = x2.constructor;
|
|
19700
|
-
if (!x2.isFinite() || x2.isZero())
|
|
19701
|
-
return new Ctor(x2);
|
|
19702
|
-
pr = Ctor.precision;
|
|
19703
|
-
rm = Ctor.rounding;
|
|
19704
|
-
Ctor.precision = pr + Math.max(x2.e, x2.sd()) + 4;
|
|
19705
|
-
Ctor.rounding = 1;
|
|
19706
|
-
len = x2.d.length;
|
|
19707
|
-
if (len < 3) {
|
|
19708
|
-
x2 = taylorSeries(Ctor, 2, x2, x2, true);
|
|
19709
|
-
} else {
|
|
19710
|
-
k3 = 1.4 * Math.sqrt(len);
|
|
19711
|
-
k3 = k3 > 16 ? 16 : k3 | 0;
|
|
19712
|
-
x2 = x2.times(1 / tinyPow(5, k3));
|
|
19713
|
-
x2 = taylorSeries(Ctor, 2, x2, x2, true);
|
|
19714
|
-
var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
19715
|
-
for (;k3--; ) {
|
|
19716
|
-
sinh2_x = x2.times(x2);
|
|
19717
|
-
x2 = x2.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
|
|
19718
|
-
}
|
|
19719
|
-
}
|
|
19720
|
-
Ctor.precision = pr;
|
|
19721
|
-
Ctor.rounding = rm;
|
|
19722
|
-
return finalise(x2, pr, rm, true);
|
|
19723
|
-
};
|
|
19724
|
-
P2.hyperbolicTangent = P2.tanh = function() {
|
|
19725
|
-
var pr, rm, x2 = this, Ctor = x2.constructor;
|
|
19726
|
-
if (!x2.isFinite())
|
|
19727
|
-
return new Ctor(x2.s);
|
|
19728
|
-
if (x2.isZero())
|
|
19729
|
-
return new Ctor(x2);
|
|
19730
|
-
pr = Ctor.precision;
|
|
19731
|
-
rm = Ctor.rounding;
|
|
19732
|
-
Ctor.precision = pr + 7;
|
|
19733
|
-
Ctor.rounding = 1;
|
|
19734
|
-
return divide(x2.sinh(), x2.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
|
|
19735
|
-
};
|
|
19736
|
-
P2.inverseCosine = P2.acos = function() {
|
|
19737
|
-
var x2 = this, Ctor = x2.constructor, k3 = x2.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
|
|
19738
|
-
if (k3 !== -1) {
|
|
19739
|
-
return k3 === 0 ? x2.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
|
|
19740
|
-
}
|
|
19741
|
-
if (x2.isZero())
|
|
19742
|
-
return getPi(Ctor, pr + 4, rm).times(0.5);
|
|
19743
|
-
Ctor.precision = pr + 6;
|
|
19744
|
-
Ctor.rounding = 1;
|
|
19745
|
-
x2 = new Ctor(1).minus(x2).div(x2.plus(1)).sqrt().atan();
|
|
19746
|
-
Ctor.precision = pr;
|
|
19747
|
-
Ctor.rounding = rm;
|
|
19748
|
-
return x2.times(2);
|
|
19749
|
-
};
|
|
19750
|
-
P2.inverseHyperbolicCosine = P2.acosh = function() {
|
|
19751
|
-
var pr, rm, x2 = this, Ctor = x2.constructor;
|
|
19752
|
-
if (x2.lte(1))
|
|
19753
|
-
return new Ctor(x2.eq(1) ? 0 : NaN);
|
|
19754
|
-
if (!x2.isFinite())
|
|
19755
|
-
return new Ctor(x2);
|
|
19756
|
-
pr = Ctor.precision;
|
|
19757
|
-
rm = Ctor.rounding;
|
|
19758
|
-
Ctor.precision = pr + Math.max(Math.abs(x2.e), x2.sd()) + 4;
|
|
19759
|
-
Ctor.rounding = 1;
|
|
19760
|
-
external2 = false;
|
|
19761
|
-
x2 = x2.times(x2).minus(1).sqrt().plus(x2);
|
|
19762
|
-
external2 = true;
|
|
19763
|
-
Ctor.precision = pr;
|
|
19764
|
-
Ctor.rounding = rm;
|
|
19765
|
-
return x2.ln();
|
|
19766
|
-
};
|
|
19767
|
-
P2.inverseHyperbolicSine = P2.asinh = function() {
|
|
19768
|
-
var pr, rm, x2 = this, Ctor = x2.constructor;
|
|
19769
|
-
if (!x2.isFinite() || x2.isZero())
|
|
19770
|
-
return new Ctor(x2);
|
|
19771
|
-
pr = Ctor.precision;
|
|
19772
|
-
rm = Ctor.rounding;
|
|
19773
|
-
Ctor.precision = pr + 2 * Math.max(Math.abs(x2.e), x2.sd()) + 6;
|
|
19774
|
-
Ctor.rounding = 1;
|
|
19775
|
-
external2 = false;
|
|
19776
|
-
x2 = x2.times(x2).plus(1).sqrt().plus(x2);
|
|
19777
|
-
external2 = true;
|
|
19778
|
-
Ctor.precision = pr;
|
|
19779
|
-
Ctor.rounding = rm;
|
|
19780
|
-
return x2.ln();
|
|
19781
|
-
};
|
|
19782
|
-
P2.inverseHyperbolicTangent = P2.atanh = function() {
|
|
19783
|
-
var pr, rm, wpr, xsd, x2 = this, Ctor = x2.constructor;
|
|
19784
|
-
if (!x2.isFinite())
|
|
19785
|
-
return new Ctor(NaN);
|
|
19786
|
-
if (x2.e >= 0)
|
|
19787
|
-
return new Ctor(x2.abs().eq(1) ? x2.s / 0 : x2.isZero() ? x2 : NaN);
|
|
19788
|
-
pr = Ctor.precision;
|
|
19789
|
-
rm = Ctor.rounding;
|
|
19790
|
-
xsd = x2.sd();
|
|
19791
|
-
if (Math.max(xsd, pr) < 2 * -x2.e - 1)
|
|
19792
|
-
return finalise(new Ctor(x2), pr, rm, true);
|
|
19793
|
-
Ctor.precision = wpr = xsd - x2.e;
|
|
19794
|
-
x2 = divide(x2.plus(1), new Ctor(1).minus(x2), wpr + pr, 1);
|
|
19795
|
-
Ctor.precision = pr + 4;
|
|
19796
|
-
Ctor.rounding = 1;
|
|
19797
|
-
x2 = x2.ln();
|
|
19798
|
-
Ctor.precision = pr;
|
|
19799
|
-
Ctor.rounding = rm;
|
|
19800
|
-
return x2.times(0.5);
|
|
19801
|
-
};
|
|
19802
|
-
P2.inverseSine = P2.asin = function() {
|
|
19803
|
-
var halfPi, k3, pr, rm, x2 = this, Ctor = x2.constructor;
|
|
19804
|
-
if (x2.isZero())
|
|
19805
|
-
return new Ctor(x2);
|
|
19806
|
-
k3 = x2.abs().cmp(1);
|
|
19807
|
-
pr = Ctor.precision;
|
|
19808
|
-
rm = Ctor.rounding;
|
|
19809
|
-
if (k3 !== -1) {
|
|
19810
|
-
if (k3 === 0) {
|
|
19811
|
-
halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
19812
|
-
halfPi.s = x2.s;
|
|
19813
|
-
return halfPi;
|
|
19814
|
-
}
|
|
19815
|
-
return new Ctor(NaN);
|
|
19816
|
-
}
|
|
19817
|
-
Ctor.precision = pr + 6;
|
|
19818
|
-
Ctor.rounding = 1;
|
|
19819
|
-
x2 = x2.div(new Ctor(1).minus(x2.times(x2)).sqrt().plus(1)).atan();
|
|
19820
|
-
Ctor.precision = pr;
|
|
19821
|
-
Ctor.rounding = rm;
|
|
19822
|
-
return x2.times(2);
|
|
19823
|
-
};
|
|
19824
|
-
P2.inverseTangent = P2.atan = function() {
|
|
19825
|
-
var i, j3, k3, n, px, t, r, wpr, x2, x3 = this, Ctor = x3.constructor, pr = Ctor.precision, rm = Ctor.rounding;
|
|
19826
|
-
if (!x3.isFinite()) {
|
|
19827
|
-
if (!x3.s)
|
|
19828
|
-
return new Ctor(NaN);
|
|
19829
|
-
if (pr + 4 <= PI_PRECISION) {
|
|
19830
|
-
r = getPi(Ctor, pr + 4, rm).times(0.5);
|
|
19831
|
-
r.s = x3.s;
|
|
19832
|
-
return r;
|
|
19833
|
-
}
|
|
19834
|
-
} else if (x3.isZero()) {
|
|
19835
|
-
return new Ctor(x3);
|
|
19836
|
-
} else if (x3.abs().eq(1) && pr + 4 <= PI_PRECISION) {
|
|
19837
|
-
r = getPi(Ctor, pr + 4, rm).times(0.25);
|
|
19838
|
-
r.s = x3.s;
|
|
19839
|
-
return r;
|
|
19840
|
-
}
|
|
19841
|
-
Ctor.precision = wpr = pr + 10;
|
|
19842
|
-
Ctor.rounding = 1;
|
|
19843
|
-
k3 = Math.min(28, wpr / LOG_BASE + 2 | 0);
|
|
19844
|
-
for (i = k3;i; --i)
|
|
19845
|
-
x3 = x3.div(x3.times(x3).plus(1).sqrt().plus(1));
|
|
19846
|
-
external2 = false;
|
|
19847
|
-
j3 = Math.ceil(wpr / LOG_BASE);
|
|
19848
|
-
n = 1;
|
|
19849
|
-
x2 = x3.times(x3);
|
|
19850
|
-
r = new Ctor(x3);
|
|
19851
|
-
px = x3;
|
|
19852
|
-
for (;i !== -1; ) {
|
|
19853
|
-
px = px.times(x2);
|
|
19854
|
-
t = r.minus(px.div(n += 2));
|
|
19855
|
-
px = px.times(x2);
|
|
19856
|
-
r = t.plus(px.div(n += 2));
|
|
19857
|
-
if (r.d[j3] !== undefined)
|
|
19858
|
-
for (i = j3;r.d[i] === t.d[i] && i--; )
|
|
19859
|
-
;
|
|
19860
|
-
}
|
|
19861
|
-
if (k3)
|
|
19862
|
-
r = r.times(2 << k3 - 1);
|
|
19863
|
-
external2 = true;
|
|
19864
|
-
return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
|
|
19865
|
-
};
|
|
19866
|
-
P2.isFinite = function() {
|
|
19867
|
-
return !!this.d;
|
|
19868
|
-
};
|
|
19869
|
-
P2.isInteger = P2.isInt = function() {
|
|
19870
|
-
return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
|
|
19871
|
-
};
|
|
19872
|
-
P2.isNaN = function() {
|
|
19873
|
-
return !this.s;
|
|
19874
|
-
};
|
|
19875
|
-
P2.isNegative = P2.isNeg = function() {
|
|
19876
|
-
return this.s < 0;
|
|
19877
|
-
};
|
|
19878
|
-
P2.isPositive = P2.isPos = function() {
|
|
19879
|
-
return this.s > 0;
|
|
19880
|
-
};
|
|
19881
|
-
P2.isZero = function() {
|
|
19882
|
-
return !!this.d && this.d[0] === 0;
|
|
19883
|
-
};
|
|
19884
|
-
P2.lessThan = P2.lt = function(y2) {
|
|
19885
|
-
return this.cmp(y2) < 0;
|
|
19886
|
-
};
|
|
19887
|
-
P2.lessThanOrEqualTo = P2.lte = function(y2) {
|
|
19888
|
-
return this.cmp(y2) < 1;
|
|
19889
|
-
};
|
|
19890
|
-
P2.logarithm = P2.log = function(base) {
|
|
19891
|
-
var isBase10, d, denominator, k3, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
|
|
19892
|
-
if (base == null) {
|
|
19893
|
-
base = new Ctor(10);
|
|
19894
|
-
isBase10 = true;
|
|
19895
|
-
} else {
|
|
19896
|
-
base = new Ctor(base);
|
|
19897
|
-
d = base.d;
|
|
19898
|
-
if (base.s < 0 || !d || !d[0] || base.eq(1))
|
|
19899
|
-
return new Ctor(NaN);
|
|
19900
|
-
isBase10 = base.eq(10);
|
|
19901
|
-
}
|
|
19902
|
-
d = arg.d;
|
|
19903
|
-
if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
|
|
19904
|
-
return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
|
|
19905
|
-
}
|
|
19906
|
-
if (isBase10) {
|
|
19907
|
-
if (d.length > 1) {
|
|
19908
|
-
inf = true;
|
|
19909
|
-
} else {
|
|
19910
|
-
for (k3 = d[0];k3 % 10 === 0; )
|
|
19911
|
-
k3 /= 10;
|
|
19912
|
-
inf = k3 !== 1;
|
|
19913
|
-
}
|
|
19914
|
-
}
|
|
19915
|
-
external2 = false;
|
|
19916
|
-
sd = pr + guard;
|
|
19917
|
-
num = naturalLogarithm(arg, sd);
|
|
19918
|
-
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
19919
|
-
r = divide(num, denominator, sd, 1);
|
|
19920
|
-
if (checkRoundingDigits(r.d, k3 = pr, rm)) {
|
|
19921
|
-
do {
|
|
19922
|
-
sd += 10;
|
|
19923
|
-
num = naturalLogarithm(arg, sd);
|
|
19924
|
-
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
19925
|
-
r = divide(num, denominator, sd, 1);
|
|
19926
|
-
if (!inf) {
|
|
19927
|
-
if (+digitsToString(r.d).slice(k3 + 1, k3 + 15) + 1 == 100000000000000) {
|
|
19928
|
-
r = finalise(r, pr + 1, 0);
|
|
19929
|
-
}
|
|
19930
|
-
break;
|
|
19931
|
-
}
|
|
19932
|
-
} while (checkRoundingDigits(r.d, k3 += 10, rm));
|
|
19933
|
-
}
|
|
19934
|
-
external2 = true;
|
|
19935
|
-
return finalise(r, pr, rm);
|
|
19936
|
-
};
|
|
19937
|
-
P2.minus = P2.sub = function(y2) {
|
|
19938
|
-
var d, e, i, j3, k3, len, pr, rm, xd, xe, xLTy, yd, x2 = this, Ctor = x2.constructor;
|
|
19939
|
-
y2 = new Ctor(y2);
|
|
19940
|
-
if (!x2.d || !y2.d) {
|
|
19941
|
-
if (!x2.s || !y2.s)
|
|
19942
|
-
y2 = new Ctor(NaN);
|
|
19943
|
-
else if (x2.d)
|
|
19944
|
-
y2.s = -y2.s;
|
|
19945
|
-
else
|
|
19946
|
-
y2 = new Ctor(y2.d || x2.s !== y2.s ? x2 : NaN);
|
|
19947
|
-
return y2;
|
|
19948
|
-
}
|
|
19949
|
-
if (x2.s != y2.s) {
|
|
19950
|
-
y2.s = -y2.s;
|
|
19951
|
-
return x2.plus(y2);
|
|
19952
|
-
}
|
|
19953
|
-
xd = x2.d;
|
|
19954
|
-
yd = y2.d;
|
|
19955
|
-
pr = Ctor.precision;
|
|
19956
|
-
rm = Ctor.rounding;
|
|
19957
|
-
if (!xd[0] || !yd[0]) {
|
|
19958
|
-
if (yd[0])
|
|
19959
|
-
y2.s = -y2.s;
|
|
19960
|
-
else if (xd[0])
|
|
19961
|
-
y2 = new Ctor(x2);
|
|
19962
|
-
else
|
|
19963
|
-
return new Ctor(rm === 3 ? -0 : 0);
|
|
19964
|
-
return external2 ? finalise(y2, pr, rm) : y2;
|
|
19965
|
-
}
|
|
19966
|
-
e = mathfloor(y2.e / LOG_BASE);
|
|
19967
|
-
xe = mathfloor(x2.e / LOG_BASE);
|
|
19968
|
-
xd = xd.slice();
|
|
19969
|
-
k3 = xe - e;
|
|
19970
|
-
if (k3) {
|
|
19971
|
-
xLTy = k3 < 0;
|
|
19972
|
-
if (xLTy) {
|
|
19973
|
-
d = xd;
|
|
19974
|
-
k3 = -k3;
|
|
19975
|
-
len = yd.length;
|
|
19976
|
-
} else {
|
|
19977
|
-
d = yd;
|
|
19978
|
-
e = xe;
|
|
19979
|
-
len = xd.length;
|
|
19980
|
-
}
|
|
19981
|
-
i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
|
|
19982
|
-
if (k3 > i) {
|
|
19983
|
-
k3 = i;
|
|
19984
|
-
d.length = 1;
|
|
19985
|
-
}
|
|
19986
|
-
d.reverse();
|
|
19987
|
-
for (i = k3;i--; )
|
|
19988
|
-
d.push(0);
|
|
19989
|
-
d.reverse();
|
|
19990
|
-
} else {
|
|
19991
|
-
i = xd.length;
|
|
19992
|
-
len = yd.length;
|
|
19993
|
-
xLTy = i < len;
|
|
19994
|
-
if (xLTy)
|
|
19995
|
-
len = i;
|
|
19996
|
-
for (i = 0;i < len; i++) {
|
|
19997
|
-
if (xd[i] != yd[i]) {
|
|
19998
|
-
xLTy = xd[i] < yd[i];
|
|
19999
|
-
break;
|
|
20000
|
-
}
|
|
20001
|
-
}
|
|
20002
|
-
k3 = 0;
|
|
20003
|
-
}
|
|
20004
|
-
if (xLTy) {
|
|
20005
|
-
d = xd;
|
|
20006
|
-
xd = yd;
|
|
20007
|
-
yd = d;
|
|
20008
|
-
y2.s = -y2.s;
|
|
20009
|
-
}
|
|
20010
|
-
len = xd.length;
|
|
20011
|
-
for (i = yd.length - len;i > 0; --i)
|
|
20012
|
-
xd[len++] = 0;
|
|
20013
|
-
for (i = yd.length;i > k3; ) {
|
|
20014
|
-
if (xd[--i] < yd[i]) {
|
|
20015
|
-
for (j3 = i;j3 && xd[--j3] === 0; )
|
|
20016
|
-
xd[j3] = BASE - 1;
|
|
20017
|
-
--xd[j3];
|
|
20018
|
-
xd[i] += BASE;
|
|
20019
|
-
}
|
|
20020
|
-
xd[i] -= yd[i];
|
|
20021
|
-
}
|
|
20022
|
-
for (;xd[--len] === 0; )
|
|
20023
|
-
xd.pop();
|
|
20024
|
-
for (;xd[0] === 0; xd.shift())
|
|
20025
|
-
--e;
|
|
20026
|
-
if (!xd[0])
|
|
20027
|
-
return new Ctor(rm === 3 ? -0 : 0);
|
|
20028
|
-
y2.d = xd;
|
|
20029
|
-
y2.e = getBase10Exponent(xd, e);
|
|
20030
|
-
return external2 ? finalise(y2, pr, rm) : y2;
|
|
20031
|
-
};
|
|
20032
|
-
P2.modulo = P2.mod = function(y2) {
|
|
20033
|
-
var q, x2 = this, Ctor = x2.constructor;
|
|
20034
|
-
y2 = new Ctor(y2);
|
|
20035
|
-
if (!x2.d || !y2.s || y2.d && !y2.d[0])
|
|
20036
|
-
return new Ctor(NaN);
|
|
20037
|
-
if (!y2.d || x2.d && !x2.d[0]) {
|
|
20038
|
-
return finalise(new Ctor(x2), Ctor.precision, Ctor.rounding);
|
|
20039
|
-
}
|
|
20040
|
-
external2 = false;
|
|
20041
|
-
if (Ctor.modulo == 9) {
|
|
20042
|
-
q = divide(x2, y2.abs(), 0, 3, 1);
|
|
20043
|
-
q.s *= y2.s;
|
|
20044
|
-
} else {
|
|
20045
|
-
q = divide(x2, y2, 0, Ctor.modulo, 1);
|
|
20046
|
-
}
|
|
20047
|
-
q = q.times(y2);
|
|
20048
|
-
external2 = true;
|
|
20049
|
-
return x2.minus(q);
|
|
20050
|
-
};
|
|
20051
|
-
P2.naturalExponential = P2.exp = function() {
|
|
20052
|
-
return naturalExponential(this);
|
|
20053
|
-
};
|
|
20054
|
-
P2.naturalLogarithm = P2.ln = function() {
|
|
20055
|
-
return naturalLogarithm(this);
|
|
20056
|
-
};
|
|
20057
|
-
P2.negated = P2.neg = function() {
|
|
20058
|
-
var x2 = new this.constructor(this);
|
|
20059
|
-
x2.s = -x2.s;
|
|
20060
|
-
return finalise(x2);
|
|
20061
|
-
};
|
|
20062
|
-
P2.plus = P2.add = function(y2) {
|
|
20063
|
-
var carry, d, e, i, k3, len, pr, rm, xd, yd, x2 = this, Ctor = x2.constructor;
|
|
20064
|
-
y2 = new Ctor(y2);
|
|
20065
|
-
if (!x2.d || !y2.d) {
|
|
20066
|
-
if (!x2.s || !y2.s)
|
|
20067
|
-
y2 = new Ctor(NaN);
|
|
20068
|
-
else if (!x2.d)
|
|
20069
|
-
y2 = new Ctor(y2.d || x2.s === y2.s ? x2 : NaN);
|
|
20070
|
-
return y2;
|
|
20071
|
-
}
|
|
20072
|
-
if (x2.s != y2.s) {
|
|
20073
|
-
y2.s = -y2.s;
|
|
20074
|
-
return x2.minus(y2);
|
|
20075
|
-
}
|
|
20076
|
-
xd = x2.d;
|
|
20077
|
-
yd = y2.d;
|
|
20078
|
-
pr = Ctor.precision;
|
|
20079
|
-
rm = Ctor.rounding;
|
|
20080
|
-
if (!xd[0] || !yd[0]) {
|
|
20081
|
-
if (!yd[0])
|
|
20082
|
-
y2 = new Ctor(x2);
|
|
20083
|
-
return external2 ? finalise(y2, pr, rm) : y2;
|
|
20084
|
-
}
|
|
20085
|
-
k3 = mathfloor(x2.e / LOG_BASE);
|
|
20086
|
-
e = mathfloor(y2.e / LOG_BASE);
|
|
20087
|
-
xd = xd.slice();
|
|
20088
|
-
i = k3 - e;
|
|
20089
|
-
if (i) {
|
|
20090
|
-
if (i < 0) {
|
|
20091
|
-
d = xd;
|
|
20092
|
-
i = -i;
|
|
20093
|
-
len = yd.length;
|
|
20094
|
-
} else {
|
|
20095
|
-
d = yd;
|
|
20096
|
-
e = k3;
|
|
20097
|
-
len = xd.length;
|
|
20098
|
-
}
|
|
20099
|
-
k3 = Math.ceil(pr / LOG_BASE);
|
|
20100
|
-
len = k3 > len ? k3 + 1 : len + 1;
|
|
20101
|
-
if (i > len) {
|
|
20102
|
-
i = len;
|
|
20103
|
-
d.length = 1;
|
|
20104
|
-
}
|
|
20105
|
-
d.reverse();
|
|
20106
|
-
for (;i--; )
|
|
20107
|
-
d.push(0);
|
|
20108
|
-
d.reverse();
|
|
20109
|
-
}
|
|
20110
|
-
len = xd.length;
|
|
20111
|
-
i = yd.length;
|
|
20112
|
-
if (len - i < 0) {
|
|
20113
|
-
i = len;
|
|
20114
|
-
d = yd;
|
|
20115
|
-
yd = xd;
|
|
20116
|
-
xd = d;
|
|
20117
|
-
}
|
|
20118
|
-
for (carry = 0;i; ) {
|
|
20119
|
-
carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
|
|
20120
|
-
xd[i] %= BASE;
|
|
20121
|
-
}
|
|
20122
|
-
if (carry) {
|
|
20123
|
-
xd.unshift(carry);
|
|
20124
|
-
++e;
|
|
20125
|
-
}
|
|
20126
|
-
for (len = xd.length;xd[--len] == 0; )
|
|
20127
|
-
xd.pop();
|
|
20128
|
-
y2.d = xd;
|
|
20129
|
-
y2.e = getBase10Exponent(xd, e);
|
|
20130
|
-
return external2 ? finalise(y2, pr, rm) : y2;
|
|
20131
|
-
};
|
|
20132
|
-
P2.precision = P2.sd = function(z) {
|
|
20133
|
-
var k3, x2 = this;
|
|
20134
|
-
if (z !== undefined && z !== !!z && z !== 1 && z !== 0)
|
|
20135
|
-
throw Error(invalidArgument + z);
|
|
20136
|
-
if (x2.d) {
|
|
20137
|
-
k3 = getPrecision(x2.d);
|
|
20138
|
-
if (z && x2.e + 1 > k3)
|
|
20139
|
-
k3 = x2.e + 1;
|
|
20140
|
-
} else {
|
|
20141
|
-
k3 = NaN;
|
|
20142
|
-
}
|
|
20143
|
-
return k3;
|
|
20144
|
-
};
|
|
20145
|
-
P2.round = function() {
|
|
20146
|
-
var x2 = this, Ctor = x2.constructor;
|
|
20147
|
-
return finalise(new Ctor(x2), x2.e + 1, Ctor.rounding);
|
|
20148
|
-
};
|
|
20149
|
-
P2.sine = P2.sin = function() {
|
|
20150
|
-
var pr, rm, x2 = this, Ctor = x2.constructor;
|
|
20151
|
-
if (!x2.isFinite())
|
|
20152
|
-
return new Ctor(NaN);
|
|
20153
|
-
if (x2.isZero())
|
|
20154
|
-
return new Ctor(x2);
|
|
20155
|
-
pr = Ctor.precision;
|
|
20156
|
-
rm = Ctor.rounding;
|
|
20157
|
-
Ctor.precision = pr + Math.max(x2.e, x2.sd()) + LOG_BASE;
|
|
20158
|
-
Ctor.rounding = 1;
|
|
20159
|
-
x2 = sine(Ctor, toLessThanHalfPi(Ctor, x2));
|
|
20160
|
-
Ctor.precision = pr;
|
|
20161
|
-
Ctor.rounding = rm;
|
|
20162
|
-
return finalise(quadrant > 2 ? x2.neg() : x2, pr, rm, true);
|
|
20163
|
-
};
|
|
20164
|
-
P2.squareRoot = P2.sqrt = function() {
|
|
20165
|
-
var m2, n, sd, r, rep, t, x2 = this, d = x2.d, e = x2.e, s = x2.s, Ctor = x2.constructor;
|
|
20166
|
-
if (s !== 1 || !d || !d[0]) {
|
|
20167
|
-
return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x2 : 1 / 0);
|
|
20168
|
-
}
|
|
20169
|
-
external2 = false;
|
|
20170
|
-
s = Math.sqrt(+x2);
|
|
20171
|
-
if (s == 0 || s == 1 / 0) {
|
|
20172
|
-
n = digitsToString(d);
|
|
20173
|
-
if ((n.length + e) % 2 == 0)
|
|
20174
|
-
n += "0";
|
|
20175
|
-
s = Math.sqrt(n);
|
|
20176
|
-
e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
20177
|
-
if (s == 1 / 0) {
|
|
20178
|
-
n = "5e" + e;
|
|
20179
|
-
} else {
|
|
20180
|
-
n = s.toExponential();
|
|
20181
|
-
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
20182
|
-
}
|
|
20183
|
-
r = new Ctor(n);
|
|
20184
|
-
} else {
|
|
20185
|
-
r = new Ctor(s.toString());
|
|
20186
|
-
}
|
|
20187
|
-
sd = (e = Ctor.precision) + 3;
|
|
20188
|
-
for (;; ) {
|
|
20189
|
-
t = r;
|
|
20190
|
-
r = t.plus(divide(x2, t, sd + 2, 1)).times(0.5);
|
|
20191
|
-
if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
|
20192
|
-
n = n.slice(sd - 3, sd + 1);
|
|
20193
|
-
if (n == "9999" || !rep && n == "4999") {
|
|
20194
|
-
if (!rep) {
|
|
20195
|
-
finalise(t, e + 1, 0);
|
|
20196
|
-
if (t.times(t).eq(x2)) {
|
|
20197
|
-
r = t;
|
|
20198
|
-
break;
|
|
20199
|
-
}
|
|
20200
|
-
}
|
|
20201
|
-
sd += 4;
|
|
20202
|
-
rep = 1;
|
|
20203
|
-
} else {
|
|
20204
|
-
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
20205
|
-
finalise(r, e + 1, 1);
|
|
20206
|
-
m2 = !r.times(r).eq(x2);
|
|
20207
|
-
}
|
|
20208
|
-
break;
|
|
20209
|
-
}
|
|
20210
|
-
}
|
|
20211
|
-
}
|
|
20212
|
-
external2 = true;
|
|
20213
|
-
return finalise(r, e, Ctor.rounding, m2);
|
|
20214
|
-
};
|
|
20215
|
-
P2.tangent = P2.tan = function() {
|
|
20216
|
-
var pr, rm, x2 = this, Ctor = x2.constructor;
|
|
20217
|
-
if (!x2.isFinite())
|
|
20218
|
-
return new Ctor(NaN);
|
|
20219
|
-
if (x2.isZero())
|
|
20220
|
-
return new Ctor(x2);
|
|
20221
|
-
pr = Ctor.precision;
|
|
20222
|
-
rm = Ctor.rounding;
|
|
20223
|
-
Ctor.precision = pr + 10;
|
|
20224
|
-
Ctor.rounding = 1;
|
|
20225
|
-
x2 = x2.sin();
|
|
20226
|
-
x2.s = 1;
|
|
20227
|
-
x2 = divide(x2, new Ctor(1).minus(x2.times(x2)).sqrt(), pr + 10, 0);
|
|
20228
|
-
Ctor.precision = pr;
|
|
20229
|
-
Ctor.rounding = rm;
|
|
20230
|
-
return finalise(quadrant == 2 || quadrant == 4 ? x2.neg() : x2, pr, rm, true);
|
|
20231
|
-
};
|
|
20232
|
-
P2.times = P2.mul = function(y2) {
|
|
20233
|
-
var carry, e, i, k3, r, rL, t, xdL, ydL, x2 = this, Ctor = x2.constructor, xd = x2.d, yd = (y2 = new Ctor(y2)).d;
|
|
20234
|
-
y2.s *= x2.s;
|
|
20235
|
-
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
20236
|
-
return new Ctor(!y2.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y2.s / 0 : y2.s * 0);
|
|
20237
|
-
}
|
|
20238
|
-
e = mathfloor(x2.e / LOG_BASE) + mathfloor(y2.e / LOG_BASE);
|
|
20239
|
-
xdL = xd.length;
|
|
20240
|
-
ydL = yd.length;
|
|
20241
|
-
if (xdL < ydL) {
|
|
20242
|
-
r = xd;
|
|
20243
|
-
xd = yd;
|
|
20244
|
-
yd = r;
|
|
20245
|
-
rL = xdL;
|
|
20246
|
-
xdL = ydL;
|
|
20247
|
-
ydL = rL;
|
|
20248
|
-
}
|
|
20249
|
-
r = [];
|
|
20250
|
-
rL = xdL + ydL;
|
|
20251
|
-
for (i = rL;i--; )
|
|
20252
|
-
r.push(0);
|
|
20253
|
-
for (i = ydL;--i >= 0; ) {
|
|
20254
|
-
carry = 0;
|
|
20255
|
-
for (k3 = xdL + i;k3 > i; ) {
|
|
20256
|
-
t = r[k3] + yd[i] * xd[k3 - i - 1] + carry;
|
|
20257
|
-
r[k3--] = t % BASE | 0;
|
|
20258
|
-
carry = t / BASE | 0;
|
|
20259
|
-
}
|
|
20260
|
-
r[k3] = (r[k3] + carry) % BASE | 0;
|
|
20261
|
-
}
|
|
20262
|
-
for (;!r[--rL]; )
|
|
20263
|
-
r.pop();
|
|
20264
|
-
if (carry)
|
|
20265
|
-
++e;
|
|
20266
|
-
else
|
|
20267
|
-
r.shift();
|
|
20268
|
-
y2.d = r;
|
|
20269
|
-
y2.e = getBase10Exponent(r, e);
|
|
20270
|
-
return external2 ? finalise(y2, Ctor.precision, Ctor.rounding) : y2;
|
|
20271
|
-
};
|
|
20272
|
-
P2.toBinary = function(sd, rm) {
|
|
20273
|
-
return toStringBinary(this, 2, sd, rm);
|
|
20274
|
-
};
|
|
20275
|
-
P2.toDecimalPlaces = P2.toDP = function(dp, rm) {
|
|
20276
|
-
var x2 = this, Ctor = x2.constructor;
|
|
20277
|
-
x2 = new Ctor(x2);
|
|
20278
|
-
if (dp === undefined)
|
|
20279
|
-
return x2;
|
|
20280
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
20281
|
-
if (rm === undefined)
|
|
20282
|
-
rm = Ctor.rounding;
|
|
20283
|
-
else
|
|
20284
|
-
checkInt32(rm, 0, 8);
|
|
20285
|
-
return finalise(x2, dp + x2.e + 1, rm);
|
|
20286
|
-
};
|
|
20287
|
-
P2.toExponential = function(dp, rm) {
|
|
20288
|
-
var str, x2 = this, Ctor = x2.constructor;
|
|
20289
|
-
if (dp === undefined) {
|
|
20290
|
-
str = finiteToString(x2, true);
|
|
20291
|
-
} else {
|
|
20292
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
20293
|
-
if (rm === undefined)
|
|
20294
|
-
rm = Ctor.rounding;
|
|
20295
|
-
else
|
|
20296
|
-
checkInt32(rm, 0, 8);
|
|
20297
|
-
x2 = finalise(new Ctor(x2), dp + 1, rm);
|
|
20298
|
-
str = finiteToString(x2, true, dp + 1);
|
|
20299
|
-
}
|
|
20300
|
-
return x2.isNeg() && !x2.isZero() ? "-" + str : str;
|
|
20301
|
-
};
|
|
20302
|
-
P2.toFixed = function(dp, rm) {
|
|
20303
|
-
var str, y2, x2 = this, Ctor = x2.constructor;
|
|
20304
|
-
if (dp === undefined) {
|
|
20305
|
-
str = finiteToString(x2);
|
|
20306
|
-
} else {
|
|
20307
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
20308
|
-
if (rm === undefined)
|
|
20309
|
-
rm = Ctor.rounding;
|
|
20310
|
-
else
|
|
20311
|
-
checkInt32(rm, 0, 8);
|
|
20312
|
-
y2 = finalise(new Ctor(x2), dp + x2.e + 1, rm);
|
|
20313
|
-
str = finiteToString(y2, false, dp + y2.e + 1);
|
|
20314
|
-
}
|
|
20315
|
-
return x2.isNeg() && !x2.isZero() ? "-" + str : str;
|
|
20316
|
-
};
|
|
20317
|
-
P2.toFraction = function(maxD) {
|
|
20318
|
-
var d, d0, d1, d2, e, k3, n, n0, n1, pr, q, r, x2 = this, xd = x2.d, Ctor = x2.constructor;
|
|
20319
|
-
if (!xd)
|
|
20320
|
-
return new Ctor(x2);
|
|
20321
|
-
n1 = d0 = new Ctor(1);
|
|
20322
|
-
d1 = n0 = new Ctor(0);
|
|
20323
|
-
d = new Ctor(d1);
|
|
20324
|
-
e = d.e = getPrecision(xd) - x2.e - 1;
|
|
20325
|
-
k3 = e % LOG_BASE;
|
|
20326
|
-
d.d[0] = mathpow(10, k3 < 0 ? LOG_BASE + k3 : k3);
|
|
20327
|
-
if (maxD == null) {
|
|
20328
|
-
maxD = e > 0 ? d : n1;
|
|
20329
|
-
} else {
|
|
20330
|
-
n = new Ctor(maxD);
|
|
20331
|
-
if (!n.isInt() || n.lt(n1))
|
|
20332
|
-
throw Error(invalidArgument + n);
|
|
20333
|
-
maxD = n.gt(d) ? e > 0 ? d : n1 : n;
|
|
20334
|
-
}
|
|
20335
|
-
external2 = false;
|
|
20336
|
-
n = new Ctor(digitsToString(xd));
|
|
20337
|
-
pr = Ctor.precision;
|
|
20338
|
-
Ctor.precision = e = xd.length * LOG_BASE * 2;
|
|
20339
|
-
for (;; ) {
|
|
20340
|
-
q = divide(n, d, 0, 1, 1);
|
|
20341
|
-
d2 = d0.plus(q.times(d1));
|
|
20342
|
-
if (d2.cmp(maxD) == 1)
|
|
20343
|
-
break;
|
|
20344
|
-
d0 = d1;
|
|
20345
|
-
d1 = d2;
|
|
20346
|
-
d2 = n1;
|
|
20347
|
-
n1 = n0.plus(q.times(d2));
|
|
20348
|
-
n0 = d2;
|
|
20349
|
-
d2 = d;
|
|
20350
|
-
d = n.minus(q.times(d2));
|
|
20351
|
-
n = d2;
|
|
20352
|
-
}
|
|
20353
|
-
d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
|
|
20354
|
-
n0 = n0.plus(d2.times(n1));
|
|
20355
|
-
d0 = d0.plus(d2.times(d1));
|
|
20356
|
-
n0.s = n1.s = x2.s;
|
|
20357
|
-
r = divide(n1, d1, e, 1).minus(x2).abs().cmp(divide(n0, d0, e, 1).minus(x2).abs()) < 1 ? [n1, d1] : [n0, d0];
|
|
20358
|
-
Ctor.precision = pr;
|
|
20359
|
-
external2 = true;
|
|
20360
|
-
return r;
|
|
20361
|
-
};
|
|
20362
|
-
P2.toHexadecimal = P2.toHex = function(sd, rm) {
|
|
20363
|
-
return toStringBinary(this, 16, sd, rm);
|
|
20364
|
-
};
|
|
20365
|
-
P2.toNearest = function(y2, rm) {
|
|
20366
|
-
var x2 = this, Ctor = x2.constructor;
|
|
20367
|
-
x2 = new Ctor(x2);
|
|
20368
|
-
if (y2 == null) {
|
|
20369
|
-
if (!x2.d)
|
|
20370
|
-
return x2;
|
|
20371
|
-
y2 = new Ctor(1);
|
|
20372
|
-
rm = Ctor.rounding;
|
|
20373
|
-
} else {
|
|
20374
|
-
y2 = new Ctor(y2);
|
|
20375
|
-
if (rm === undefined) {
|
|
20376
|
-
rm = Ctor.rounding;
|
|
20377
|
-
} else {
|
|
20378
|
-
checkInt32(rm, 0, 8);
|
|
20379
|
-
}
|
|
20380
|
-
if (!x2.d)
|
|
20381
|
-
return y2.s ? x2 : y2;
|
|
20382
|
-
if (!y2.d) {
|
|
20383
|
-
if (y2.s)
|
|
20384
|
-
y2.s = x2.s;
|
|
20385
|
-
return y2;
|
|
20386
|
-
}
|
|
20387
|
-
}
|
|
20388
|
-
if (y2.d[0]) {
|
|
20389
|
-
external2 = false;
|
|
20390
|
-
x2 = divide(x2, y2, 0, rm, 1).times(y2);
|
|
20391
|
-
external2 = true;
|
|
20392
|
-
finalise(x2);
|
|
20393
|
-
} else {
|
|
20394
|
-
y2.s = x2.s;
|
|
20395
|
-
x2 = y2;
|
|
20396
|
-
}
|
|
20397
|
-
return x2;
|
|
20398
|
-
};
|
|
20399
|
-
P2.toNumber = function() {
|
|
20400
|
-
return +this;
|
|
20401
|
-
};
|
|
20402
|
-
P2.toOctal = function(sd, rm) {
|
|
20403
|
-
return toStringBinary(this, 8, sd, rm);
|
|
20404
|
-
};
|
|
20405
|
-
P2.toPower = P2.pow = function(y2) {
|
|
20406
|
-
var e, k3, pr, r, rm, s, x2 = this, Ctor = x2.constructor, yn = +(y2 = new Ctor(y2));
|
|
20407
|
-
if (!x2.d || !y2.d || !x2.d[0] || !y2.d[0])
|
|
20408
|
-
return new Ctor(mathpow(+x2, yn));
|
|
20409
|
-
x2 = new Ctor(x2);
|
|
20410
|
-
if (x2.eq(1))
|
|
20411
|
-
return x2;
|
|
20412
|
-
pr = Ctor.precision;
|
|
20413
|
-
rm = Ctor.rounding;
|
|
20414
|
-
if (y2.eq(1))
|
|
20415
|
-
return finalise(x2, pr, rm);
|
|
20416
|
-
e = mathfloor(y2.e / LOG_BASE);
|
|
20417
|
-
if (e >= y2.d.length - 1 && (k3 = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
|
|
20418
|
-
r = intPow(Ctor, x2, k3, pr);
|
|
20419
|
-
return y2.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
|
|
20420
|
-
}
|
|
20421
|
-
s = x2.s;
|
|
20422
|
-
if (s < 0) {
|
|
20423
|
-
if (e < y2.d.length - 1)
|
|
20424
|
-
return new Ctor(NaN);
|
|
20425
|
-
if ((y2.d[e] & 1) == 0)
|
|
20426
|
-
s = 1;
|
|
20427
|
-
if (x2.e == 0 && x2.d[0] == 1 && x2.d.length == 1) {
|
|
20428
|
-
x2.s = s;
|
|
20429
|
-
return x2;
|
|
20430
|
-
}
|
|
20431
|
-
}
|
|
20432
|
-
k3 = mathpow(+x2, yn);
|
|
20433
|
-
e = k3 == 0 || !isFinite(k3) ? mathfloor(yn * (Math.log("0." + digitsToString(x2.d)) / Math.LN10 + x2.e + 1)) : new Ctor(k3 + "").e;
|
|
20434
|
-
if (e > Ctor.maxE + 1 || e < Ctor.minE - 1)
|
|
20435
|
-
return new Ctor(e > 0 ? s / 0 : 0);
|
|
20436
|
-
external2 = false;
|
|
20437
|
-
Ctor.rounding = x2.s = 1;
|
|
20438
|
-
k3 = Math.min(12, (e + "").length);
|
|
20439
|
-
r = naturalExponential(y2.times(naturalLogarithm(x2, pr + k3)), pr);
|
|
20440
|
-
if (r.d) {
|
|
20441
|
-
r = finalise(r, pr + 5, 1);
|
|
20442
|
-
if (checkRoundingDigits(r.d, pr, rm)) {
|
|
20443
|
-
e = pr + 10;
|
|
20444
|
-
r = finalise(naturalExponential(y2.times(naturalLogarithm(x2, e + k3)), e), e + 5, 1);
|
|
20445
|
-
if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 100000000000000) {
|
|
20446
|
-
r = finalise(r, pr + 1, 0);
|
|
20447
|
-
}
|
|
20448
|
-
}
|
|
20449
|
-
}
|
|
20450
|
-
r.s = s;
|
|
20451
|
-
external2 = true;
|
|
20452
|
-
Ctor.rounding = rm;
|
|
20453
|
-
return finalise(r, pr, rm);
|
|
20454
|
-
};
|
|
20455
|
-
P2.toPrecision = function(sd, rm) {
|
|
20456
|
-
var str, x2 = this, Ctor = x2.constructor;
|
|
20457
|
-
if (sd === undefined) {
|
|
20458
|
-
str = finiteToString(x2, x2.e <= Ctor.toExpNeg || x2.e >= Ctor.toExpPos);
|
|
20459
|
-
} else {
|
|
20460
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
20461
|
-
if (rm === undefined)
|
|
20462
|
-
rm = Ctor.rounding;
|
|
20463
|
-
else
|
|
20464
|
-
checkInt32(rm, 0, 8);
|
|
20465
|
-
x2 = finalise(new Ctor(x2), sd, rm);
|
|
20466
|
-
str = finiteToString(x2, sd <= x2.e || x2.e <= Ctor.toExpNeg, sd);
|
|
20467
|
-
}
|
|
20468
|
-
return x2.isNeg() && !x2.isZero() ? "-" + str : str;
|
|
20469
|
-
};
|
|
20470
|
-
P2.toSignificantDigits = P2.toSD = function(sd, rm) {
|
|
20471
|
-
var x2 = this, Ctor = x2.constructor;
|
|
20472
|
-
if (sd === undefined) {
|
|
20473
|
-
sd = Ctor.precision;
|
|
20474
|
-
rm = Ctor.rounding;
|
|
20475
|
-
} else {
|
|
20476
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
20477
|
-
if (rm === undefined)
|
|
20478
|
-
rm = Ctor.rounding;
|
|
20479
|
-
else
|
|
20480
|
-
checkInt32(rm, 0, 8);
|
|
20481
|
-
}
|
|
20482
|
-
return finalise(new Ctor(x2), sd, rm);
|
|
20483
|
-
};
|
|
20484
|
-
P2.toString = function() {
|
|
20485
|
-
var x2 = this, Ctor = x2.constructor, str = finiteToString(x2, x2.e <= Ctor.toExpNeg || x2.e >= Ctor.toExpPos);
|
|
20486
|
-
return x2.isNeg() && !x2.isZero() ? "-" + str : str;
|
|
20487
|
-
};
|
|
20488
|
-
P2.truncated = P2.trunc = function() {
|
|
20489
|
-
return finalise(new this.constructor(this), this.e + 1, 1);
|
|
20490
|
-
};
|
|
20491
|
-
P2.valueOf = P2.toJSON = function() {
|
|
20492
|
-
var x2 = this, Ctor = x2.constructor, str = finiteToString(x2, x2.e <= Ctor.toExpNeg || x2.e >= Ctor.toExpPos);
|
|
20493
|
-
return x2.isNeg() ? "-" + str : str;
|
|
20494
|
-
};
|
|
20495
|
-
function digitsToString(d) {
|
|
20496
|
-
var i, k3, ws, indexOfLastWord = d.length - 1, str = "", w2 = d[0];
|
|
20497
|
-
if (indexOfLastWord > 0) {
|
|
20498
|
-
str += w2;
|
|
20499
|
-
for (i = 1;i < indexOfLastWord; i++) {
|
|
20500
|
-
ws = d[i] + "";
|
|
20501
|
-
k3 = LOG_BASE - ws.length;
|
|
20502
|
-
if (k3)
|
|
20503
|
-
str += getZeroString(k3);
|
|
20504
|
-
str += ws;
|
|
20505
|
-
}
|
|
20506
|
-
w2 = d[i];
|
|
20507
|
-
ws = w2 + "";
|
|
20508
|
-
k3 = LOG_BASE - ws.length;
|
|
20509
|
-
if (k3)
|
|
20510
|
-
str += getZeroString(k3);
|
|
20511
|
-
} else if (w2 === 0) {
|
|
20512
|
-
return "0";
|
|
20513
|
-
}
|
|
20514
|
-
for (;w2 % 10 === 0; )
|
|
20515
|
-
w2 /= 10;
|
|
20516
|
-
return str + w2;
|
|
20517
|
-
}
|
|
20518
|
-
function checkInt32(i, min, max) {
|
|
20519
|
-
if (i !== ~~i || i < min || i > max) {
|
|
20520
|
-
throw Error(invalidArgument + i);
|
|
20521
|
-
}
|
|
20522
|
-
}
|
|
20523
|
-
function checkRoundingDigits(d, i, rm, repeating) {
|
|
20524
|
-
var di, k3, r, rd;
|
|
20525
|
-
for (k3 = d[0];k3 >= 10; k3 /= 10)
|
|
20526
|
-
--i;
|
|
20527
|
-
if (--i < 0) {
|
|
20528
|
-
i += LOG_BASE;
|
|
20529
|
-
di = 0;
|
|
20530
|
-
} else {
|
|
20531
|
-
di = Math.ceil((i + 1) / LOG_BASE);
|
|
20532
|
-
i %= LOG_BASE;
|
|
20533
|
-
}
|
|
20534
|
-
k3 = mathpow(10, LOG_BASE - i);
|
|
20535
|
-
rd = d[di] % k3 | 0;
|
|
20536
|
-
if (repeating == null) {
|
|
20537
|
-
if (i < 3) {
|
|
20538
|
-
if (i == 0)
|
|
20539
|
-
rd = rd / 100 | 0;
|
|
20540
|
-
else if (i == 1)
|
|
20541
|
-
rd = rd / 10 | 0;
|
|
20542
|
-
r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 50000 || rd == 0;
|
|
20543
|
-
} else {
|
|
20544
|
-
r = (rm < 4 && rd + 1 == k3 || rm > 3 && rd + 1 == k3 / 2) && (d[di + 1] / k3 / 100 | 0) == mathpow(10, i - 2) - 1 || (rd == k3 / 2 || rd == 0) && (d[di + 1] / k3 / 100 | 0) == 0;
|
|
20545
|
-
}
|
|
20546
|
-
} else {
|
|
20547
|
-
if (i < 4) {
|
|
20548
|
-
if (i == 0)
|
|
20549
|
-
rd = rd / 1000 | 0;
|
|
20550
|
-
else if (i == 1)
|
|
20551
|
-
rd = rd / 100 | 0;
|
|
20552
|
-
else if (i == 2)
|
|
20553
|
-
rd = rd / 10 | 0;
|
|
20554
|
-
r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
|
|
20555
|
-
} else {
|
|
20556
|
-
r = ((repeating || rm < 4) && rd + 1 == k3 || !repeating && rm > 3 && rd + 1 == k3 / 2) && (d[di + 1] / k3 / 1000 | 0) == mathpow(10, i - 3) - 1;
|
|
20557
|
-
}
|
|
20558
|
-
}
|
|
20559
|
-
return r;
|
|
20560
|
-
}
|
|
20561
|
-
function convertBase(str, baseIn, baseOut) {
|
|
20562
|
-
var j3, arr = [0], arrL, i = 0, strL = str.length;
|
|
20563
|
-
for (;i < strL; ) {
|
|
20564
|
-
for (arrL = arr.length;arrL--; )
|
|
20565
|
-
arr[arrL] *= baseIn;
|
|
20566
|
-
arr[0] += NUMERALS.indexOf(str.charAt(i++));
|
|
20567
|
-
for (j3 = 0;j3 < arr.length; j3++) {
|
|
20568
|
-
if (arr[j3] > baseOut - 1) {
|
|
20569
|
-
if (arr[j3 + 1] === undefined)
|
|
20570
|
-
arr[j3 + 1] = 0;
|
|
20571
|
-
arr[j3 + 1] += arr[j3] / baseOut | 0;
|
|
20572
|
-
arr[j3] %= baseOut;
|
|
20573
|
-
}
|
|
20574
|
-
}
|
|
20575
|
-
}
|
|
20576
|
-
return arr.reverse();
|
|
20577
|
-
}
|
|
20578
|
-
function cosine(Ctor, x2) {
|
|
20579
|
-
var k3, len, y2;
|
|
20580
|
-
if (x2.isZero())
|
|
20581
|
-
return x2;
|
|
20582
|
-
len = x2.d.length;
|
|
20583
|
-
if (len < 32) {
|
|
20584
|
-
k3 = Math.ceil(len / 3);
|
|
20585
|
-
y2 = (1 / tinyPow(4, k3)).toString();
|
|
20586
|
-
} else {
|
|
20587
|
-
k3 = 16;
|
|
20588
|
-
y2 = "2.3283064365386962890625e-10";
|
|
20589
|
-
}
|
|
20590
|
-
Ctor.precision += k3;
|
|
20591
|
-
x2 = taylorSeries(Ctor, 1, x2.times(y2), new Ctor(1));
|
|
20592
|
-
for (var i = k3;i--; ) {
|
|
20593
|
-
var cos2x = x2.times(x2);
|
|
20594
|
-
x2 = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
|
|
20595
|
-
}
|
|
20596
|
-
Ctor.precision -= k3;
|
|
20597
|
-
return x2;
|
|
20598
|
-
}
|
|
20599
|
-
var divide = function() {
|
|
20600
|
-
function multiplyInteger(x2, k3, base) {
|
|
20601
|
-
var temp, carry = 0, i = x2.length;
|
|
20602
|
-
for (x2 = x2.slice();i--; ) {
|
|
20603
|
-
temp = x2[i] * k3 + carry;
|
|
20604
|
-
x2[i] = temp % base | 0;
|
|
20605
|
-
carry = temp / base | 0;
|
|
20606
|
-
}
|
|
20607
|
-
if (carry)
|
|
20608
|
-
x2.unshift(carry);
|
|
20609
|
-
return x2;
|
|
20610
|
-
}
|
|
20611
|
-
function compare(a, b, aL, bL) {
|
|
20612
|
-
var i, r;
|
|
20613
|
-
if (aL != bL) {
|
|
20614
|
-
r = aL > bL ? 1 : -1;
|
|
20615
|
-
} else {
|
|
20616
|
-
for (i = r = 0;i < aL; i++) {
|
|
20617
|
-
if (a[i] != b[i]) {
|
|
20618
|
-
r = a[i] > b[i] ? 1 : -1;
|
|
20619
|
-
break;
|
|
20620
|
-
}
|
|
20621
|
-
}
|
|
20622
|
-
}
|
|
20623
|
-
return r;
|
|
20624
|
-
}
|
|
20625
|
-
function subtract(a, b, aL, base) {
|
|
20626
|
-
var i = 0;
|
|
20627
|
-
for (;aL--; ) {
|
|
20628
|
-
a[aL] -= i;
|
|
20629
|
-
i = a[aL] < b[aL] ? 1 : 0;
|
|
20630
|
-
a[aL] = i * base + a[aL] - b[aL];
|
|
20631
|
-
}
|
|
20632
|
-
for (;!a[0] && a.length > 1; )
|
|
20633
|
-
a.shift();
|
|
20634
|
-
}
|
|
20635
|
-
return function(x2, y2, pr, rm, dp, base) {
|
|
20636
|
-
var cmp, e, i, k3, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x2.constructor, sign = x2.s == y2.s ? 1 : -1, xd = x2.d, yd = y2.d;
|
|
20637
|
-
if (!xd || !xd[0] || !yd || !yd[0]) {
|
|
20638
|
-
return new Ctor(!x2.s || !y2.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : xd && xd[0] == 0 || !yd ? sign * 0 : sign / 0);
|
|
20639
|
-
}
|
|
20640
|
-
if (base) {
|
|
20641
|
-
logBase = 1;
|
|
20642
|
-
e = x2.e - y2.e;
|
|
20643
|
-
} else {
|
|
20644
|
-
base = BASE;
|
|
20645
|
-
logBase = LOG_BASE;
|
|
20646
|
-
e = mathfloor(x2.e / logBase) - mathfloor(y2.e / logBase);
|
|
20647
|
-
}
|
|
20648
|
-
yL = yd.length;
|
|
20649
|
-
xL = xd.length;
|
|
20650
|
-
q = new Ctor(sign);
|
|
20651
|
-
qd = q.d = [];
|
|
20652
|
-
for (i = 0;yd[i] == (xd[i] || 0); i++)
|
|
20653
|
-
;
|
|
20654
|
-
if (yd[i] > (xd[i] || 0))
|
|
20655
|
-
e--;
|
|
20656
|
-
if (pr == null) {
|
|
20657
|
-
sd = pr = Ctor.precision;
|
|
20658
|
-
rm = Ctor.rounding;
|
|
20659
|
-
} else if (dp) {
|
|
20660
|
-
sd = pr + (x2.e - y2.e) + 1;
|
|
20661
|
-
} else {
|
|
20662
|
-
sd = pr;
|
|
20663
|
-
}
|
|
20664
|
-
if (sd < 0) {
|
|
20665
|
-
qd.push(1);
|
|
20666
|
-
more = true;
|
|
20667
|
-
} else {
|
|
20668
|
-
sd = sd / logBase + 2 | 0;
|
|
20669
|
-
i = 0;
|
|
20670
|
-
if (yL == 1) {
|
|
20671
|
-
k3 = 0;
|
|
20672
|
-
yd = yd[0];
|
|
20673
|
-
sd++;
|
|
20674
|
-
for (;(i < xL || k3) && sd--; i++) {
|
|
20675
|
-
t = k3 * base + (xd[i] || 0);
|
|
20676
|
-
qd[i] = t / yd | 0;
|
|
20677
|
-
k3 = t % yd | 0;
|
|
20678
|
-
}
|
|
20679
|
-
more = k3 || i < xL;
|
|
20680
|
-
} else {
|
|
20681
|
-
k3 = base / (yd[0] + 1) | 0;
|
|
20682
|
-
if (k3 > 1) {
|
|
20683
|
-
yd = multiplyInteger(yd, k3, base);
|
|
20684
|
-
xd = multiplyInteger(xd, k3, base);
|
|
20685
|
-
yL = yd.length;
|
|
20686
|
-
xL = xd.length;
|
|
20687
|
-
}
|
|
20688
|
-
xi = yL;
|
|
20689
|
-
rem = xd.slice(0, yL);
|
|
20690
|
-
remL = rem.length;
|
|
20691
|
-
for (;remL < yL; )
|
|
20692
|
-
rem[remL++] = 0;
|
|
20693
|
-
yz = yd.slice();
|
|
20694
|
-
yz.unshift(0);
|
|
20695
|
-
yd0 = yd[0];
|
|
20696
|
-
if (yd[1] >= base / 2)
|
|
20697
|
-
++yd0;
|
|
20698
|
-
do {
|
|
20699
|
-
k3 = 0;
|
|
20700
|
-
cmp = compare(yd, rem, yL, remL);
|
|
20701
|
-
if (cmp < 0) {
|
|
20702
|
-
rem0 = rem[0];
|
|
20703
|
-
if (yL != remL)
|
|
20704
|
-
rem0 = rem0 * base + (rem[1] || 0);
|
|
20705
|
-
k3 = rem0 / yd0 | 0;
|
|
20706
|
-
if (k3 > 1) {
|
|
20707
|
-
if (k3 >= base)
|
|
20708
|
-
k3 = base - 1;
|
|
20709
|
-
prod = multiplyInteger(yd, k3, base);
|
|
20710
|
-
prodL = prod.length;
|
|
20711
|
-
remL = rem.length;
|
|
20712
|
-
cmp = compare(prod, rem, prodL, remL);
|
|
20713
|
-
if (cmp == 1) {
|
|
20714
|
-
k3--;
|
|
20715
|
-
subtract(prod, yL < prodL ? yz : yd, prodL, base);
|
|
20716
|
-
}
|
|
20717
|
-
} else {
|
|
20718
|
-
if (k3 == 0)
|
|
20719
|
-
cmp = k3 = 1;
|
|
20720
|
-
prod = yd.slice();
|
|
20721
|
-
}
|
|
20722
|
-
prodL = prod.length;
|
|
20723
|
-
if (prodL < remL)
|
|
20724
|
-
prod.unshift(0);
|
|
20725
|
-
subtract(rem, prod, remL, base);
|
|
20726
|
-
if (cmp == -1) {
|
|
20727
|
-
remL = rem.length;
|
|
20728
|
-
cmp = compare(yd, rem, yL, remL);
|
|
20729
|
-
if (cmp < 1) {
|
|
20730
|
-
k3++;
|
|
20731
|
-
subtract(rem, yL < remL ? yz : yd, remL, base);
|
|
20732
|
-
}
|
|
20733
|
-
}
|
|
20734
|
-
remL = rem.length;
|
|
20735
|
-
} else if (cmp === 0) {
|
|
20736
|
-
k3++;
|
|
20737
|
-
rem = [0];
|
|
20738
|
-
}
|
|
20739
|
-
qd[i++] = k3;
|
|
20740
|
-
if (cmp && rem[0]) {
|
|
20741
|
-
rem[remL++] = xd[xi] || 0;
|
|
20742
|
-
} else {
|
|
20743
|
-
rem = [xd[xi]];
|
|
20744
|
-
remL = 1;
|
|
20745
|
-
}
|
|
20746
|
-
} while ((xi++ < xL || rem[0] !== undefined) && sd--);
|
|
20747
|
-
more = rem[0] !== undefined;
|
|
20748
|
-
}
|
|
20749
|
-
if (!qd[0])
|
|
20750
|
-
qd.shift();
|
|
20751
|
-
}
|
|
20752
|
-
if (logBase == 1) {
|
|
20753
|
-
q.e = e;
|
|
20754
|
-
inexact = more;
|
|
20755
|
-
} else {
|
|
20756
|
-
for (i = 1, k3 = qd[0];k3 >= 10; k3 /= 10)
|
|
20757
|
-
i++;
|
|
20758
|
-
q.e = i + e * logBase - 1;
|
|
20759
|
-
finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
|
|
20760
|
-
}
|
|
20761
|
-
return q;
|
|
20762
|
-
};
|
|
20763
|
-
}();
|
|
20764
|
-
function finalise(x2, sd, rm, isTruncated) {
|
|
20765
|
-
var digits, i, j3, k3, rd, roundUp, w2, xd, xdi, Ctor = x2.constructor;
|
|
20766
|
-
out:
|
|
20767
|
-
if (sd != null) {
|
|
20768
|
-
xd = x2.d;
|
|
20769
|
-
if (!xd)
|
|
20770
|
-
return x2;
|
|
20771
|
-
for (digits = 1, k3 = xd[0];k3 >= 10; k3 /= 10)
|
|
20772
|
-
digits++;
|
|
20773
|
-
i = sd - digits;
|
|
20774
|
-
if (i < 0) {
|
|
20775
|
-
i += LOG_BASE;
|
|
20776
|
-
j3 = sd;
|
|
20777
|
-
w2 = xd[xdi = 0];
|
|
20778
|
-
rd = w2 / mathpow(10, digits - j3 - 1) % 10 | 0;
|
|
20779
|
-
} else {
|
|
20780
|
-
xdi = Math.ceil((i + 1) / LOG_BASE);
|
|
20781
|
-
k3 = xd.length;
|
|
20782
|
-
if (xdi >= k3) {
|
|
20783
|
-
if (isTruncated) {
|
|
20784
|
-
for (;k3++ <= xdi; )
|
|
20785
|
-
xd.push(0);
|
|
20786
|
-
w2 = rd = 0;
|
|
20787
|
-
digits = 1;
|
|
20788
|
-
i %= LOG_BASE;
|
|
20789
|
-
j3 = i - LOG_BASE + 1;
|
|
20790
|
-
} else {
|
|
20791
|
-
break out;
|
|
20792
|
-
}
|
|
20793
|
-
} else {
|
|
20794
|
-
w2 = k3 = xd[xdi];
|
|
20795
|
-
for (digits = 1;k3 >= 10; k3 /= 10)
|
|
20796
|
-
digits++;
|
|
20797
|
-
i %= LOG_BASE;
|
|
20798
|
-
j3 = i - LOG_BASE + digits;
|
|
20799
|
-
rd = j3 < 0 ? 0 : w2 / mathpow(10, digits - j3 - 1) % 10 | 0;
|
|
20800
|
-
}
|
|
20801
|
-
}
|
|
20802
|
-
isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== undefined || (j3 < 0 ? w2 : w2 % mathpow(10, digits - j3 - 1));
|
|
20803
|
-
roundUp = rm < 4 ? (rd || isTruncated) && (rm == 0 || rm == (x2.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 && (i > 0 ? j3 > 0 ? w2 / mathpow(10, digits - j3) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x2.s < 0 ? 8 : 7));
|
|
20804
|
-
if (sd < 1 || !xd[0]) {
|
|
20805
|
-
xd.length = 0;
|
|
20806
|
-
if (roundUp) {
|
|
20807
|
-
sd -= x2.e + 1;
|
|
20808
|
-
xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
|
|
20809
|
-
x2.e = -sd || 0;
|
|
20810
|
-
} else {
|
|
20811
|
-
xd[0] = x2.e = 0;
|
|
20812
|
-
}
|
|
20813
|
-
return x2;
|
|
20814
|
-
}
|
|
20815
|
-
if (i == 0) {
|
|
20816
|
-
xd.length = xdi;
|
|
20817
|
-
k3 = 1;
|
|
20818
|
-
xdi--;
|
|
20819
|
-
} else {
|
|
20820
|
-
xd.length = xdi + 1;
|
|
20821
|
-
k3 = mathpow(10, LOG_BASE - i);
|
|
20822
|
-
xd[xdi] = j3 > 0 ? (w2 / mathpow(10, digits - j3) % mathpow(10, j3) | 0) * k3 : 0;
|
|
20823
|
-
}
|
|
20824
|
-
if (roundUp) {
|
|
20825
|
-
for (;; ) {
|
|
20826
|
-
if (xdi == 0) {
|
|
20827
|
-
for (i = 1, j3 = xd[0];j3 >= 10; j3 /= 10)
|
|
20828
|
-
i++;
|
|
20829
|
-
j3 = xd[0] += k3;
|
|
20830
|
-
for (k3 = 1;j3 >= 10; j3 /= 10)
|
|
20831
|
-
k3++;
|
|
20832
|
-
if (i != k3) {
|
|
20833
|
-
x2.e++;
|
|
20834
|
-
if (xd[0] == BASE)
|
|
20835
|
-
xd[0] = 1;
|
|
20836
|
-
}
|
|
20837
|
-
break;
|
|
20838
|
-
} else {
|
|
20839
|
-
xd[xdi] += k3;
|
|
20840
|
-
if (xd[xdi] != BASE)
|
|
20841
|
-
break;
|
|
20842
|
-
xd[xdi--] = 0;
|
|
20843
|
-
k3 = 1;
|
|
20844
|
-
}
|
|
20845
|
-
}
|
|
20846
|
-
}
|
|
20847
|
-
for (i = xd.length;xd[--i] === 0; )
|
|
20848
|
-
xd.pop();
|
|
20849
|
-
}
|
|
20850
|
-
if (external2) {
|
|
20851
|
-
if (x2.e > Ctor.maxE) {
|
|
20852
|
-
x2.d = null;
|
|
20853
|
-
x2.e = NaN;
|
|
20854
|
-
} else if (x2.e < Ctor.minE) {
|
|
20855
|
-
x2.e = 0;
|
|
20856
|
-
x2.d = [0];
|
|
20857
|
-
}
|
|
20858
|
-
}
|
|
20859
|
-
return x2;
|
|
20860
|
-
}
|
|
20861
|
-
function finiteToString(x2, isExp, sd) {
|
|
20862
|
-
if (!x2.isFinite())
|
|
20863
|
-
return nonFiniteToString(x2);
|
|
20864
|
-
var k3, e = x2.e, str = digitsToString(x2.d), len = str.length;
|
|
20865
|
-
if (isExp) {
|
|
20866
|
-
if (sd && (k3 = sd - len) > 0) {
|
|
20867
|
-
str = str.charAt(0) + "." + str.slice(1) + getZeroString(k3);
|
|
20868
|
-
} else if (len > 1) {
|
|
20869
|
-
str = str.charAt(0) + "." + str.slice(1);
|
|
20870
|
-
}
|
|
20871
|
-
str = str + (x2.e < 0 ? "e" : "e+") + x2.e;
|
|
20872
|
-
} else if (e < 0) {
|
|
20873
|
-
str = "0." + getZeroString(-e - 1) + str;
|
|
20874
|
-
if (sd && (k3 = sd - len) > 0)
|
|
20875
|
-
str += getZeroString(k3);
|
|
20876
|
-
} else if (e >= len) {
|
|
20877
|
-
str += getZeroString(e + 1 - len);
|
|
20878
|
-
if (sd && (k3 = sd - e - 1) > 0)
|
|
20879
|
-
str = str + "." + getZeroString(k3);
|
|
20880
|
-
} else {
|
|
20881
|
-
if ((k3 = e + 1) < len)
|
|
20882
|
-
str = str.slice(0, k3) + "." + str.slice(k3);
|
|
20883
|
-
if (sd && (k3 = sd - len) > 0) {
|
|
20884
|
-
if (e + 1 === len)
|
|
20885
|
-
str += ".";
|
|
20886
|
-
str += getZeroString(k3);
|
|
20887
|
-
}
|
|
20888
|
-
}
|
|
20889
|
-
return str;
|
|
20890
|
-
}
|
|
20891
|
-
function getBase10Exponent(digits, e) {
|
|
20892
|
-
var w2 = digits[0];
|
|
20893
|
-
for (e *= LOG_BASE;w2 >= 10; w2 /= 10)
|
|
20894
|
-
e++;
|
|
20895
|
-
return e;
|
|
20896
|
-
}
|
|
20897
|
-
function getLn10(Ctor, sd, pr) {
|
|
20898
|
-
if (sd > LN10_PRECISION) {
|
|
20899
|
-
external2 = true;
|
|
20900
|
-
if (pr)
|
|
20901
|
-
Ctor.precision = pr;
|
|
20902
|
-
throw Error(precisionLimitExceeded);
|
|
20903
|
-
}
|
|
20904
|
-
return finalise(new Ctor(LN10), sd, 1, true);
|
|
20905
|
-
}
|
|
20906
|
-
function getPi(Ctor, sd, rm) {
|
|
20907
|
-
if (sd > PI_PRECISION)
|
|
20908
|
-
throw Error(precisionLimitExceeded);
|
|
20909
|
-
return finalise(new Ctor(PI), sd, rm, true);
|
|
20910
|
-
}
|
|
20911
|
-
function getPrecision(digits) {
|
|
20912
|
-
var w2 = digits.length - 1, len = w2 * LOG_BASE + 1;
|
|
20913
|
-
w2 = digits[w2];
|
|
20914
|
-
if (w2) {
|
|
20915
|
-
for (;w2 % 10 == 0; w2 /= 10)
|
|
20916
|
-
len--;
|
|
20917
|
-
for (w2 = digits[0];w2 >= 10; w2 /= 10)
|
|
20918
|
-
len++;
|
|
20919
|
-
}
|
|
20920
|
-
return len;
|
|
20921
|
-
}
|
|
20922
|
-
function getZeroString(k3) {
|
|
20923
|
-
var zs = "";
|
|
20924
|
-
for (;k3--; )
|
|
20925
|
-
zs += "0";
|
|
20926
|
-
return zs;
|
|
20927
|
-
}
|
|
20928
|
-
function intPow(Ctor, x2, n, pr) {
|
|
20929
|
-
var isTruncated, r = new Ctor(1), k3 = Math.ceil(pr / LOG_BASE + 4);
|
|
20930
|
-
external2 = false;
|
|
20931
|
-
for (;; ) {
|
|
20932
|
-
if (n % 2) {
|
|
20933
|
-
r = r.times(x2);
|
|
20934
|
-
if (truncate(r.d, k3))
|
|
20935
|
-
isTruncated = true;
|
|
20936
|
-
}
|
|
20937
|
-
n = mathfloor(n / 2);
|
|
20938
|
-
if (n === 0) {
|
|
20939
|
-
n = r.d.length - 1;
|
|
20940
|
-
if (isTruncated && r.d[n] === 0)
|
|
20941
|
-
++r.d[n];
|
|
20942
|
-
break;
|
|
20943
|
-
}
|
|
20944
|
-
x2 = x2.times(x2);
|
|
20945
|
-
truncate(x2.d, k3);
|
|
20946
|
-
}
|
|
20947
|
-
external2 = true;
|
|
20948
|
-
return r;
|
|
20949
|
-
}
|
|
20950
|
-
function isOdd(n) {
|
|
20951
|
-
return n.d[n.d.length - 1] & 1;
|
|
20952
|
-
}
|
|
20953
|
-
function maxOrMin(Ctor, args, n) {
|
|
20954
|
-
var k3, y2, x2 = new Ctor(args[0]), i = 0;
|
|
20955
|
-
for (;++i < args.length; ) {
|
|
20956
|
-
y2 = new Ctor(args[i]);
|
|
20957
|
-
if (!y2.s) {
|
|
20958
|
-
x2 = y2;
|
|
20959
|
-
break;
|
|
20960
|
-
}
|
|
20961
|
-
k3 = x2.cmp(y2);
|
|
20962
|
-
if (k3 === n || k3 === 0 && x2.s === n) {
|
|
20963
|
-
x2 = y2;
|
|
20964
|
-
}
|
|
20965
|
-
}
|
|
20966
|
-
return x2;
|
|
20967
|
-
}
|
|
20968
|
-
function naturalExponential(x2, sd) {
|
|
20969
|
-
var denominator, guard, j3, pow, sum, t, wpr, rep = 0, i = 0, k3 = 0, Ctor = x2.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
|
20970
|
-
if (!x2.d || !x2.d[0] || x2.e > 17) {
|
|
20971
|
-
return new Ctor(x2.d ? !x2.d[0] ? 1 : x2.s < 0 ? 0 : 1 / 0 : x2.s ? x2.s < 0 ? 0 : x2 : 0 / 0);
|
|
20972
|
-
}
|
|
20973
|
-
if (sd == null) {
|
|
20974
|
-
external2 = false;
|
|
20975
|
-
wpr = pr;
|
|
20976
|
-
} else {
|
|
20977
|
-
wpr = sd;
|
|
20978
|
-
}
|
|
20979
|
-
t = new Ctor(0.03125);
|
|
20980
|
-
while (x2.e > -2) {
|
|
20981
|
-
x2 = x2.times(t);
|
|
20982
|
-
k3 += 5;
|
|
20983
|
-
}
|
|
20984
|
-
guard = Math.log(mathpow(2, k3)) / Math.LN10 * 2 + 5 | 0;
|
|
20985
|
-
wpr += guard;
|
|
20986
|
-
denominator = pow = sum = new Ctor(1);
|
|
20987
|
-
Ctor.precision = wpr;
|
|
20988
|
-
for (;; ) {
|
|
20989
|
-
pow = finalise(pow.times(x2), wpr, 1);
|
|
20990
|
-
denominator = denominator.times(++i);
|
|
20991
|
-
t = sum.plus(divide(pow, denominator, wpr, 1));
|
|
20992
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
|
|
20993
|
-
j3 = k3;
|
|
20994
|
-
while (j3--)
|
|
20995
|
-
sum = finalise(sum.times(sum), wpr, 1);
|
|
20996
|
-
if (sd == null) {
|
|
20997
|
-
if (rep < 3 && checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
|
|
20998
|
-
Ctor.precision = wpr += 10;
|
|
20999
|
-
denominator = pow = t = new Ctor(1);
|
|
21000
|
-
i = 0;
|
|
21001
|
-
rep++;
|
|
21002
|
-
} else {
|
|
21003
|
-
return finalise(sum, Ctor.precision = pr, rm, external2 = true);
|
|
21004
|
-
}
|
|
21005
|
-
} else {
|
|
21006
|
-
Ctor.precision = pr;
|
|
21007
|
-
return sum;
|
|
21008
|
-
}
|
|
21009
|
-
}
|
|
21010
|
-
sum = t;
|
|
21011
|
-
}
|
|
21012
|
-
}
|
|
21013
|
-
function naturalLogarithm(y2, sd) {
|
|
21014
|
-
var c, c0, denominator, e, numerator, rep, sum, t, wpr, x1, x2, n = 1, guard = 10, x3 = y2, xd = x3.d, Ctor = x3.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
|
21015
|
-
if (x3.s < 0 || !xd || !xd[0] || !x3.e && xd[0] == 1 && xd.length == 1) {
|
|
21016
|
-
return new Ctor(xd && !xd[0] ? -1 / 0 : x3.s != 1 ? NaN : xd ? 0 : x3);
|
|
21017
|
-
}
|
|
21018
|
-
if (sd == null) {
|
|
21019
|
-
external2 = false;
|
|
21020
|
-
wpr = pr;
|
|
21021
|
-
} else {
|
|
21022
|
-
wpr = sd;
|
|
21023
|
-
}
|
|
21024
|
-
Ctor.precision = wpr += guard;
|
|
21025
|
-
c = digitsToString(xd);
|
|
21026
|
-
c0 = c.charAt(0);
|
|
21027
|
-
if (Math.abs(e = x3.e) < 1500000000000000) {
|
|
21028
|
-
while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
|
|
21029
|
-
x3 = x3.times(y2);
|
|
21030
|
-
c = digitsToString(x3.d);
|
|
21031
|
-
c0 = c.charAt(0);
|
|
21032
|
-
n++;
|
|
21033
|
-
}
|
|
21034
|
-
e = x3.e;
|
|
21035
|
-
if (c0 > 1) {
|
|
21036
|
-
x3 = new Ctor("0." + c);
|
|
21037
|
-
e++;
|
|
21038
|
-
} else {
|
|
21039
|
-
x3 = new Ctor(c0 + "." + c.slice(1));
|
|
21040
|
-
}
|
|
21041
|
-
} else {
|
|
21042
|
-
t = getLn10(Ctor, wpr + 2, pr).times(e + "");
|
|
21043
|
-
x3 = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
|
|
21044
|
-
Ctor.precision = pr;
|
|
21045
|
-
return sd == null ? finalise(x3, pr, rm, external2 = true) : x3;
|
|
21046
|
-
}
|
|
21047
|
-
x1 = x3;
|
|
21048
|
-
sum = numerator = x3 = divide(x3.minus(1), x3.plus(1), wpr, 1);
|
|
21049
|
-
x2 = finalise(x3.times(x3), wpr, 1);
|
|
21050
|
-
denominator = 3;
|
|
21051
|
-
for (;; ) {
|
|
21052
|
-
numerator = finalise(numerator.times(x2), wpr, 1);
|
|
21053
|
-
t = sum.plus(divide(numerator, new Ctor(denominator), wpr, 1));
|
|
21054
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
|
|
21055
|
-
sum = sum.times(2);
|
|
21056
|
-
if (e !== 0)
|
|
21057
|
-
sum = sum.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
|
|
21058
|
-
sum = divide(sum, new Ctor(n), wpr, 1);
|
|
21059
|
-
if (sd == null) {
|
|
21060
|
-
if (checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
|
|
21061
|
-
Ctor.precision = wpr += guard;
|
|
21062
|
-
t = numerator = x3 = divide(x1.minus(1), x1.plus(1), wpr, 1);
|
|
21063
|
-
x2 = finalise(x3.times(x3), wpr, 1);
|
|
21064
|
-
denominator = rep = 1;
|
|
21065
|
-
} else {
|
|
21066
|
-
return finalise(sum, Ctor.precision = pr, rm, external2 = true);
|
|
21067
|
-
}
|
|
21068
|
-
} else {
|
|
21069
|
-
Ctor.precision = pr;
|
|
21070
|
-
return sum;
|
|
21071
|
-
}
|
|
21072
|
-
}
|
|
21073
|
-
sum = t;
|
|
21074
|
-
denominator += 2;
|
|
21075
|
-
}
|
|
21076
|
-
}
|
|
21077
|
-
function nonFiniteToString(x2) {
|
|
21078
|
-
return String(x2.s * x2.s / 0);
|
|
21079
|
-
}
|
|
21080
|
-
function parseDecimal(x2, str) {
|
|
21081
|
-
var e, i, len;
|
|
21082
|
-
if ((e = str.indexOf(".")) > -1)
|
|
21083
|
-
str = str.replace(".", "");
|
|
21084
|
-
if ((i = str.search(/e/i)) > 0) {
|
|
21085
|
-
if (e < 0)
|
|
21086
|
-
e = i;
|
|
21087
|
-
e += +str.slice(i + 1);
|
|
21088
|
-
str = str.substring(0, i);
|
|
21089
|
-
} else if (e < 0) {
|
|
21090
|
-
e = str.length;
|
|
21091
|
-
}
|
|
21092
|
-
for (i = 0;str.charCodeAt(i) === 48; i++)
|
|
21093
|
-
;
|
|
21094
|
-
for (len = str.length;str.charCodeAt(len - 1) === 48; --len)
|
|
21095
|
-
;
|
|
21096
|
-
str = str.slice(i, len);
|
|
21097
|
-
if (str) {
|
|
21098
|
-
len -= i;
|
|
21099
|
-
x2.e = e = e - i - 1;
|
|
21100
|
-
x2.d = [];
|
|
21101
|
-
i = (e + 1) % LOG_BASE;
|
|
21102
|
-
if (e < 0)
|
|
21103
|
-
i += LOG_BASE;
|
|
21104
|
-
if (i < len) {
|
|
21105
|
-
if (i)
|
|
21106
|
-
x2.d.push(+str.slice(0, i));
|
|
21107
|
-
for (len -= LOG_BASE;i < len; )
|
|
21108
|
-
x2.d.push(+str.slice(i, i += LOG_BASE));
|
|
21109
|
-
str = str.slice(i);
|
|
21110
|
-
i = LOG_BASE - str.length;
|
|
21111
|
-
} else {
|
|
21112
|
-
i -= len;
|
|
21113
|
-
}
|
|
21114
|
-
for (;i--; )
|
|
21115
|
-
str += "0";
|
|
21116
|
-
x2.d.push(+str);
|
|
21117
|
-
if (external2) {
|
|
21118
|
-
if (x2.e > x2.constructor.maxE) {
|
|
21119
|
-
x2.d = null;
|
|
21120
|
-
x2.e = NaN;
|
|
21121
|
-
} else if (x2.e < x2.constructor.minE) {
|
|
21122
|
-
x2.e = 0;
|
|
21123
|
-
x2.d = [0];
|
|
21124
|
-
}
|
|
21125
|
-
}
|
|
21126
|
-
} else {
|
|
21127
|
-
x2.e = 0;
|
|
21128
|
-
x2.d = [0];
|
|
21129
|
-
}
|
|
21130
|
-
return x2;
|
|
21131
|
-
}
|
|
21132
|
-
function parseOther(x2, str) {
|
|
21133
|
-
var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
|
|
21134
|
-
if (str.indexOf("_") > -1) {
|
|
21135
|
-
str = str.replace(/(\d)_(?=\d)/g, "$1");
|
|
21136
|
-
if (isDecimal.test(str))
|
|
21137
|
-
return parseDecimal(x2, str);
|
|
21138
|
-
} else if (str === "Infinity" || str === "NaN") {
|
|
21139
|
-
if (!+str)
|
|
21140
|
-
x2.s = NaN;
|
|
21141
|
-
x2.e = NaN;
|
|
21142
|
-
x2.d = null;
|
|
21143
|
-
return x2;
|
|
21144
|
-
}
|
|
21145
|
-
if (isHex.test(str)) {
|
|
21146
|
-
base = 16;
|
|
21147
|
-
str = str.toLowerCase();
|
|
21148
|
-
} else if (isBinary.test(str)) {
|
|
21149
|
-
base = 2;
|
|
21150
|
-
} else if (isOctal.test(str)) {
|
|
21151
|
-
base = 8;
|
|
21152
|
-
} else {
|
|
21153
|
-
throw Error(invalidArgument + str);
|
|
21154
|
-
}
|
|
21155
|
-
i = str.search(/p/i);
|
|
21156
|
-
if (i > 0) {
|
|
21157
|
-
p = +str.slice(i + 1);
|
|
21158
|
-
str = str.substring(2, i);
|
|
21159
|
-
} else {
|
|
21160
|
-
str = str.slice(2);
|
|
21161
|
-
}
|
|
21162
|
-
i = str.indexOf(".");
|
|
21163
|
-
isFloat = i >= 0;
|
|
21164
|
-
Ctor = x2.constructor;
|
|
21165
|
-
if (isFloat) {
|
|
21166
|
-
str = str.replace(".", "");
|
|
21167
|
-
len = str.length;
|
|
21168
|
-
i = len - i;
|
|
21169
|
-
divisor = intPow(Ctor, new Ctor(base), i, i * 2);
|
|
21170
|
-
}
|
|
21171
|
-
xd = convertBase(str, base, BASE);
|
|
21172
|
-
xe = xd.length - 1;
|
|
21173
|
-
for (i = xe;xd[i] === 0; --i)
|
|
21174
|
-
xd.pop();
|
|
21175
|
-
if (i < 0)
|
|
21176
|
-
return new Ctor(x2.s * 0);
|
|
21177
|
-
x2.e = getBase10Exponent(xd, xe);
|
|
21178
|
-
x2.d = xd;
|
|
21179
|
-
external2 = false;
|
|
21180
|
-
if (isFloat)
|
|
21181
|
-
x2 = divide(x2, divisor, len * 4);
|
|
21182
|
-
if (p)
|
|
21183
|
-
x2 = x2.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
|
|
21184
|
-
external2 = true;
|
|
21185
|
-
return x2;
|
|
21186
|
-
}
|
|
21187
|
-
function sine(Ctor, x2) {
|
|
21188
|
-
var k3, len = x2.d.length;
|
|
21189
|
-
if (len < 3) {
|
|
21190
|
-
return x2.isZero() ? x2 : taylorSeries(Ctor, 2, x2, x2);
|
|
21191
|
-
}
|
|
21192
|
-
k3 = 1.4 * Math.sqrt(len);
|
|
21193
|
-
k3 = k3 > 16 ? 16 : k3 | 0;
|
|
21194
|
-
x2 = x2.times(1 / tinyPow(5, k3));
|
|
21195
|
-
x2 = taylorSeries(Ctor, 2, x2, x2);
|
|
21196
|
-
var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
21197
|
-
for (;k3--; ) {
|
|
21198
|
-
sin2_x = x2.times(x2);
|
|
21199
|
-
x2 = x2.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
|
|
21200
|
-
}
|
|
21201
|
-
return x2;
|
|
21202
|
-
}
|
|
21203
|
-
function taylorSeries(Ctor, n, x2, y2, isHyperbolic) {
|
|
21204
|
-
var j3, t, u2, x22, i = 1, pr = Ctor.precision, k3 = Math.ceil(pr / LOG_BASE);
|
|
21205
|
-
external2 = false;
|
|
21206
|
-
x22 = x2.times(x2);
|
|
21207
|
-
u2 = new Ctor(y2);
|
|
21208
|
-
for (;; ) {
|
|
21209
|
-
t = divide(u2.times(x22), new Ctor(n++ * n++), pr, 1);
|
|
21210
|
-
u2 = isHyperbolic ? y2.plus(t) : y2.minus(t);
|
|
21211
|
-
y2 = divide(t.times(x22), new Ctor(n++ * n++), pr, 1);
|
|
21212
|
-
t = u2.plus(y2);
|
|
21213
|
-
if (t.d[k3] !== undefined) {
|
|
21214
|
-
for (j3 = k3;t.d[j3] === u2.d[j3] && j3--; )
|
|
21215
|
-
;
|
|
21216
|
-
if (j3 == -1)
|
|
21217
|
-
break;
|
|
21218
|
-
}
|
|
21219
|
-
j3 = u2;
|
|
21220
|
-
u2 = y2;
|
|
21221
|
-
y2 = t;
|
|
21222
|
-
t = j3;
|
|
21223
|
-
i++;
|
|
21224
|
-
}
|
|
21225
|
-
external2 = true;
|
|
21226
|
-
t.d.length = k3 + 1;
|
|
21227
|
-
return t;
|
|
21228
|
-
}
|
|
21229
|
-
function tinyPow(b, e) {
|
|
21230
|
-
var n = b;
|
|
21231
|
-
while (--e)
|
|
21232
|
-
n *= b;
|
|
21233
|
-
return n;
|
|
21234
|
-
}
|
|
21235
|
-
function toLessThanHalfPi(Ctor, x2) {
|
|
21236
|
-
var t, isNeg = x2.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
|
|
21237
|
-
x2 = x2.abs();
|
|
21238
|
-
if (x2.lte(halfPi)) {
|
|
21239
|
-
quadrant = isNeg ? 4 : 1;
|
|
21240
|
-
return x2;
|
|
21241
|
-
}
|
|
21242
|
-
t = x2.divToInt(pi);
|
|
21243
|
-
if (t.isZero()) {
|
|
21244
|
-
quadrant = isNeg ? 3 : 2;
|
|
21245
|
-
} else {
|
|
21246
|
-
x2 = x2.minus(t.times(pi));
|
|
21247
|
-
if (x2.lte(halfPi)) {
|
|
21248
|
-
quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
|
|
21249
|
-
return x2;
|
|
21250
|
-
}
|
|
21251
|
-
quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
|
|
21252
|
-
}
|
|
21253
|
-
return x2.minus(pi).abs();
|
|
21254
|
-
}
|
|
21255
|
-
function toStringBinary(x2, baseOut, sd, rm) {
|
|
21256
|
-
var base, e, i, k3, len, roundUp, str, xd, y2, Ctor = x2.constructor, isExp = sd !== undefined;
|
|
21257
|
-
if (isExp) {
|
|
21258
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
21259
|
-
if (rm === undefined)
|
|
21260
|
-
rm = Ctor.rounding;
|
|
21261
|
-
else
|
|
21262
|
-
checkInt32(rm, 0, 8);
|
|
21263
|
-
} else {
|
|
21264
|
-
sd = Ctor.precision;
|
|
21265
|
-
rm = Ctor.rounding;
|
|
21266
|
-
}
|
|
21267
|
-
if (!x2.isFinite()) {
|
|
21268
|
-
str = nonFiniteToString(x2);
|
|
21269
|
-
} else {
|
|
21270
|
-
str = finiteToString(x2);
|
|
21271
|
-
i = str.indexOf(".");
|
|
21272
|
-
if (isExp) {
|
|
21273
|
-
base = 2;
|
|
21274
|
-
if (baseOut == 16) {
|
|
21275
|
-
sd = sd * 4 - 3;
|
|
21276
|
-
} else if (baseOut == 8) {
|
|
21277
|
-
sd = sd * 3 - 2;
|
|
21278
|
-
}
|
|
21279
|
-
} else {
|
|
21280
|
-
base = baseOut;
|
|
21281
|
-
}
|
|
21282
|
-
if (i >= 0) {
|
|
21283
|
-
str = str.replace(".", "");
|
|
21284
|
-
y2 = new Ctor(1);
|
|
21285
|
-
y2.e = str.length - i;
|
|
21286
|
-
y2.d = convertBase(finiteToString(y2), 10, base);
|
|
21287
|
-
y2.e = y2.d.length;
|
|
21288
|
-
}
|
|
21289
|
-
xd = convertBase(str, 10, base);
|
|
21290
|
-
e = len = xd.length;
|
|
21291
|
-
for (;xd[--len] == 0; )
|
|
21292
|
-
xd.pop();
|
|
21293
|
-
if (!xd[0]) {
|
|
21294
|
-
str = isExp ? "0p+0" : "0";
|
|
21295
|
-
} else {
|
|
21296
|
-
if (i < 0) {
|
|
21297
|
-
e--;
|
|
21298
|
-
} else {
|
|
21299
|
-
x2 = new Ctor(x2);
|
|
21300
|
-
x2.d = xd;
|
|
21301
|
-
x2.e = e;
|
|
21302
|
-
x2 = divide(x2, y2, sd, rm, 0, base);
|
|
21303
|
-
xd = x2.d;
|
|
21304
|
-
e = x2.e;
|
|
21305
|
-
roundUp = inexact;
|
|
21306
|
-
}
|
|
21307
|
-
i = xd[sd];
|
|
21308
|
-
k3 = base / 2;
|
|
21309
|
-
roundUp = roundUp || xd[sd + 1] !== undefined;
|
|
21310
|
-
roundUp = rm < 4 ? (i !== undefined || roundUp) && (rm === 0 || rm === (x2.s < 0 ? 3 : 2)) : i > k3 || i === k3 && (rm === 4 || roundUp || rm === 6 && xd[sd - 1] & 1 || rm === (x2.s < 0 ? 8 : 7));
|
|
21311
|
-
xd.length = sd;
|
|
21312
|
-
if (roundUp) {
|
|
21313
|
-
for (;++xd[--sd] > base - 1; ) {
|
|
21314
|
-
xd[sd] = 0;
|
|
21315
|
-
if (!sd) {
|
|
21316
|
-
++e;
|
|
21317
|
-
xd.unshift(1);
|
|
21318
|
-
}
|
|
21319
|
-
}
|
|
21320
|
-
}
|
|
21321
|
-
for (len = xd.length;!xd[len - 1]; --len)
|
|
21322
|
-
;
|
|
21323
|
-
for (i = 0, str = "";i < len; i++)
|
|
21324
|
-
str += NUMERALS.charAt(xd[i]);
|
|
21325
|
-
if (isExp) {
|
|
21326
|
-
if (len > 1) {
|
|
21327
|
-
if (baseOut == 16 || baseOut == 8) {
|
|
21328
|
-
i = baseOut == 16 ? 4 : 3;
|
|
21329
|
-
for (--len;len % i; len++)
|
|
21330
|
-
str += "0";
|
|
21331
|
-
xd = convertBase(str, base, baseOut);
|
|
21332
|
-
for (len = xd.length;!xd[len - 1]; --len)
|
|
21333
|
-
;
|
|
21334
|
-
for (i = 1, str = "1.";i < len; i++)
|
|
21335
|
-
str += NUMERALS.charAt(xd[i]);
|
|
21336
|
-
} else {
|
|
21337
|
-
str = str.charAt(0) + "." + str.slice(1);
|
|
21338
|
-
}
|
|
21339
|
-
}
|
|
21340
|
-
str = str + (e < 0 ? "p" : "p+") + e;
|
|
21341
|
-
} else if (e < 0) {
|
|
21342
|
-
for (;++e; )
|
|
21343
|
-
str = "0" + str;
|
|
21344
|
-
str = "0." + str;
|
|
21345
|
-
} else {
|
|
21346
|
-
if (++e > len)
|
|
21347
|
-
for (e -= len;e--; )
|
|
21348
|
-
str += "0";
|
|
21349
|
-
else if (e < len)
|
|
21350
|
-
str = str.slice(0, e) + "." + str.slice(e);
|
|
21351
|
-
}
|
|
21352
|
-
}
|
|
21353
|
-
str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
|
|
21354
|
-
}
|
|
21355
|
-
return x2.s < 0 ? "-" + str : str;
|
|
21356
|
-
}
|
|
21357
|
-
function truncate(arr, len) {
|
|
21358
|
-
if (arr.length > len) {
|
|
21359
|
-
arr.length = len;
|
|
21360
|
-
return true;
|
|
21361
|
-
}
|
|
21362
|
-
}
|
|
21363
|
-
function abs(x2) {
|
|
21364
|
-
return new this(x2).abs();
|
|
21365
|
-
}
|
|
21366
|
-
function acos(x2) {
|
|
21367
|
-
return new this(x2).acos();
|
|
21368
|
-
}
|
|
21369
|
-
function acosh(x2) {
|
|
21370
|
-
return new this(x2).acosh();
|
|
21371
|
-
}
|
|
21372
|
-
function add(x2, y2) {
|
|
21373
|
-
return new this(x2).plus(y2);
|
|
21374
|
-
}
|
|
21375
|
-
function asin(x2) {
|
|
21376
|
-
return new this(x2).asin();
|
|
21377
|
-
}
|
|
21378
|
-
function asinh(x2) {
|
|
21379
|
-
return new this(x2).asinh();
|
|
21380
|
-
}
|
|
21381
|
-
function atan(x2) {
|
|
21382
|
-
return new this(x2).atan();
|
|
21383
|
-
}
|
|
21384
|
-
function atanh(x2) {
|
|
21385
|
-
return new this(x2).atanh();
|
|
21386
|
-
}
|
|
21387
|
-
function atan2(y2, x2) {
|
|
21388
|
-
y2 = new this(y2);
|
|
21389
|
-
x2 = new this(x2);
|
|
21390
|
-
var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
|
|
21391
|
-
if (!y2.s || !x2.s) {
|
|
21392
|
-
r = new this(NaN);
|
|
21393
|
-
} else if (!y2.d && !x2.d) {
|
|
21394
|
-
r = getPi(this, wpr, 1).times(x2.s > 0 ? 0.25 : 0.75);
|
|
21395
|
-
r.s = y2.s;
|
|
21396
|
-
} else if (!x2.d || y2.isZero()) {
|
|
21397
|
-
r = x2.s < 0 ? getPi(this, pr, rm) : new this(0);
|
|
21398
|
-
r.s = y2.s;
|
|
21399
|
-
} else if (!y2.d || x2.isZero()) {
|
|
21400
|
-
r = getPi(this, wpr, 1).times(0.5);
|
|
21401
|
-
r.s = y2.s;
|
|
21402
|
-
} else if (x2.s < 0) {
|
|
21403
|
-
this.precision = wpr;
|
|
21404
|
-
this.rounding = 1;
|
|
21405
|
-
r = this.atan(divide(y2, x2, wpr, 1));
|
|
21406
|
-
x2 = getPi(this, wpr, 1);
|
|
21407
|
-
this.precision = pr;
|
|
21408
|
-
this.rounding = rm;
|
|
21409
|
-
r = y2.s < 0 ? r.minus(x2) : r.plus(x2);
|
|
21410
|
-
} else {
|
|
21411
|
-
r = this.atan(divide(y2, x2, wpr, 1));
|
|
21412
|
-
}
|
|
21413
|
-
return r;
|
|
21414
|
-
}
|
|
21415
|
-
function cbrt(x2) {
|
|
21416
|
-
return new this(x2).cbrt();
|
|
21417
|
-
}
|
|
21418
|
-
function ceil(x2) {
|
|
21419
|
-
return finalise(x2 = new this(x2), x2.e + 1, 2);
|
|
21420
|
-
}
|
|
21421
|
-
function clamp(x2, min, max) {
|
|
21422
|
-
return new this(x2).clamp(min, max);
|
|
21423
|
-
}
|
|
21424
|
-
function config(obj) {
|
|
21425
|
-
if (!obj || typeof obj !== "object")
|
|
21426
|
-
throw Error(decimalError + "Object expected");
|
|
21427
|
-
var i, p, v, useDefaults = obj.defaults === true, ps = [
|
|
21428
|
-
"precision",
|
|
21429
|
-
1,
|
|
21430
|
-
MAX_DIGITS,
|
|
21431
|
-
"rounding",
|
|
21432
|
-
0,
|
|
21433
|
-
8,
|
|
21434
|
-
"toExpNeg",
|
|
21435
|
-
-EXP_LIMIT,
|
|
21436
|
-
0,
|
|
21437
|
-
"toExpPos",
|
|
21438
|
-
0,
|
|
21439
|
-
EXP_LIMIT,
|
|
21440
|
-
"maxE",
|
|
21441
|
-
0,
|
|
21442
|
-
EXP_LIMIT,
|
|
21443
|
-
"minE",
|
|
21444
|
-
-EXP_LIMIT,
|
|
21445
|
-
0,
|
|
21446
|
-
"modulo",
|
|
21447
|
-
0,
|
|
21448
|
-
9
|
|
21449
|
-
];
|
|
21450
|
-
for (i = 0;i < ps.length; i += 3) {
|
|
21451
|
-
if (p = ps[i], useDefaults)
|
|
21452
|
-
this[p] = DEFAULTS[p];
|
|
21453
|
-
if ((v = obj[p]) !== undefined) {
|
|
21454
|
-
if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
|
|
21455
|
-
this[p] = v;
|
|
21456
|
-
else
|
|
21457
|
-
throw Error(invalidArgument + p + ": " + v);
|
|
21458
|
-
}
|
|
21459
|
-
}
|
|
21460
|
-
if (p = "crypto", useDefaults)
|
|
21461
|
-
this[p] = DEFAULTS[p];
|
|
21462
|
-
if ((v = obj[p]) !== undefined) {
|
|
21463
|
-
if (v === true || v === false || v === 0 || v === 1) {
|
|
21464
|
-
if (v) {
|
|
21465
|
-
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
|
21466
|
-
this[p] = true;
|
|
21467
|
-
} else {
|
|
21468
|
-
throw Error(cryptoUnavailable);
|
|
21469
|
-
}
|
|
21470
|
-
} else {
|
|
21471
|
-
this[p] = false;
|
|
21472
|
-
}
|
|
21473
|
-
} else {
|
|
21474
|
-
throw Error(invalidArgument + p + ": " + v);
|
|
21475
|
-
}
|
|
21476
|
-
}
|
|
21477
|
-
return this;
|
|
21478
|
-
}
|
|
21479
|
-
function cos(x2) {
|
|
21480
|
-
return new this(x2).cos();
|
|
21481
|
-
}
|
|
21482
|
-
function cosh(x2) {
|
|
21483
|
-
return new this(x2).cosh();
|
|
21484
|
-
}
|
|
21485
|
-
function clone(obj) {
|
|
21486
|
-
var i, p, ps;
|
|
21487
|
-
function Decimal(v) {
|
|
21488
|
-
var e, i2, t, x2 = this;
|
|
21489
|
-
if (!(x2 instanceof Decimal))
|
|
21490
|
-
return new Decimal(v);
|
|
21491
|
-
x2.constructor = Decimal;
|
|
21492
|
-
if (isDecimalInstance(v)) {
|
|
21493
|
-
x2.s = v.s;
|
|
21494
|
-
if (external2) {
|
|
21495
|
-
if (!v.d || v.e > Decimal.maxE) {
|
|
21496
|
-
x2.e = NaN;
|
|
21497
|
-
x2.d = null;
|
|
21498
|
-
} else if (v.e < Decimal.minE) {
|
|
21499
|
-
x2.e = 0;
|
|
21500
|
-
x2.d = [0];
|
|
21501
|
-
} else {
|
|
21502
|
-
x2.e = v.e;
|
|
21503
|
-
x2.d = v.d.slice();
|
|
21504
|
-
}
|
|
21505
|
-
} else {
|
|
21506
|
-
x2.e = v.e;
|
|
21507
|
-
x2.d = v.d ? v.d.slice() : v.d;
|
|
21508
|
-
}
|
|
21509
|
-
return;
|
|
21510
|
-
}
|
|
21511
|
-
t = typeof v;
|
|
21512
|
-
if (t === "number") {
|
|
21513
|
-
if (v === 0) {
|
|
21514
|
-
x2.s = 1 / v < 0 ? -1 : 1;
|
|
21515
|
-
x2.e = 0;
|
|
21516
|
-
x2.d = [0];
|
|
21517
|
-
return;
|
|
21518
|
-
}
|
|
21519
|
-
if (v < 0) {
|
|
21520
|
-
v = -v;
|
|
21521
|
-
x2.s = -1;
|
|
21522
|
-
} else {
|
|
21523
|
-
x2.s = 1;
|
|
21524
|
-
}
|
|
21525
|
-
if (v === ~~v && v < 1e7) {
|
|
21526
|
-
for (e = 0, i2 = v;i2 >= 10; i2 /= 10)
|
|
21527
|
-
e++;
|
|
21528
|
-
if (external2) {
|
|
21529
|
-
if (e > Decimal.maxE) {
|
|
21530
|
-
x2.e = NaN;
|
|
21531
|
-
x2.d = null;
|
|
21532
|
-
} else if (e < Decimal.minE) {
|
|
21533
|
-
x2.e = 0;
|
|
21534
|
-
x2.d = [0];
|
|
21535
|
-
} else {
|
|
21536
|
-
x2.e = e;
|
|
21537
|
-
x2.d = [v];
|
|
21538
|
-
}
|
|
21539
|
-
} else {
|
|
21540
|
-
x2.e = e;
|
|
21541
|
-
x2.d = [v];
|
|
21542
|
-
}
|
|
21543
|
-
return;
|
|
21544
|
-
}
|
|
21545
|
-
if (v * 0 !== 0) {
|
|
21546
|
-
if (!v)
|
|
21547
|
-
x2.s = NaN;
|
|
21548
|
-
x2.e = NaN;
|
|
21549
|
-
x2.d = null;
|
|
21550
|
-
return;
|
|
21551
|
-
}
|
|
21552
|
-
return parseDecimal(x2, v.toString());
|
|
21553
|
-
}
|
|
21554
|
-
if (t === "string") {
|
|
21555
|
-
if ((i2 = v.charCodeAt(0)) === 45) {
|
|
21556
|
-
v = v.slice(1);
|
|
21557
|
-
x2.s = -1;
|
|
21558
|
-
} else {
|
|
21559
|
-
if (i2 === 43)
|
|
21560
|
-
v = v.slice(1);
|
|
21561
|
-
x2.s = 1;
|
|
21562
|
-
}
|
|
21563
|
-
return isDecimal.test(v) ? parseDecimal(x2, v) : parseOther(x2, v);
|
|
21564
|
-
}
|
|
21565
|
-
if (t === "bigint") {
|
|
21566
|
-
if (v < 0) {
|
|
21567
|
-
v = -v;
|
|
21568
|
-
x2.s = -1;
|
|
21569
|
-
} else {
|
|
21570
|
-
x2.s = 1;
|
|
21571
|
-
}
|
|
21572
|
-
return parseDecimal(x2, v.toString());
|
|
21573
|
-
}
|
|
21574
|
-
throw Error(invalidArgument + v);
|
|
21575
|
-
}
|
|
21576
|
-
Decimal.prototype = P2;
|
|
21577
|
-
Decimal.ROUND_UP = 0;
|
|
21578
|
-
Decimal.ROUND_DOWN = 1;
|
|
21579
|
-
Decimal.ROUND_CEIL = 2;
|
|
21580
|
-
Decimal.ROUND_FLOOR = 3;
|
|
21581
|
-
Decimal.ROUND_HALF_UP = 4;
|
|
21582
|
-
Decimal.ROUND_HALF_DOWN = 5;
|
|
21583
|
-
Decimal.ROUND_HALF_EVEN = 6;
|
|
21584
|
-
Decimal.ROUND_HALF_CEIL = 7;
|
|
21585
|
-
Decimal.ROUND_HALF_FLOOR = 8;
|
|
21586
|
-
Decimal.EUCLID = 9;
|
|
21587
|
-
Decimal.config = Decimal.set = config;
|
|
21588
|
-
Decimal.clone = clone;
|
|
21589
|
-
Decimal.isDecimal = isDecimalInstance;
|
|
21590
|
-
Decimal.abs = abs;
|
|
21591
|
-
Decimal.acos = acos;
|
|
21592
|
-
Decimal.acosh = acosh;
|
|
21593
|
-
Decimal.add = add;
|
|
21594
|
-
Decimal.asin = asin;
|
|
21595
|
-
Decimal.asinh = asinh;
|
|
21596
|
-
Decimal.atan = atan;
|
|
21597
|
-
Decimal.atanh = atanh;
|
|
21598
|
-
Decimal.atan2 = atan2;
|
|
21599
|
-
Decimal.cbrt = cbrt;
|
|
21600
|
-
Decimal.ceil = ceil;
|
|
21601
|
-
Decimal.clamp = clamp;
|
|
21602
|
-
Decimal.cos = cos;
|
|
21603
|
-
Decimal.cosh = cosh;
|
|
21604
|
-
Decimal.div = div;
|
|
21605
|
-
Decimal.exp = exp;
|
|
21606
|
-
Decimal.floor = floor;
|
|
21607
|
-
Decimal.hypot = hypot;
|
|
21608
|
-
Decimal.ln = ln;
|
|
21609
|
-
Decimal.log = log;
|
|
21610
|
-
Decimal.log10 = log10;
|
|
21611
|
-
Decimal.log2 = log2;
|
|
21612
|
-
Decimal.max = max;
|
|
21613
|
-
Decimal.min = min;
|
|
21614
|
-
Decimal.mod = mod;
|
|
21615
|
-
Decimal.mul = mul;
|
|
21616
|
-
Decimal.pow = pow;
|
|
21617
|
-
Decimal.random = random;
|
|
21618
|
-
Decimal.round = round;
|
|
21619
|
-
Decimal.sign = sign;
|
|
21620
|
-
Decimal.sin = sin;
|
|
21621
|
-
Decimal.sinh = sinh;
|
|
21622
|
-
Decimal.sqrt = sqrt;
|
|
21623
|
-
Decimal.sub = sub;
|
|
21624
|
-
Decimal.sum = sum;
|
|
21625
|
-
Decimal.tan = tan;
|
|
21626
|
-
Decimal.tanh = tanh;
|
|
21627
|
-
Decimal.trunc = trunc;
|
|
21628
|
-
if (obj === undefined)
|
|
21629
|
-
obj = {};
|
|
21630
|
-
if (obj) {
|
|
21631
|
-
if (obj.defaults !== true) {
|
|
21632
|
-
ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
|
|
21633
|
-
for (i = 0;i < ps.length; )
|
|
21634
|
-
if (!obj.hasOwnProperty(p = ps[i++]))
|
|
21635
|
-
obj[p] = this[p];
|
|
21636
|
-
}
|
|
21637
|
-
}
|
|
21638
|
-
Decimal.config(obj);
|
|
21639
|
-
return Decimal;
|
|
21640
|
-
}
|
|
21641
|
-
function div(x2, y2) {
|
|
21642
|
-
return new this(x2).div(y2);
|
|
21643
|
-
}
|
|
21644
|
-
function exp(x2) {
|
|
21645
|
-
return new this(x2).exp();
|
|
21646
|
-
}
|
|
21647
|
-
function floor(x2) {
|
|
21648
|
-
return finalise(x2 = new this(x2), x2.e + 1, 3);
|
|
21649
|
-
}
|
|
21650
|
-
function hypot() {
|
|
21651
|
-
var i, n, t = new this(0);
|
|
21652
|
-
external2 = false;
|
|
21653
|
-
for (i = 0;i < arguments.length; ) {
|
|
21654
|
-
n = new this(arguments[i++]);
|
|
21655
|
-
if (!n.d) {
|
|
21656
|
-
if (n.s) {
|
|
21657
|
-
external2 = true;
|
|
21658
|
-
return new this(1 / 0);
|
|
21659
|
-
}
|
|
21660
|
-
t = n;
|
|
21661
|
-
} else if (t.d) {
|
|
21662
|
-
t = t.plus(n.times(n));
|
|
21663
|
-
}
|
|
21664
|
-
}
|
|
21665
|
-
external2 = true;
|
|
21666
|
-
return t.sqrt();
|
|
21667
|
-
}
|
|
21668
|
-
function isDecimalInstance(obj) {
|
|
21669
|
-
return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
|
|
21670
|
-
}
|
|
21671
|
-
function ln(x2) {
|
|
21672
|
-
return new this(x2).ln();
|
|
21673
|
-
}
|
|
21674
|
-
function log(x2, y2) {
|
|
21675
|
-
return new this(x2).log(y2);
|
|
21676
|
-
}
|
|
21677
|
-
function log2(x2) {
|
|
21678
|
-
return new this(x2).log(2);
|
|
21679
|
-
}
|
|
21680
|
-
function log10(x2) {
|
|
21681
|
-
return new this(x2).log(10);
|
|
21682
|
-
}
|
|
21683
|
-
function max() {
|
|
21684
|
-
return maxOrMin(this, arguments, -1);
|
|
21685
|
-
}
|
|
21686
|
-
function min() {
|
|
21687
|
-
return maxOrMin(this, arguments, 1);
|
|
21688
|
-
}
|
|
21689
|
-
function mod(x2, y2) {
|
|
21690
|
-
return new this(x2).mod(y2);
|
|
21691
|
-
}
|
|
21692
|
-
function mul(x2, y2) {
|
|
21693
|
-
return new this(x2).mul(y2);
|
|
21694
|
-
}
|
|
21695
|
-
function pow(x2, y2) {
|
|
21696
|
-
return new this(x2).pow(y2);
|
|
21697
|
-
}
|
|
21698
|
-
function random(sd) {
|
|
21699
|
-
var d, e, k3, n, i = 0, r = new this(1), rd = [];
|
|
21700
|
-
if (sd === undefined)
|
|
21701
|
-
sd = this.precision;
|
|
21702
|
-
else
|
|
21703
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
21704
|
-
k3 = Math.ceil(sd / LOG_BASE);
|
|
21705
|
-
if (!this.crypto) {
|
|
21706
|
-
for (;i < k3; )
|
|
21707
|
-
rd[i++] = Math.random() * 1e7 | 0;
|
|
21708
|
-
} else if (crypto.getRandomValues) {
|
|
21709
|
-
d = crypto.getRandomValues(new Uint32Array(k3));
|
|
21710
|
-
for (;i < k3; ) {
|
|
21711
|
-
n = d[i];
|
|
21712
|
-
if (n >= 4290000000) {
|
|
21713
|
-
d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
|
|
21714
|
-
} else {
|
|
21715
|
-
rd[i++] = n % 1e7;
|
|
21716
|
-
}
|
|
21717
|
-
}
|
|
21718
|
-
} else if (crypto.randomBytes) {
|
|
21719
|
-
d = crypto.randomBytes(k3 *= 4);
|
|
21720
|
-
for (;i < k3; ) {
|
|
21721
|
-
n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
|
|
21722
|
-
if (n >= 2140000000) {
|
|
21723
|
-
crypto.randomBytes(4).copy(d, i);
|
|
21724
|
-
} else {
|
|
21725
|
-
rd.push(n % 1e7);
|
|
21726
|
-
i += 4;
|
|
21727
|
-
}
|
|
21728
|
-
}
|
|
21729
|
-
i = k3 / 4;
|
|
21730
|
-
} else {
|
|
21731
|
-
throw Error(cryptoUnavailable);
|
|
21732
|
-
}
|
|
21733
|
-
k3 = rd[--i];
|
|
21734
|
-
sd %= LOG_BASE;
|
|
21735
|
-
if (k3 && sd) {
|
|
21736
|
-
n = mathpow(10, LOG_BASE - sd);
|
|
21737
|
-
rd[i] = (k3 / n | 0) * n;
|
|
21738
|
-
}
|
|
21739
|
-
for (;rd[i] === 0; i--)
|
|
21740
|
-
rd.pop();
|
|
21741
|
-
if (i < 0) {
|
|
21742
|
-
e = 0;
|
|
21743
|
-
rd = [0];
|
|
21744
|
-
} else {
|
|
21745
|
-
e = -1;
|
|
21746
|
-
for (;rd[0] === 0; e -= LOG_BASE)
|
|
21747
|
-
rd.shift();
|
|
21748
|
-
for (k3 = 1, n = rd[0];n >= 10; n /= 10)
|
|
21749
|
-
k3++;
|
|
21750
|
-
if (k3 < LOG_BASE)
|
|
21751
|
-
e -= LOG_BASE - k3;
|
|
21752
|
-
}
|
|
21753
|
-
r.e = e;
|
|
21754
|
-
r.d = rd;
|
|
21755
|
-
return r;
|
|
21756
|
-
}
|
|
21757
|
-
function round(x2) {
|
|
21758
|
-
return finalise(x2 = new this(x2), x2.e + 1, this.rounding);
|
|
21759
|
-
}
|
|
21760
|
-
function sign(x2) {
|
|
21761
|
-
x2 = new this(x2);
|
|
21762
|
-
return x2.d ? x2.d[0] ? x2.s : 0 * x2.s : x2.s || NaN;
|
|
21763
|
-
}
|
|
21764
|
-
function sin(x2) {
|
|
21765
|
-
return new this(x2).sin();
|
|
21766
|
-
}
|
|
21767
|
-
function sinh(x2) {
|
|
21768
|
-
return new this(x2).sinh();
|
|
21769
|
-
}
|
|
21770
|
-
function sqrt(x2) {
|
|
21771
|
-
return new this(x2).sqrt();
|
|
21772
|
-
}
|
|
21773
|
-
function sub(x2, y2) {
|
|
21774
|
-
return new this(x2).sub(y2);
|
|
21775
|
-
}
|
|
21776
|
-
function sum() {
|
|
21777
|
-
var i = 0, args = arguments, x2 = new this(args[i]);
|
|
21778
|
-
external2 = false;
|
|
21779
|
-
for (;x2.s && ++i < args.length; )
|
|
21780
|
-
x2 = x2.plus(args[i]);
|
|
21781
|
-
external2 = true;
|
|
21782
|
-
return finalise(x2, this.precision, this.rounding);
|
|
21783
|
-
}
|
|
21784
|
-
function tan(x2) {
|
|
21785
|
-
return new this(x2).tan();
|
|
21786
|
-
}
|
|
21787
|
-
function tanh(x2) {
|
|
21788
|
-
return new this(x2).tanh();
|
|
21789
|
-
}
|
|
21790
|
-
function trunc(x2) {
|
|
21791
|
-
return finalise(x2 = new this(x2), x2.e + 1, 1);
|
|
21792
|
-
}
|
|
21793
|
-
P2[Symbol.for("nodejs.util.inspect.custom")] = P2.toString;
|
|
21794
|
-
P2[Symbol.toStringTag] = "Decimal";
|
|
21795
|
-
var Decimal = P2.constructor = clone(DEFAULTS);
|
|
21796
|
-
LN10 = new Decimal(LN10);
|
|
21797
|
-
PI = new Decimal(PI);
|
|
21798
|
-
var decimal_default = Decimal;
|
|
21799
|
-
|
|
21800
|
-
// src/common/base/other.ts
|
|
21801
|
-
var delay = (time = 1000) => {
|
|
21802
|
-
return new Promise((resolve) => setTimeout(resolve, time));
|
|
21803
|
-
};
|
|
21804
|
-
var calcJsText = (expr, context) => {
|
|
21805
|
-
const keys = Object.keys(context);
|
|
21806
|
-
const values = keys.map((key2) => context[key2]);
|
|
21807
|
-
return Function(...keys, `return (${expr})`)(...values);
|
|
21808
|
-
};
|
|
21809
|
-
var optionsToEnum = (options, text, key2) => {
|
|
21810
|
-
return options.reduce((acc, cur) => {
|
|
21811
|
-
acc[cur[key2]] = {
|
|
21812
|
-
text: cur[text]
|
|
21813
|
-
};
|
|
21814
|
-
return acc;
|
|
21815
|
-
}, {});
|
|
21816
|
-
};
|
|
21817
|
-
var performDecimalOperation = (num1, num2, operator) => {
|
|
21818
|
-
if (num1 === undefined || num2 === undefined || !operator) {
|
|
21819
|
-
return;
|
|
21820
|
-
}
|
|
21821
|
-
const decimalNum1 = new decimal_default(Number(num1));
|
|
21822
|
-
const decimalNum2 = new decimal_default(Number(num2));
|
|
21823
|
-
switch (operator) {
|
|
21824
|
-
case "+":
|
|
21825
|
-
return decimalNum1.plus(decimalNum2).toNumber();
|
|
21826
|
-
case "-":
|
|
21827
|
-
return decimalNum1.minus(decimalNum2).toNumber();
|
|
21828
|
-
case "*":
|
|
21829
|
-
return decimalNum1.times(decimalNum2).toNumber();
|
|
21830
|
-
case "/":
|
|
21831
|
-
if (num2 !== 0) {
|
|
21832
|
-
return decimalNum1.dividedBy(decimalNum2).toNumber();
|
|
21833
|
-
} else {
|
|
21834
|
-
console.error("Division by zero is not allowed.");
|
|
21835
|
-
return NaN;
|
|
21836
|
-
}
|
|
21837
|
-
default:
|
|
21838
|
-
console.error("Invalid operator:", operator);
|
|
21839
|
-
return NaN;
|
|
21840
|
-
}
|
|
21841
|
-
};
|
|
21842
|
-
var printConsoleLog = (type, path, params, response) => {
|
|
21843
|
-
const styles = {
|
|
21844
|
-
header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
|
|
21845
|
-
value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
|
|
21846
|
-
separator: "color: #409EFF; margin: 0 4px;"
|
|
21847
|
-
};
|
|
21848
|
-
console.groupCollapsed(`666 %c${type}%c${path}`, styles.header, styles.value);
|
|
21849
|
-
if (params) {
|
|
21850
|
-
console.table(params);
|
|
21851
|
-
}
|
|
21852
|
-
if (response) {
|
|
21853
|
-
console.table(response);
|
|
21854
|
-
}
|
|
21855
|
-
console.groupEnd();
|
|
21856
|
-
};
|
|
21857
|
-
|
|
21858
|
-
// src/common/base/array.ts
|
|
21859
|
-
var shuffleArray = (array) => {
|
|
21860
|
-
const shuffledArray = [...array];
|
|
21861
|
-
for (let i = shuffledArray.length - 1;i > 0; i--) {
|
|
21862
|
-
const j3 = Math.floor(Math.random() * (i + 1));
|
|
21863
|
-
[shuffledArray[i], shuffledArray[j3]] = [shuffledArray[j3], shuffledArray[i]];
|
|
21864
|
-
}
|
|
21865
|
-
return shuffledArray;
|
|
21866
|
-
};
|
|
21867
|
-
var removeSimilarDuplicates = (arr, threshold, isLog) => {
|
|
21868
|
-
const uniqueArray = [];
|
|
21869
|
-
const similarPairs = [];
|
|
21870
|
-
for (const str of arr) {
|
|
21871
|
-
const isSimilar = uniqueArray.some((uniqueStr) => {
|
|
21872
|
-
const distance = levenshteinDistance(str, uniqueStr);
|
|
21873
|
-
if (distance <= threshold) {
|
|
21874
|
-
similarPairs.push([str, uniqueStr]);
|
|
21875
|
-
return true;
|
|
21876
|
-
}
|
|
21877
|
-
return false;
|
|
21878
|
-
});
|
|
21879
|
-
if (!isSimilar) {
|
|
21880
|
-
uniqueArray.push(str);
|
|
21881
|
-
}
|
|
21882
|
-
}
|
|
21883
|
-
if (isLog) {
|
|
21884
|
-
if (similarPairs.length > 0) {
|
|
21885
|
-
similarPairs.forEach((pair) => {
|
|
21886
|
-
console.log(pair[0]);
|
|
21887
|
-
console.log(pair[1]);
|
|
21888
|
-
console.log();
|
|
21889
|
-
});
|
|
21890
|
-
} else {
|
|
21891
|
-
console.log("没有找到类似的字符串");
|
|
21892
|
-
}
|
|
21893
|
-
}
|
|
21894
|
-
return uniqueArray;
|
|
21895
|
-
};
|
|
21896
|
-
var getTotal = (arr, key2) => {
|
|
21897
|
-
if (!Array.isArray(arr) || !key2) {
|
|
21898
|
-
return 0;
|
|
21899
|
-
}
|
|
21900
|
-
return arr.reduce((total, item) => {
|
|
21901
|
-
const itemValue = Number(item[key2]);
|
|
21902
|
-
if (!isNaN(itemValue)) {
|
|
21903
|
-
return performDecimalOperation(total, itemValue, "+");
|
|
21904
|
-
}
|
|
21905
|
-
return total;
|
|
21906
|
-
}, 0);
|
|
21907
|
-
};
|
|
21908
|
-
|
|
21909
|
-
// src/common/base/number.ts
|
|
21910
|
-
var getRandomNum = (min2, max2) => {
|
|
21911
|
-
return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
|
|
21912
|
-
};
|
|
21913
|
-
var limitDecimals = (v, num = 2, isForce) => {
|
|
21914
|
-
let value = parseFloat(v);
|
|
21915
|
-
if (isNaN(value)) {
|
|
21916
|
-
if (isForce) {
|
|
21917
|
-
value = 0;
|
|
21918
|
-
} else {
|
|
21919
|
-
return "";
|
|
21920
|
-
}
|
|
21921
|
-
}
|
|
21922
|
-
return value.toFixed(num).toString();
|
|
21923
|
-
};
|
|
21924
|
-
var getFileSize = (size) => {
|
|
21925
|
-
let d = "G";
|
|
21926
|
-
let s = size / 1024 / 1024 / 1024;
|
|
21927
|
-
if (s < 1) {
|
|
21928
|
-
d = "M";
|
|
21929
|
-
s *= 1024;
|
|
21930
|
-
}
|
|
21931
|
-
return `${(s.toFixed(1) / 1).toString()}${d}`;
|
|
21932
|
-
};
|
|
21933
|
-
var isValidNumber = (value) => {
|
|
21934
|
-
if (typeof value !== "number") {
|
|
21935
|
-
return false;
|
|
21936
|
-
}
|
|
21937
|
-
if (isNaN(value)) {
|
|
21938
|
-
return false;
|
|
21939
|
-
}
|
|
21940
|
-
if (value === Infinity || value === -Infinity) {
|
|
21941
|
-
return false;
|
|
21942
|
-
}
|
|
21943
|
-
return true;
|
|
21944
|
-
};
|
|
21945
|
-
var numberWithCommas = (x2) => {
|
|
21946
|
-
if (x2 === undefined || x2 === null) {
|
|
21947
|
-
return "";
|
|
21948
|
-
}
|
|
21949
|
-
return x2.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
21950
|
-
};
|
|
21951
|
-
|
|
21952
|
-
// src/common/base/object.ts
|
|
21953
|
-
var findItem = (list, attr, value) => {
|
|
21954
|
-
return list.find((item) => value === undefined ? item[attr] : item[attr] === value);
|
|
21955
|
-
};
|
|
21956
|
-
var filterParams = (params, deep = false) => {
|
|
21957
|
-
const clean = (value) => {
|
|
21958
|
-
if (value === undefined || value === null) {
|
|
21959
|
-
return;
|
|
21960
|
-
}
|
|
21961
|
-
if (!deep) {
|
|
21962
|
-
return value;
|
|
21963
|
-
}
|
|
21964
|
-
if (Array.isArray(value)) {
|
|
21965
|
-
return value.map((v) => clean(v)).filter((v) => v !== undefined);
|
|
21966
|
-
}
|
|
21967
|
-
if (typeof value === "object") {
|
|
21968
|
-
return Object.entries(value).reduce((acc, [k3, v]) => {
|
|
21969
|
-
const cleaned = clean(v);
|
|
21970
|
-
if (cleaned !== undefined)
|
|
21971
|
-
acc[k3] = cleaned;
|
|
21972
|
-
return acc;
|
|
21973
|
-
}, {});
|
|
21974
|
-
}
|
|
21975
|
-
return value;
|
|
21976
|
-
};
|
|
21977
|
-
return clean(params);
|
|
21978
|
-
};
|
|
21979
|
-
var watch = {
|
|
21980
|
-
observe(obj, key2, watchFun) {
|
|
21981
|
-
const val = obj[key2];
|
|
21982
|
-
Object.defineProperty(obj, key2, {
|
|
21983
|
-
configurable: true,
|
|
21984
|
-
enumerable: true,
|
|
21985
|
-
set(value) {
|
|
21986
|
-
obj[key2] = value;
|
|
21987
|
-
watchFun(value, val);
|
|
21988
|
-
},
|
|
21989
|
-
get() {
|
|
21990
|
-
return val;
|
|
21991
|
-
}
|
|
21992
|
-
});
|
|
21993
|
-
},
|
|
21994
|
-
setWatcher(data = {}, watch2 = {}) {
|
|
21995
|
-
Object.keys(watch2).forEach((v) => {
|
|
21996
|
-
this.observe(data, v, watch2[v]);
|
|
21997
|
-
});
|
|
21998
|
-
}
|
|
21999
|
-
};
|
|
22000
|
-
|
|
22001
|
-
// src/common/base/promise.ts
|
|
22002
|
-
var executePromise = async (promise) => {
|
|
22003
|
-
const start = Date.now();
|
|
22004
|
-
const result = await promise;
|
|
22005
|
-
const time = Date.now() - start;
|
|
22006
|
-
return {
|
|
22007
|
-
result,
|
|
22008
|
-
time
|
|
22009
|
-
};
|
|
22010
|
-
};
|
|
22011
|
-
var retryPromise = async (promiseFn, retryInterval = 1000, retryCount = 3) => {
|
|
22012
|
-
try {
|
|
22013
|
-
return await promiseFn();
|
|
22014
|
-
} catch (error) {
|
|
22015
|
-
if (retryCount <= 0) {
|
|
22016
|
-
throw error;
|
|
22017
|
-
}
|
|
22018
|
-
await new Promise((resolve) => setTimeout(resolve, retryInterval));
|
|
22019
|
-
return retryPromise(promiseFn, retryCount - 1, retryInterval);
|
|
22020
|
-
}
|
|
22021
|
-
};
|
|
22022
|
-
// src/common/enum.ts
|
|
22023
|
-
class EnumItem {
|
|
22024
|
-
label;
|
|
22025
|
-
value;
|
|
22026
|
-
extra;
|
|
22027
|
-
constructor(config2) {
|
|
22028
|
-
this.value = config2.value;
|
|
22029
|
-
this.label = config2.label;
|
|
22030
|
-
this.extra = config2.extra;
|
|
22031
|
-
}
|
|
22032
|
-
}
|
|
22033
|
-
var Enum = {
|
|
22034
|
-
create: (members) => {
|
|
22035
|
-
const usedValues = new Set;
|
|
22036
|
-
const enumObj = {};
|
|
22037
|
-
const map = new Map;
|
|
22038
|
-
const options = [];
|
|
22039
|
-
const extras = new Map;
|
|
22040
|
-
const labels = new Map;
|
|
22041
|
-
const enums = {};
|
|
22042
|
-
for (const key2 in members) {
|
|
22043
|
-
const member = members[key2];
|
|
22044
|
-
if (!member)
|
|
22045
|
-
continue;
|
|
22046
|
-
if (usedValues.has(member.value)) {
|
|
22047
|
-
throw new Error(`Duplicate enum value detected: ${member.value}`);
|
|
22048
|
-
}
|
|
22049
|
-
usedValues.add(member.value);
|
|
22050
|
-
const item = new EnumItem(member);
|
|
22051
|
-
enumObj[key2] = item;
|
|
22052
|
-
map.set(item.value, item);
|
|
22053
|
-
labels.set(item.value, item.label);
|
|
22054
|
-
options.push(item);
|
|
22055
|
-
enums[item.value] = { text: item.label, status: item.extra?.status };
|
|
22056
|
-
if (member.extra !== undefined) {
|
|
22057
|
-
extras.set(item.value, { ...member.extra });
|
|
22058
|
-
}
|
|
22059
|
-
}
|
|
22060
|
-
enumObj.map = map;
|
|
22061
|
-
enumObj.options = options;
|
|
22062
|
-
enumObj.extras = extras;
|
|
22063
|
-
enumObj.source = members;
|
|
22064
|
-
enumObj.labels = labels;
|
|
22065
|
-
enumObj.enums = enums;
|
|
22066
|
-
return enumObj;
|
|
22067
|
-
}
|
|
22068
|
-
};
|
|
22069
|
-
// src/common/image.ts
|
|
22070
|
-
async function imageToBase64(url) {
|
|
22071
|
-
try {
|
|
22072
|
-
const response = await axios_default.get(url, {
|
|
22073
|
-
responseType: "arraybuffer"
|
|
22074
|
-
});
|
|
22075
|
-
const base64String = Buffer.from(response.data).toString("base64");
|
|
22076
|
-
return `data:image/*;base64,${base64String}`;
|
|
22077
|
-
} catch (error) {
|
|
22078
|
-
console.error("Failed to fetch the image:", error);
|
|
22079
|
-
throw error;
|
|
22080
|
-
}
|
|
22081
|
-
}
|
|
22082
|
-
// src/common/dayjs.ts
|
|
22083
|
-
var import_dayjs = __toESM(require_dayjs_min());
|
|
22084
|
-
var import_isBetween = __toESM(require_isBetween());
|
|
22085
|
-
var import_weekday = __toESM(require_weekday());
|
|
22086
|
-
var import_localeData = __toESM(require_localeData());
|
|
22087
|
-
var import_isoWeek = __toESM(require_isoWeek());
|
|
22088
|
-
var import_updateLocale = __toESM(require_updateLocale());
|
|
22089
|
-
var import_timezone = __toESM(require_timezone());
|
|
22090
|
-
var import_isSameOrAfter = __toESM(require_isSameOrAfter());
|
|
22091
|
-
var import_isSameOrBefore = __toESM(require_isSameOrBefore());
|
|
22092
|
-
var import_utc = __toESM(require_utc());
|
|
22093
|
-
var import_zh_cn = __toESM(require_zh_cn());
|
|
22094
|
-
var import_dayjs2 = __toESM(require_dayjs_min());
|
|
22095
|
-
import_dayjs.default.extend(import_utc.default);
|
|
22096
|
-
import_dayjs.default.extend(import_isBetween.default);
|
|
22097
|
-
import_dayjs.default.extend(import_weekday.default);
|
|
22098
|
-
import_dayjs.default.extend(import_localeData.default);
|
|
22099
|
-
import_dayjs.default.extend(import_isoWeek.default);
|
|
22100
|
-
import_dayjs.default.extend(import_updateLocale.default);
|
|
22101
|
-
import_dayjs.default.extend(import_timezone.default);
|
|
22102
|
-
import_dayjs.default.extend(import_isSameOrAfter.default);
|
|
22103
|
-
import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
22104
|
-
var Timezone;
|
|
22105
|
-
((Timezone2) => {
|
|
22106
|
-
Timezone2["AsiaShanghai"] = "Asia/Shanghai";
|
|
22107
|
-
Timezone2["AsiaTokyo"] = "Asia/Tokyo";
|
|
22108
|
-
Timezone2["AmericaNewYork"] = "America/New_York";
|
|
22109
|
-
Timezone2["EuropeLondon"] = "Europe/London";
|
|
22110
|
-
Timezone2["EuropeBerlin"] = "Europe/Berlin";
|
|
22111
|
-
})(Timezone ||= {});
|
|
22112
|
-
var initChinaDayjs = () => {
|
|
22113
|
-
import_dayjs.default.locale("zh-cn");
|
|
22114
|
-
import_dayjs.default.tz.setDefault("Asia/Shanghai" /* AsiaShanghai */);
|
|
22115
|
-
import_dayjs.default.updateLocale("zh-cn", {
|
|
22116
|
-
weekStart: 1
|
|
22117
|
-
});
|
|
22118
|
-
return import_dayjs.default;
|
|
22119
|
-
};
|
|
22120
|
-
var chinaDayjs = initChinaDayjs();
|
|
22121
|
-
var dayjs_default = import_dayjs.default;
|
|
22122
|
-
// src/web/element.ts
|
|
22123
|
-
var scrollIntoView = (el, option) => {
|
|
22124
|
-
if (!el) {
|
|
22125
|
-
return;
|
|
22126
|
-
}
|
|
22127
|
-
el.scrollIntoView({ behavior: "smooth", block: "start", ...option });
|
|
18998
|
+
el.scrollIntoView({ behavior: "smooth", block: "start", ...option });
|
|
22128
18999
|
};
|
|
22129
19000
|
var getElement = (el) => {
|
|
22130
19001
|
const element = typeof el === "string" ? document.querySelector(el) : el;
|
|
@@ -22238,3 +19109,6 @@ var readClipboard = async () => {
|
|
|
22238
19109
|
return "";
|
|
22239
19110
|
}
|
|
22240
19111
|
};
|
|
19112
|
+
|
|
19113
|
+
// src/web.ts
|
|
19114
|
+
console.log(666, 16);
|