@cjhd/cj-decimal 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/Decimal.d.ts +464 -0
- package/dist/cocos/assets/Decimal.js +4 -0
- package/dist/cocos/index.js +4 -0
- package/{index.ts → index.d.ts} +2 -2
- package/package.json +26 -7
- package/assets/Decimal.ts +0 -1428
- package/assets/Decimal.ts.meta +0 -9
- package/assets.meta +0 -9
- package/index.ts.meta +0 -9
- package/package.json.meta +0 -11
- /package/{.cj-decimal.md → README.md} +0 -0
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
type DecimalSign = 1 | -1;
|
|
2
|
+
type IntNumber = number;
|
|
3
|
+
/**
|
|
4
|
+
* Decimal 原地修改观察器。
|
|
5
|
+
* 默认不绑定,只有 @EcsObservedDecimal 这类业务装饰器显式绑定后才会触发。
|
|
6
|
+
*/
|
|
7
|
+
export interface IDecimalMutationObserver {
|
|
8
|
+
onDecimalMutated(decimal: Decimal): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 定点数计算
|
|
12
|
+
*/
|
|
13
|
+
export declare class Decimal {
|
|
14
|
+
static copy(other: Decimal): Decimal;
|
|
15
|
+
static createInt(value: IntNumber): Decimal;
|
|
16
|
+
static createFloat(value: string): Decimal;
|
|
17
|
+
static create(sign: DecimalSign, v1: IntNumber, v2: IntNumber): Decimal;
|
|
18
|
+
/**
|
|
19
|
+
* 精确度保留n位小数点, 默认是8。
|
|
20
|
+
* @description 注意整数与小数部分长度和不要超过16位,并且整数位大小不要超过「9 * Math.pow(10, 15-n)」,否则运算过程中会出现大整数导致的精度丢失。
|
|
21
|
+
*/
|
|
22
|
+
static set accuracy(value: IntNumber);
|
|
23
|
+
static get accuracy(): IntNumber;
|
|
24
|
+
/**
|
|
25
|
+
* 180度对应的弧度值 (不要修改此值)
|
|
26
|
+
*/
|
|
27
|
+
static get PI(): Decimal;
|
|
28
|
+
/**
|
|
29
|
+
* 180度的一半(90度)对应的弧度值 (不要修改此值)
|
|
30
|
+
*/
|
|
31
|
+
static get PI_HALF(): Decimal;
|
|
32
|
+
/**
|
|
33
|
+
* 1度对应的弧度值 (不要修改此值)
|
|
34
|
+
*/
|
|
35
|
+
static get DEG_TO_RAD(): Decimal;
|
|
36
|
+
/**
|
|
37
|
+
* 1弧度对应的角度值 (不要修改此值)
|
|
38
|
+
*/
|
|
39
|
+
static get RAD_TO_DEG(): Decimal;
|
|
40
|
+
/**
|
|
41
|
+
* 0
|
|
42
|
+
*/
|
|
43
|
+
static get zero(): Decimal;
|
|
44
|
+
/**
|
|
45
|
+
* 0 (不要修改此值)
|
|
46
|
+
*/
|
|
47
|
+
static get ZERO(): Decimal;
|
|
48
|
+
/**
|
|
49
|
+
* 1
|
|
50
|
+
*/
|
|
51
|
+
static get one(): Decimal;
|
|
52
|
+
/**
|
|
53
|
+
* 1 (不要修改此值)
|
|
54
|
+
*/
|
|
55
|
+
static get ONE(): Decimal;
|
|
56
|
+
/**
|
|
57
|
+
* 2
|
|
58
|
+
*/
|
|
59
|
+
static get two(): Decimal;
|
|
60
|
+
/**
|
|
61
|
+
* 2 (不要修改此值)
|
|
62
|
+
*/
|
|
63
|
+
static get TWO(): Decimal;
|
|
64
|
+
/**
|
|
65
|
+
* -1
|
|
66
|
+
*/
|
|
67
|
+
static get(): Decimal;
|
|
68
|
+
/**
|
|
69
|
+
* -1 (不要修改此值)
|
|
70
|
+
*/
|
|
71
|
+
static get MINUS(): Decimal;
|
|
72
|
+
/**
|
|
73
|
+
* NaN
|
|
74
|
+
*/
|
|
75
|
+
static get NaN(): Decimal;
|
|
76
|
+
/**
|
|
77
|
+
* 取较大
|
|
78
|
+
*/
|
|
79
|
+
static max(...args: Decimal[]): Decimal;
|
|
80
|
+
/**
|
|
81
|
+
* 取较小
|
|
82
|
+
*/
|
|
83
|
+
static min(...args: Decimal[]): Decimal;
|
|
84
|
+
/**
|
|
85
|
+
* 弧度转角度
|
|
86
|
+
*/
|
|
87
|
+
static radiansToDegrees(out: Decimal, radians: Decimal): Decimal;
|
|
88
|
+
/**
|
|
89
|
+
* 角度转弧度
|
|
90
|
+
* @param out 输出结果
|
|
91
|
+
* @param degrees 角度
|
|
92
|
+
* @returns 结果
|
|
93
|
+
*/
|
|
94
|
+
static degreesToRadians(out: Decimal, degrees: Decimal): Decimal;
|
|
95
|
+
/**
|
|
96
|
+
* 正弦函数
|
|
97
|
+
*/
|
|
98
|
+
static sin(out: Decimal, angle: Decimal): Decimal;
|
|
99
|
+
/**
|
|
100
|
+
* 余弦函数
|
|
101
|
+
*/
|
|
102
|
+
static cos(out: Decimal, angle: Decimal): Decimal;
|
|
103
|
+
/**
|
|
104
|
+
* 正切函数
|
|
105
|
+
*/
|
|
106
|
+
static tan(out: Decimal, angle: Decimal): Decimal;
|
|
107
|
+
/**
|
|
108
|
+
* 计算反正弦
|
|
109
|
+
*/
|
|
110
|
+
static asin(out: Decimal, value: Decimal): Decimal;
|
|
111
|
+
/**
|
|
112
|
+
* 计算反余弦
|
|
113
|
+
*/
|
|
114
|
+
static acos(out: Decimal, value: Decimal): Decimal;
|
|
115
|
+
/**
|
|
116
|
+
* 计算反正切
|
|
117
|
+
*/
|
|
118
|
+
static atan(out: Decimal, value: Decimal): Decimal;
|
|
119
|
+
/**
|
|
120
|
+
* 计算反正切,给定 x 和 y 的值
|
|
121
|
+
*/
|
|
122
|
+
static atan2(out: Decimal, y: Decimal, x: Decimal): Decimal;
|
|
123
|
+
private _sign;
|
|
124
|
+
get sign(): DecimalSign;
|
|
125
|
+
private set sign(value);
|
|
126
|
+
private _v1;
|
|
127
|
+
get v1(): IntNumber;
|
|
128
|
+
private set v1(value);
|
|
129
|
+
private _v2;
|
|
130
|
+
get v2(): IntNumber;
|
|
131
|
+
private set v2(value);
|
|
132
|
+
/** 可选 observer。默认 null,算法 scratch Decimal 不承担观察成本。 */
|
|
133
|
+
private __observer;
|
|
134
|
+
/** 嵌套 mutation 深度,用于 batch 合并多次原地修改。 */
|
|
135
|
+
private __mutationDepth;
|
|
136
|
+
/** batch 内是否发生过实际数值变化。 */
|
|
137
|
+
private __mutationPending;
|
|
138
|
+
/** 静默写入深度。大批量业务写屏障可用 setSilent/copySilent 后手动 markDirty。 */
|
|
139
|
+
private __silentDepth;
|
|
140
|
+
/**
|
|
141
|
+
* 绑定或解绑 Decimal mutation observer。
|
|
142
|
+
* 仅 @EcsObservedDecimal 管理的组件字段需要绑定;普通 Decimal、SAT/MTV 临时值不要绑定。
|
|
143
|
+
*/
|
|
144
|
+
bindMutationObserver(observer: IDecimalMutationObserver | null): this;
|
|
145
|
+
/** 开始合并多次 Decimal 修改,直到 endMutationBatch 才通知一次 observer。 */
|
|
146
|
+
beginMutationBatch(): this;
|
|
147
|
+
/** 结束 batch;如果期间值发生变化且已回到最外层,则通知一次 observer。 */
|
|
148
|
+
endMutationBatch(): this;
|
|
149
|
+
/** 用函数作用域包住 batch,避免异常时忘记 endMutationBatch。 */
|
|
150
|
+
runMutationBatch<T>(action: () => T): T;
|
|
151
|
+
/** 静默执行 Decimal 修改,不通知 observer。适合业务写屏障合并后手动 markDirty。 */
|
|
152
|
+
runSilentMutation<T>(action: () => T): T;
|
|
153
|
+
/** 静默 set,不触发 Decimal observer。 */
|
|
154
|
+
setSilent(sign?: DecimalSign, v1?: IntNumber, v2?: IntNumber): this;
|
|
155
|
+
/** 静默 copy,不触发 Decimal observer。 */
|
|
156
|
+
copySilent(other: Decimal): this;
|
|
157
|
+
private static compareAbs;
|
|
158
|
+
private static compareSigned;
|
|
159
|
+
private normalizeZero;
|
|
160
|
+
private snapshot;
|
|
161
|
+
private changedSince;
|
|
162
|
+
/** 所有会原地修改 Decimal 的 public 方法都应通过这里包裹,确保值变才通知。 */
|
|
163
|
+
private runMutation;
|
|
164
|
+
/** batch/silent 状态允许时,把一次已合并的 mutation 通知给 observer。 */
|
|
165
|
+
private flushMutationObserverIfReady;
|
|
166
|
+
private setAbsSub;
|
|
167
|
+
private setAbsAdd;
|
|
168
|
+
private setFromRawBigInt;
|
|
169
|
+
/**
|
|
170
|
+
* 用于等号赋值
|
|
171
|
+
* @example
|
|
172
|
+
* const a = new Decimal('1');
|
|
173
|
+
* const b = new Decimal('10');
|
|
174
|
+
* a.value = b;
|
|
175
|
+
*/
|
|
176
|
+
set value(other: Decimal);
|
|
177
|
+
/**
|
|
178
|
+
* 传入字符串数字
|
|
179
|
+
* @param value 字符串数字(不支持科学计数)
|
|
180
|
+
*/
|
|
181
|
+
constructor(value: string);
|
|
182
|
+
/**
|
|
183
|
+
* 构造 0
|
|
184
|
+
*/
|
|
185
|
+
constructor();
|
|
186
|
+
/**
|
|
187
|
+
* 设置, 默认为0
|
|
188
|
+
*/
|
|
189
|
+
set(sign?: DecimalSign, v1?: IntNumber, v2?: IntNumber): this;
|
|
190
|
+
/**
|
|
191
|
+
* 通过float字符串设置, 默认为0
|
|
192
|
+
*/
|
|
193
|
+
setFloat(value?: string): this;
|
|
194
|
+
/**
|
|
195
|
+
* 通过int设置, 默认为0
|
|
196
|
+
*/
|
|
197
|
+
setInt(value?: IntNumber): this;
|
|
198
|
+
/**
|
|
199
|
+
* 通过其他Decimal设置
|
|
200
|
+
*/
|
|
201
|
+
copy(other: Decimal): this;
|
|
202
|
+
/**
|
|
203
|
+
* 转为浮点数
|
|
204
|
+
* @param strict 严格模式,默认关闭。开启后额外消耗性能,避免定点数转小数时出现精度问题。
|
|
205
|
+
*/
|
|
206
|
+
toNumber(strict?: boolean): number;
|
|
207
|
+
/**
|
|
208
|
+
* 转为字符串
|
|
209
|
+
*/
|
|
210
|
+
toString(): string;
|
|
211
|
+
/**
|
|
212
|
+
* 转为大整数
|
|
213
|
+
*/
|
|
214
|
+
toBigInt(): IntNumber;
|
|
215
|
+
/**
|
|
216
|
+
* 是否为0
|
|
217
|
+
*/
|
|
218
|
+
isZero(): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* 是否是负数
|
|
221
|
+
*/
|
|
222
|
+
isNegative(): boolean;
|
|
223
|
+
/**
|
|
224
|
+
* 是否是NaN
|
|
225
|
+
*/
|
|
226
|
+
isNaN(): boolean;
|
|
227
|
+
/**
|
|
228
|
+
* 克隆
|
|
229
|
+
*/
|
|
230
|
+
clone(): Decimal;
|
|
231
|
+
/**
|
|
232
|
+
* 向下取整
|
|
233
|
+
*/
|
|
234
|
+
floor(): this;
|
|
235
|
+
/**
|
|
236
|
+
* 向上取整
|
|
237
|
+
*/
|
|
238
|
+
ceil(): this;
|
|
239
|
+
/**
|
|
240
|
+
* 四舍五入
|
|
241
|
+
*/
|
|
242
|
+
round(): this;
|
|
243
|
+
/**
|
|
244
|
+
* 绝对值
|
|
245
|
+
*/
|
|
246
|
+
abs(): Decimal;
|
|
247
|
+
/**
|
|
248
|
+
* @deprecated 使用negative代替
|
|
249
|
+
*/
|
|
250
|
+
reverse(): Decimal;
|
|
251
|
+
/**
|
|
252
|
+
* 相反数
|
|
253
|
+
*/
|
|
254
|
+
negative(): Decimal;
|
|
255
|
+
/**
|
|
256
|
+
* 倒数
|
|
257
|
+
*/
|
|
258
|
+
reciprocal(): Decimal;
|
|
259
|
+
/**
|
|
260
|
+
* 加法
|
|
261
|
+
* @param other
|
|
262
|
+
*/
|
|
263
|
+
add(other: Decimal): Decimal;
|
|
264
|
+
/**
|
|
265
|
+
* 加法
|
|
266
|
+
* @param other
|
|
267
|
+
*/
|
|
268
|
+
addInt(other: IntNumber): Decimal;
|
|
269
|
+
/**
|
|
270
|
+
* 加法
|
|
271
|
+
* @param other
|
|
272
|
+
*/
|
|
273
|
+
addFloat(other: string): Decimal;
|
|
274
|
+
/**
|
|
275
|
+
* 减法
|
|
276
|
+
* @param other
|
|
277
|
+
*/
|
|
278
|
+
sub(other: Decimal): Decimal;
|
|
279
|
+
/**
|
|
280
|
+
* 减法
|
|
281
|
+
* @param other
|
|
282
|
+
*/
|
|
283
|
+
subInt(other: IntNumber): Decimal;
|
|
284
|
+
/**
|
|
285
|
+
* 减法
|
|
286
|
+
* @param other
|
|
287
|
+
*/
|
|
288
|
+
subFloat(other: string): Decimal;
|
|
289
|
+
/**
|
|
290
|
+
* 乘法
|
|
291
|
+
* @param other
|
|
292
|
+
*/
|
|
293
|
+
mul(other: Decimal): Decimal;
|
|
294
|
+
/**
|
|
295
|
+
* 乘法
|
|
296
|
+
* @param other
|
|
297
|
+
*/
|
|
298
|
+
mulInt(other: IntNumber): Decimal;
|
|
299
|
+
/**
|
|
300
|
+
* 乘法
|
|
301
|
+
* @param other
|
|
302
|
+
*/
|
|
303
|
+
mulFloat(other: string): Decimal;
|
|
304
|
+
/**
|
|
305
|
+
* 除法
|
|
306
|
+
* @param other
|
|
307
|
+
*/
|
|
308
|
+
div(other: Decimal): Decimal;
|
|
309
|
+
/**
|
|
310
|
+
* 除法
|
|
311
|
+
* @param other
|
|
312
|
+
*/
|
|
313
|
+
divInt(other: IntNumber): Decimal;
|
|
314
|
+
/**
|
|
315
|
+
* 除法
|
|
316
|
+
* @param other
|
|
317
|
+
*/
|
|
318
|
+
divFloat(other: string): Decimal;
|
|
319
|
+
/**
|
|
320
|
+
* 取余数
|
|
321
|
+
* @param other
|
|
322
|
+
*/
|
|
323
|
+
mod(other: Decimal): Decimal;
|
|
324
|
+
/**
|
|
325
|
+
* 取余数
|
|
326
|
+
* @param other
|
|
327
|
+
*/
|
|
328
|
+
modInt(other: IntNumber): Decimal;
|
|
329
|
+
/**
|
|
330
|
+
* 取余数
|
|
331
|
+
* @param other
|
|
332
|
+
*/
|
|
333
|
+
modFloat(other: string): Decimal;
|
|
334
|
+
/**
|
|
335
|
+
* n次方
|
|
336
|
+
* @param n 整数
|
|
337
|
+
*/
|
|
338
|
+
pow(n?: IntNumber): this;
|
|
339
|
+
/**
|
|
340
|
+
* 开方
|
|
341
|
+
*/
|
|
342
|
+
sqrt(): this;
|
|
343
|
+
/**
|
|
344
|
+
* 小于
|
|
345
|
+
* @param other
|
|
346
|
+
*/
|
|
347
|
+
LT(other: Decimal): boolean;
|
|
348
|
+
/**
|
|
349
|
+
* 小于
|
|
350
|
+
* @param other
|
|
351
|
+
*/
|
|
352
|
+
['<'](other: Decimal): boolean;
|
|
353
|
+
/**
|
|
354
|
+
* 小于
|
|
355
|
+
* @param other
|
|
356
|
+
*/
|
|
357
|
+
LTInt(other: IntNumber): boolean;
|
|
358
|
+
/**
|
|
359
|
+
* 小于
|
|
360
|
+
* @param other
|
|
361
|
+
*/
|
|
362
|
+
LTFloat(other: string): boolean;
|
|
363
|
+
/**
|
|
364
|
+
* 小于等于
|
|
365
|
+
* @param other
|
|
366
|
+
*/
|
|
367
|
+
LE(other: Decimal): boolean;
|
|
368
|
+
/**
|
|
369
|
+
* 小于等于
|
|
370
|
+
* @param other
|
|
371
|
+
*/
|
|
372
|
+
['<='](other: Decimal): boolean;
|
|
373
|
+
/**
|
|
374
|
+
* 小于等于
|
|
375
|
+
* @param other
|
|
376
|
+
*/
|
|
377
|
+
LEInt(other: IntNumber): boolean;
|
|
378
|
+
/**
|
|
379
|
+
* 小于等于
|
|
380
|
+
* @param other
|
|
381
|
+
*/
|
|
382
|
+
LEFloat(other: string): boolean;
|
|
383
|
+
/**
|
|
384
|
+
* 等于
|
|
385
|
+
* @param other
|
|
386
|
+
*/
|
|
387
|
+
EQ(other: Decimal): boolean;
|
|
388
|
+
/**
|
|
389
|
+
* 等于
|
|
390
|
+
* @param other
|
|
391
|
+
*/
|
|
392
|
+
['=='](other: Decimal): boolean;
|
|
393
|
+
/**
|
|
394
|
+
* 等于
|
|
395
|
+
* @param other
|
|
396
|
+
*/
|
|
397
|
+
EQInt(other: IntNumber): boolean;
|
|
398
|
+
/**
|
|
399
|
+
* 等于
|
|
400
|
+
* @param other
|
|
401
|
+
*/
|
|
402
|
+
EQFloat(other: string): boolean;
|
|
403
|
+
/**
|
|
404
|
+
* 不等于
|
|
405
|
+
* @param other
|
|
406
|
+
*/
|
|
407
|
+
NE(other: Decimal): boolean;
|
|
408
|
+
/**
|
|
409
|
+
* 不等于
|
|
410
|
+
* @param other
|
|
411
|
+
*/
|
|
412
|
+
['!='](other: Decimal): boolean;
|
|
413
|
+
/**
|
|
414
|
+
* 不等于
|
|
415
|
+
* @param other
|
|
416
|
+
*/
|
|
417
|
+
NEInt(other: IntNumber): boolean;
|
|
418
|
+
/**
|
|
419
|
+
* 不等于
|
|
420
|
+
* @param other
|
|
421
|
+
*/
|
|
422
|
+
NEFloat(other: string): boolean;
|
|
423
|
+
/**
|
|
424
|
+
* 大于
|
|
425
|
+
* @param other
|
|
426
|
+
*/
|
|
427
|
+
GT(other: Decimal): boolean;
|
|
428
|
+
/**
|
|
429
|
+
* 大于
|
|
430
|
+
* @param other
|
|
431
|
+
*/
|
|
432
|
+
['>'](other: Decimal): boolean;
|
|
433
|
+
/**
|
|
434
|
+
* 大于
|
|
435
|
+
* @param other
|
|
436
|
+
*/
|
|
437
|
+
GTInt(other: IntNumber): boolean;
|
|
438
|
+
/**
|
|
439
|
+
* 大于
|
|
440
|
+
* @param other
|
|
441
|
+
*/
|
|
442
|
+
GTFloat(other: string): boolean;
|
|
443
|
+
/**
|
|
444
|
+
* 大于等于
|
|
445
|
+
* @param other
|
|
446
|
+
*/
|
|
447
|
+
GE(other: Decimal): boolean;
|
|
448
|
+
/**
|
|
449
|
+
* 大于等于
|
|
450
|
+
* @param other
|
|
451
|
+
*/
|
|
452
|
+
['>='](other: Decimal): boolean;
|
|
453
|
+
/**
|
|
454
|
+
* 大于等于
|
|
455
|
+
* @param other
|
|
456
|
+
*/
|
|
457
|
+
GEInt(other: IntNumber): boolean;
|
|
458
|
+
/**
|
|
459
|
+
* 大于等于
|
|
460
|
+
* @param other
|
|
461
|
+
*/
|
|
462
|
+
GEFloat(other: string): boolean;
|
|
463
|
+
}
|
|
464
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/* CJ_RUNTIME_PROTECTED_JS */
|
|
2
|
+
"use strict";
|
|
3
|
+
var __cj_sa_8990661f=["57.29577951308232","0.19999967200053792","0.14285489799446008","1.5707963267948966","cc/env"];
|
|
4
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.Decimal=void 0;const env_1=require(__cj_sa_8990661f[4]);let DotLen=8,Scale=Math.pow(10,DotLen),Scale_L=Math.pow(10,DotLen-1);function decimalStr(t){const i=t.length;return i===DotLen?t:i>DotLen?t.slice(0,DotLen):t+"0".repeat(DotLen-i)}function intDiv(t,i){return t<i?0:t===i?1:Math.floor(t/i)}function intMod(t,i){return t<i?t:t===i?0:t-intDiv(t,i)*i}function mulFractionToScaledFloor(t,i){const e=1e4,s=intDiv(t,e),n=t-s*e,r=intDiv(i,e),a=i-r*e;return s*r+intDiv((s*a+n*r)*e+n*a,1e8)}const BigIntCtor="function"==typeof globalThis.BigInt?globalThis.BigInt:void 0;class Decimal{static copy(t){return(new Decimal).copy(t)}static createInt(t){return(new Decimal).setInt(t)}static createFloat(t){return(new Decimal).setFloat(t)}static create(t,i,e){return(new Decimal).set(t,i,e)}static set accuracy(t){DotLen=Math.max(Math.floor(t),1),Scale=Math.pow(10,DotLen),Scale_L=Math.pow(10,DotLen-1),PI_Decimal.setFloat("3.141592653589793"),PI_HALF_Decimal.setFloat("1.5707963267948966"),Deg_Rad_Decimal.setFloat("0.017453292519943"),Rad_Deg_Decimal.setFloat(__cj_sa_8990661f[0])}static get accuracy(){return DotLen}static get PI(){return PI_Decimal}static get PI_HALF(){return PI_HALF_Decimal}static get DEG_TO_RAD(){return Deg_Rad_Decimal}static get RAD_TO_DEG(){return Rad_Deg_Decimal}static get zero(){return new Decimal}static get ZERO(){return Zero_Decimal.sign=1,Zero_Decimal.v1=0,Zero_Decimal.v2=0,Zero_Decimal}static get one(){return Decimal.createInt(1)}static get ONE(){return One_Decimal.sign=1,One_Decimal.v1=1,One_Decimal.v2=0,One_Decimal}static get two(){return Decimal.createInt(2)}static get TWO(){return Two_Decimal.sign=1,Two_Decimal.v1=2,Two_Decimal.v2=0,Two_Decimal}static get(){return Decimal.createInt(-1)}static get MINUS(){return Minus_Decimal.sign=-1,Minus_Decimal.v1=1,Minus_Decimal.v2=0,Minus_Decimal}static get NaN(){return Decimal.create(1,Number.NaN,Number.NaN)}static max(...t){let i=t[0];for(let e=1;e<t.length;e++){const s=t[e];s.GT(i)&&(i=s)}return i}static min(...t){let i=t[0];for(let e=1;e<t.length;e++){const s=t[e];s.LT(i)&&(i=s)}return i}static radiansToDegrees(t,i){return t.copy(i).mul(this.RAD_TO_DEG)}static degreesToRadians(t,i){return t.copy(i).mul(this.DEG_TO_RAD)}static sin(t,i){return this.cos(t,TempB1.copy(i).addInt(90)).negative()}static cos(t,i){const e=TempB1.copy(i).modInt(360).mul(this.DEG_TO_RAD),s=t.copy(this.ONE),n=TempB2.setInt(1);for(let t=1;t<=9;t++)n.mul(e).mul(e).negative().divInt(2*t*(2*t-1)),s.add(n);return s}static tan(t,i){const e=this.sin(t,i),s=this.cos(TempB3,i);return e.div(s)}static asin(t,i){return TempB1.copy(i).pow().negative().add(this.ONE).sqrt(),TempB2.copy(i).div(TempB1),this.atan(t,TempB2)}static acos(t,i){return i.LT(this.MINUS)||i.GT(this.ONE)?t.set(1,Number.NaN,Number.NaN):i.EQ(this.ONE)?t.set(1,0,0):i.EQ(this.ZERO)?t.set(1,90,0):i.EQ(this.MINUS)?t.set(1,180,0):(TempB1.copy(i).pow().negative().add(this.ONE).sqrt().div(i),this.atan(t,TempB1).modInt(180),t.isNegative()?t.addInt(180):t)}static atan(t,i){if(i.EQ(this.ZERO))return t.copy(this.ZERO);if(1===i.v1&&0===i.v2)return t.set(i.sign,45,0);let e=1,s=!1,n=!1;if(t.copy(i).isNegative()&&(e=-1,t.negative()),t.GT(this.ONE)&&(t.reciprocal(),s=!0),t.GTFloat("0.26794919")){const i=TempC1.setFloat("1.7320508075688772");TempC2.copy(t).add(i),t.mul(i).sub(this.ONE).div(TempC2),n=!0}return TempC1.copy(t).sub(TempC2.setFloat("0.3333333342477778").mul(TempC3.copy(t).pow(3))).add(TempC2.setFloat(__cj_sa_8990661f[1]).mul(TempC3.mul(t).mul(t))).add(TempC2.setFloat("0.11108765927193148").mul(TempC3.mul(t))).sub(TempC2.setFloat(__cj_sa_8990661f[2]).mul(TempC3.mul(t))).sub(TempC2.setFloat("0.0849762066621346").mul(TempC3.mul(t))),t.copy(TempC1),n&&t.addFloat("0.5235987755982988"),s&&t.sub(this.PI_HALF).negative(),t.sign*=e,t.mul(this.RAD_TO_DEG)}static atan2(t,i,e){return e.EQ(this.ZERO)&&i.EQ(this.ZERO)?t.copy(this.ZERO):e.GT(this.ZERO)?this.atan(t,TempD1.copy(i).div(e)):e.LT(this.ZERO)&&i.GE(this.ZERO)?this.atan(t,TempD1.copy(i).div(e)).addInt(180):e.LT(this.ZERO)&&i.LT(this.ZERO)?this.atan(t,TempD1.copy(i).div(e)).subInt(180):e.EQ(this.ZERO)&&i.GT(this.ZERO)?t.setInt(90):t.setInt(-90)}get sign(){return this._sign}set sign(t){this._sign=t}get v1(){return this._v1}set v1(t){this._v1=t}get v2(){return this._v2}set v2(t){this._v2=t}bindMutationObserver(t){return this.__observer=t,t||(this.__mutationDepth=0,this.__mutationPending=!1),this}beginMutationBatch(){return this.__observer&&0===this.__silentDepth&&this.__mutationDepth++,this}endMutationBatch(){return this.__observer&&0===this.__silentDepth&&this.__mutationDepth>0&&(this.__mutationDepth--,this.flushMutationObserverIfReady()),this}runMutationBatch(t){this.beginMutationBatch();try{return t()}finally{this.endMutationBatch()}}runSilentMutation(t){this.__silentDepth++;try{return t()}finally{this.__silentDepth--}}setSilent(t=1,i=0,e=0){return this.runSilentMutation(()=>this.set(t,i,e))}copySilent(t){return this.runSilentMutation(()=>this.copy(t))}static compareAbs(t,i){return t.v1>i.v1?1:t.v1<i.v1?-1:t.v2>i.v2?1:t.v2<i.v2?-1:0}static compareSigned(t,i){if(t.sign!==i.sign)return t.sign>i.sign?1:-1;const e=Decimal.compareAbs(t,i);return 1===t.sign?e:0===e?0:e>0?-1:1}normalizeZero(){return 0===this.v1&&0===this.v2&&(this.sign=1),this}snapshot(){return{sign:this.sign,v1:this.v1,v2:this.v2}}changedSince(t){return!Object.is(this.sign,t.sign)||!Object.is(this.v1,t.v1)||!Object.is(this.v2,t.v2)}runMutation(t){if(!this.__observer||this.__silentDepth>0)return t();const i=this.snapshot();this.__mutationDepth++;try{return t()}finally{this.changedSince(i)&&(this.__mutationPending=!0),this.__mutationDepth--,this.flushMutationObserverIfReady()}}flushMutationObserverIfReady(){if(0!==this.__mutationDepth||!this.__mutationPending||this.__silentDepth>0)return;this.__mutationPending=!1;const t=this.__observer;t&&t.onDecimalMutated(this)}setAbsSub(t,i,e,s,n){let r=i-s,a=e-n;return a<0&&(a+=Scale,r-=1),this.sign=t,this.v1=r,this.v2=a,this.normalizeZero()}setAbsAdd(t,i,e,s,n){let r=i+s,a=e+n;return a>=Scale&&(a-=Scale,r+=1),this.sign=t,this.v1=r,this.v2=a,this.normalizeZero()}setFromRawBigInt(t){if(!BigIntCtor)return this.set(1,Number.NaN,Number.NaN);const i=BigIntCtor(0),e=BigIntCtor(Scale);let s=1;return t<i&&(s=-1,t=-t),this.sign=s,this.v1=Number(t/e),this.v2=Number(t%e),this.normalizeZero()}set value(t){this.runMutation(()=>{this.sign=t.sign,this.v1=t.v1,this.v2=t.v2})}constructor(t){this._sign=1,this._v1=0,this._v2=0,this.__observer=null,this.__mutationDepth=0,this.__mutationPending=!1,this.__silentDepth=0,this.setFloat(t)}set(t=1,i=0,e=0){return this.runMutation(()=>(this.sign=t,this.v1=i,this.v2=e,this))}setFloat(t=""){return this.runMutation(()=>{if(!t)return this.sign=1,this.v1=0,this.v2=0,this;this.sign="-"===t[0]?-1:1;const i=t.split(".");return this.v1=Math.abs(parseInt(i[0]||"0")),this.v2=1===i.length?0:parseInt(decimalStr(i[1])),0===this.v1&&0===this.v2&&(this.sign=1),this})}setInt(t=0){return this.runMutation(()=>(env_1.DEV&&t!==Math.floor(t)&&console.error("setInt: 参数必须是整数,而不应该是",t),t<0?(this.sign=-1,this.v1=Math.floor(-t),this.v2=0):(this.sign=1,this.v1=Math.floor(t),this.v2=0),this))}copy(t){return this.runMutation(()=>(this.sign=t.sign,this.v1=t.v1,this.v2=t.v2,this))}toNumber(t=!1){return t?parseFloat(this.toString()):this.sign*(this.v1+this.v2/Scale)}toString(){return 1===this.sign?this.v1.toString()+"."+"0".repeat(DotLen-this.v2.toString().length)+this.v2:"-"+this.v1.toString()+"."+"0".repeat(DotLen-this.v2.toString().length)+this.v2}toBigInt(){return this.sign*(this.v1*Scale+this.v2)}isZero(){return 0===this.v1&&0===this.v2}isNegative(){return this.sign<0&&(this.v1>0||this.v2>0)}isNaN(){return Number.isNaN(this.v1)||Number.isNaN(this.v2)}clone(){return(new Decimal).copy(this)}floor(){return this.runMutation(()=>(this.v2>0&&-1===this.sign&&(this.v1+=1),this.v2=0,this))}ceil(){return this.runMutation(()=>(this.v2>0&&1===this.sign&&(this.v1+=1),this.v2=0,0===this.v1&&(this.sign=1),this))}round(){return this.runMutation(()=>(this.v2>Scale>>1&&(this.v1+=1),this.v2=0,0===this.v1&&(this.sign=1),this))}abs(){return this.runMutation(()=>(this.sign=1,this))}reverse(){return this.runMutation(()=>(this.sign*=-1,this))}negative(){return this.runMutation(()=>(this.sign*=-1,this))}reciprocal(){return this.runMutation(()=>this.copy(Decimal.ONE.div(this)))}add(t){return this.runMutation(()=>{if(this.sign===t.sign)return this.setAbsAdd(this.sign,this.v1,this.v2,t.v1,t.v2);const i=Decimal.compareAbs(this,t);return 0===i?this.set():i>0?this.setAbsSub(this.sign,this.v1,this.v2,t.v1,t.v2):this.setAbsSub(t.sign,t.v1,t.v2,this.v1,this.v2)})}addInt(t){return this.add(Temp.setInt(t))}addFloat(t){return this.add(Temp.setFloat(t))}sub(t){return this.runMutation(()=>{if(this.sign!==t.sign)return this.setAbsAdd(this.sign,this.v1,this.v2,t.v1,t.v2);const i=Decimal.compareAbs(this,t);return 0===i?this.set():i>0?this.setAbsSub(this.sign,this.v1,this.v2,t.v1,t.v2):this.setAbsSub(1===this.sign?-1:1,t.v1,t.v2,this.v1,this.v2)})}subInt(t){return this.sub(Temp.setInt(t))}subFloat(t){return this.sub(Temp.setFloat(t))}mul(t){return this.runMutation(()=>{const i=this.sign===t.sign?1:-1;let e=this.v1*t.v1,s=0,n=this.v1*t.v2;return e+=intDiv(n,Scale),s+=intMod(n,Scale),s>=Scale&&(e+=intDiv(s,Scale),s=intMod(s,Scale)),n=this.v2*t.v1,e+=intDiv(n,Scale),s+=intMod(n,Scale),s>=Scale&&(e+=intDiv(s,Scale),s=intMod(s,Scale)),s+=mulFractionToScaledFloor(this.v2,t.v2),s>=Scale&&(e+=intDiv(s,Scale),s=intMod(s,Scale)),this.sign=i,this.v1=e,this.v2=s,this.normalizeZero()})}mulInt(t){return this.mul(Temp.setInt(t))}mulFloat(t){return this.mul(Temp.setFloat(t))}div(t){return this.runMutation(()=>{const i=t.v1*Scale+t.v2;if(0===i)return this.set(1,Number.NaN,Number.NaN);const e=this.sign===t.sign?1:-1;if(BigIntCtor){const i=BigIntCtor(Scale),s=(BigIntCtor(this.v1)*i+BigIntCtor(this.v2))*i/(BigIntCtor(t.v1)*i+BigIntCtor(t.v2))*BigIntCtor(e);return this.setFromRawBigInt(s)}const s=this.v1*Scale+this.v2,n=intDiv(s,i),r=intDiv((s-n*i)*Scale,i);return this.sign=e,this.v1=n,this.v2=r,this.normalizeZero()})}divInt(t){return this.div(Temp.setInt(t))}divFloat(t){return this.div(Temp.setFloat(t))}mod(t){return this.runMutation(()=>{const i=t.v1*Scale+t.v2;if(0===i)return this.set(1,Number.NaN,Number.NaN);if(Decimal.compareAbs(this,t)<0)return this;if(0===Decimal.compareAbs(this,t))return this.set();if(BigIntCtor){const i=BigIntCtor(Scale),e=BigIntCtor(this.v1)*i+BigIntCtor(this.v2),s=BigIntCtor(t.v1)*i+BigIntCtor(t.v2);return this.setFromRawBigInt(e%s*BigIntCtor(this.sign))}const e=intMod(this.v1*Scale+this.v2,i);return this.v1=intDiv(e,Scale),this.v2=intMod(e,Scale),this.normalizeZero()})}modInt(t){return this.mod(Temp.setInt(t))}modFloat(t){return this.mod(Temp.setFloat(t))}pow(t=2){return this.runMutation(()=>{if(0===t)this.sign=1,this.v1=1,this.v2=0;else{if(1===t)return this;if(2===t)this.mul(TempA1.copy(this));else if(t>0){const i=TempA1.copy(this);for(let e=1;e<t;e++)this.mul(i)}else{const i=TempA1.copy(this);this.sign=1,this.v1=1,this.v2=0;for(let e=-1;e>=t;e--)this.div(i)}}return this})}sqrt(){return this.runMutation(()=>{if(this.LE(Zero_Decimal))return this.set(1,Number.NaN,Number.NaN);const t=5*Scale_L,i=TempA2.copy(this).div(TempA1.copy(Decimal.TWO)),e=TempA3.copy(this).div(TempA1.copy(Decimal.TWO).mul(i)).add(TempA1.set(1,0,t).mul(i));for(;TempA1.copy(e).sub(i).abs().GT(Threshold_Decimal);)i.copy(e),e.copy(this).div(TempA1.copy(Decimal.TWO).mul(i)).add(TempA1.set(1,0,t).mul(i));return this.sign=e.sign,this.v1=e.v1,this.v2=e.v2,this})}LT(t){return Decimal.compareSigned(this,t)<0}"<"(t){return Decimal.compareSigned(this,t)<0}LTInt(t){return this.LT(Temp.setInt(t))}LTFloat(t){return this.LT(Temp.setFloat(t))}LE(t){return Decimal.compareSigned(this,t)<=0}"<="(t){return Decimal.compareSigned(this,t)<=0}LEInt(t){return this.LE(Temp.setInt(t))}LEFloat(t){return this.LE(Temp.setFloat(t))}EQ(t){return this.sign===t.sign&&this.v1===t.v1&&this.v2===t.v2}"=="(t){return this.EQ(t)}EQInt(t){return this.EQ(Temp.setInt(t))}EQFloat(t){return this.EQ(Temp.setFloat(t))}NE(t){return!this.EQ(t)}"!="(t){return!this.EQ(t)}NEInt(t){return this.NE(Temp.setInt(t))}NEFloat(t){return this.NE(Temp.setFloat(t))}GT(t){return Decimal.compareSigned(this,t)>0}">"(t){return Decimal.compareSigned(this,t)>0}GTInt(t){return this.GT(Temp.setInt(t))}GTFloat(t){return this.GT(Temp.setFloat(t))}GE(t){return Decimal.compareSigned(this,t)>=0}">="(t){return Decimal.compareSigned(this,t)>=0}GEInt(t){return this.GE(Temp.setInt(t))}GEFloat(t){return this.GE(Temp.setFloat(t))}}exports.Decimal=Decimal;const Temp=new Decimal,Temp1=new Decimal,Temp2=new Decimal,TempA1=new Decimal,TempA2=new Decimal,TempA3=new Decimal,TempB1=new Decimal,TempB2=new Decimal,TempB3=new Decimal,TempC1=new Decimal,TempC2=new Decimal,TempC3=new Decimal,TempD1=new Decimal,Threshold_Decimal=Decimal.create(1,0,1),Zero_Decimal=Decimal.createInt(0),One_Decimal=Decimal.createInt(1),Two_Decimal=Decimal.createInt(2),Minus_Decimal=Decimal.createInt(-1),PI_Decimal=Decimal.createFloat("3.141592653589793"),PI_HALF_Decimal=Decimal.createFloat(__cj_sa_8990661f[3]),Deg_Rad_Decimal=Decimal.createFloat("0.017453292519943"),Rad_Deg_Decimal=Decimal.createFloat("57.29577951308232");
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/* CJ_RUNTIME_PROTECTED_JS */
|
|
2
|
+
"use strict";
|
|
3
|
+
var __cj_sa_e696be72=["./assets/Decimal"];
|
|
4
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.Decimal=void 0;var Decimal_1=require(__cj_sa_e696be72[0]);Object.defineProperty(exports,"Decimal",{enumerable:!0,get:function(){return Decimal_1.Decimal}});
|
package/{index.ts → index.d.ts}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Decimal } from './assets/Decimal';
|
|
2
|
-
export type { IDecimalMutationObserver } from './assets/Decimal';
|
|
1
|
+
export { Decimal } from './assets/Decimal';
|
|
2
|
+
export type { IDecimalMutationObserver } from './assets/Decimal';
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cjhd/cj-decimal",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"engine": ">=3.8.0",
|
|
5
5
|
"description": "定点数学计算模块",
|
|
6
|
-
"main": "index.
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
-
},
|
|
6
|
+
"main": "./dist/cocos/index.js",
|
|
10
7
|
"repository": {
|
|
11
8
|
"type": "git",
|
|
12
9
|
"url": "https://gitee.com/cocos2d-zp/cococs-creator-frame-3d"
|
|
@@ -17,5 +14,27 @@
|
|
|
17
14
|
},
|
|
18
15
|
"author": "超M <402879660@qq.com>",
|
|
19
16
|
"license": "MIT",
|
|
20
|
-
"
|
|
21
|
-
|
|
17
|
+
"module": "./dist/cocos/index.js",
|
|
18
|
+
"browser": "./dist/cocos/index.js",
|
|
19
|
+
"types": "./index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./index.d.ts",
|
|
23
|
+
"import": "./dist/cocos/index.js",
|
|
24
|
+
"browser": "./dist/cocos/index.js",
|
|
25
|
+
"default": "./dist/cocos/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./assets/*": {
|
|
28
|
+
"import": "./dist/cocos/assets/*",
|
|
29
|
+
"browser": "./dist/cocos/assets/*",
|
|
30
|
+
"default": "./dist/cocos/assets/*"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/",
|
|
35
|
+
"**/*.d.ts",
|
|
36
|
+
"package.json",
|
|
37
|
+
"README.md",
|
|
38
|
+
"license/"
|
|
39
|
+
]
|
|
40
|
+
}
|