@danielsimonjr/mathts-core 0.14.0 → 0.14.3
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/{chunk-YZN52XIQ.js → chunk-L5MWGOLB.js} +166 -59
- package/dist/index.d.ts +14 -6
- package/dist/index.js +53 -6
- package/dist/internal.js +5 -3
- package/package.json +59 -59
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
function isComplex(value) {
|
|
3
3
|
return value instanceof Complex;
|
|
4
4
|
}
|
|
5
|
+
function hypotFast(re, im) {
|
|
6
|
+
if (im === 0) return Math.abs(re);
|
|
7
|
+
if (re === 0) return Math.abs(im);
|
|
8
|
+
const a = re < 0 ? -re : re;
|
|
9
|
+
const b = im < 0 ? -im : im;
|
|
10
|
+
if (a < 1e150 && b < 1e150 && (a > 1e-150 || b > 1e-150)) {
|
|
11
|
+
return Math.sqrt(re * re + im * im);
|
|
12
|
+
}
|
|
13
|
+
return Math.hypot(re, im);
|
|
14
|
+
}
|
|
5
15
|
var Complex = class _Complex {
|
|
6
16
|
type = "Complex";
|
|
7
17
|
re;
|
|
@@ -19,7 +29,15 @@ var Complex = class _Complex {
|
|
|
19
29
|
* @param theta - angle in radians
|
|
20
30
|
*/
|
|
21
31
|
static fromPolar(r, theta) {
|
|
22
|
-
|
|
32
|
+
const cosT = Math.cos(theta);
|
|
33
|
+
const sinT = Math.sin(theta);
|
|
34
|
+
let re = r * cosT;
|
|
35
|
+
let im = r * sinT;
|
|
36
|
+
if (!Number.isFinite(r) && !Number.isNaN(r)) {
|
|
37
|
+
if (cosT === 0) re = cosT;
|
|
38
|
+
if (sinT === 0) im = sinT;
|
|
39
|
+
}
|
|
40
|
+
return new _Complex(re, im);
|
|
23
41
|
}
|
|
24
42
|
/**
|
|
25
43
|
* Create a Complex from a real number
|
|
@@ -142,7 +160,7 @@ var Complex = class _Complex {
|
|
|
142
160
|
* Magnitude (absolute value) |z| = √(re² + im²)
|
|
143
161
|
*/
|
|
144
162
|
abs() {
|
|
145
|
-
return
|
|
163
|
+
return hypotFast(this.re, this.im);
|
|
146
164
|
}
|
|
147
165
|
/**
|
|
148
166
|
* Phase angle (argument) in radians, range (-π, π]
|
|
@@ -258,13 +276,28 @@ var Complex = class _Complex {
|
|
|
258
276
|
// Transcendental Functions
|
|
259
277
|
// ============================================================
|
|
260
278
|
/**
|
|
261
|
-
* Square root using principal branch
|
|
262
|
-
*
|
|
279
|
+
* Square root using the principal branch (Re ≥ 0; Im has the sign of `this.im`).
|
|
280
|
+
*
|
|
281
|
+
* Algebraic form, not polar: one hypot + one sqrt instead of hypot + atan2 +
|
|
282
|
+
* cos + sin. Same branch cut as C99 / the previous polar implementation,
|
|
283
|
+
* including `sqrt(-x - 0i) = −√x · i`.
|
|
263
284
|
*/
|
|
264
285
|
sqrt() {
|
|
265
|
-
const
|
|
266
|
-
const
|
|
267
|
-
|
|
286
|
+
const x = this.re;
|
|
287
|
+
const y = this.im;
|
|
288
|
+
if (y === 0) {
|
|
289
|
+
if (x >= 0) return new _Complex(Math.sqrt(x), y);
|
|
290
|
+
const im2 = Math.sqrt(-x);
|
|
291
|
+
return new _Complex(0, Object.is(y, -0) ? -im2 : im2);
|
|
292
|
+
}
|
|
293
|
+
const r = hypotFast(x, y);
|
|
294
|
+
if (x >= 0) {
|
|
295
|
+
const t2 = Math.sqrt(0.5 * (r + x));
|
|
296
|
+
return new _Complex(t2, y / (2 * t2));
|
|
297
|
+
}
|
|
298
|
+
const t = Math.sqrt(0.5 * (r - x));
|
|
299
|
+
const im = y < 0 ? -t : t;
|
|
300
|
+
return new _Complex(y / (2 * im), im);
|
|
268
301
|
}
|
|
269
302
|
/**
|
|
270
303
|
* n-th root (returns principal root)
|
|
@@ -304,13 +337,15 @@ var Complex = class _Complex {
|
|
|
304
337
|
* Logarithm base 10
|
|
305
338
|
*/
|
|
306
339
|
log10() {
|
|
307
|
-
|
|
340
|
+
const ln10 = Math.LN10;
|
|
341
|
+
return new _Complex(Math.log(hypotFast(this.re, this.im)) / ln10, this.arg() / ln10);
|
|
308
342
|
}
|
|
309
343
|
/**
|
|
310
344
|
* Logarithm base 2
|
|
311
345
|
*/
|
|
312
346
|
log2() {
|
|
313
|
-
|
|
347
|
+
const ln2 = Math.LN2;
|
|
348
|
+
return new _Complex(Math.log(hypotFast(this.re, this.im)) / ln2, this.arg() / ln2);
|
|
314
349
|
}
|
|
315
350
|
/**
|
|
316
351
|
* Power: z^w = e^(w·ln(z))
|
|
@@ -351,16 +386,24 @@ var Complex = class _Complex {
|
|
|
351
386
|
);
|
|
352
387
|
}
|
|
353
388
|
/**
|
|
354
|
-
* Tangent: tan(
|
|
389
|
+
* Tangent: tan(x+iy) = (sin 2x + i sinh 2y) / (cos 2x + cosh 2y)
|
|
390
|
+
*
|
|
391
|
+
* Closed form — no intermediate `sin`/`cos` Complex allocations.
|
|
355
392
|
*/
|
|
356
393
|
tan() {
|
|
357
|
-
|
|
394
|
+
const x2 = this.re * 2;
|
|
395
|
+
const y2 = this.im * 2;
|
|
396
|
+
const d = Math.cos(x2) + Math.cosh(y2);
|
|
397
|
+
return new _Complex(Math.sin(x2) / d, Math.sinh(y2) / d);
|
|
358
398
|
}
|
|
359
399
|
/**
|
|
360
|
-
* Cotangent: cot(
|
|
400
|
+
* Cotangent: cot(x+iy) = (sin 2x − i sinh 2y) / (cosh 2y − cos 2x)
|
|
361
401
|
*/
|
|
362
402
|
cot() {
|
|
363
|
-
|
|
403
|
+
const x2 = this.re * 2;
|
|
404
|
+
const y2 = this.im * 2;
|
|
405
|
+
const d = Math.cosh(y2) - Math.cos(x2);
|
|
406
|
+
return new _Complex(Math.sin(x2) / d, -Math.sinh(y2) / d);
|
|
364
407
|
}
|
|
365
408
|
/**
|
|
366
409
|
* Secant: sec(z) = 1 / cos(z)
|
|
@@ -396,16 +439,22 @@ var Complex = class _Complex {
|
|
|
396
439
|
);
|
|
397
440
|
}
|
|
398
441
|
/**
|
|
399
|
-
* Hyperbolic tangent: tanh(
|
|
442
|
+
* Hyperbolic tangent: tanh(x+iy) = (sinh 2x + i sin 2y) / (cosh 2x + cos 2y)
|
|
400
443
|
*/
|
|
401
444
|
tanh() {
|
|
402
|
-
|
|
445
|
+
const x2 = this.re * 2;
|
|
446
|
+
const y2 = this.im * 2;
|
|
447
|
+
const d = Math.cosh(x2) + Math.cos(y2);
|
|
448
|
+
return new _Complex(Math.sinh(x2) / d, Math.sin(y2) / d);
|
|
403
449
|
}
|
|
404
450
|
/**
|
|
405
|
-
* Hyperbolic cotangent: coth(
|
|
451
|
+
* Hyperbolic cotangent: coth(x+iy) = (sinh 2x − i sin 2y) / (cosh 2x − cos 2y)
|
|
406
452
|
*/
|
|
407
453
|
coth() {
|
|
408
|
-
|
|
454
|
+
const x2 = this.re * 2;
|
|
455
|
+
const y2 = this.im * 2;
|
|
456
|
+
const d = Math.cosh(x2) - Math.cos(y2);
|
|
457
|
+
return new _Complex(Math.sinh(x2) / d, -Math.sin(y2) / d);
|
|
409
458
|
}
|
|
410
459
|
/**
|
|
411
460
|
* Hyperbolic secant: sech(z) = 1 / cosh(z)
|
|
@@ -1483,11 +1532,49 @@ function gcd(a, b) {
|
|
|
1483
1532
|
}
|
|
1484
1533
|
return a;
|
|
1485
1534
|
}
|
|
1535
|
+
function reducePair(num, den) {
|
|
1536
|
+
if (den === 0n) {
|
|
1537
|
+
throw new Error("Fraction denominator cannot be zero");
|
|
1538
|
+
}
|
|
1539
|
+
if (den < 0n) {
|
|
1540
|
+
num = -num;
|
|
1541
|
+
den = -den;
|
|
1542
|
+
}
|
|
1543
|
+
if (num === 0n) return [0n, 1n];
|
|
1544
|
+
const g = gcd(num, den);
|
|
1545
|
+
return [num / g, den / g];
|
|
1546
|
+
}
|
|
1486
1547
|
var Fraction = class _Fraction {
|
|
1487
1548
|
type = "Fraction";
|
|
1488
1549
|
numerator;
|
|
1489
1550
|
denominator;
|
|
1490
1551
|
constructor(numerator, denominator = 1n) {
|
|
1552
|
+
if (typeof numerator === "bigint" && typeof denominator === "bigint") {
|
|
1553
|
+
const [num2, den2] = reducePair(numerator, denominator);
|
|
1554
|
+
this.numerator = num2;
|
|
1555
|
+
this.denominator = den2;
|
|
1556
|
+
return;
|
|
1557
|
+
}
|
|
1558
|
+
if (typeof numerator === "number" && Number.isInteger(numerator)) {
|
|
1559
|
+
if (typeof denominator === "bigint") {
|
|
1560
|
+
const [num2, den2] = reducePair(BigInt(numerator), denominator);
|
|
1561
|
+
this.numerator = num2;
|
|
1562
|
+
this.denominator = den2;
|
|
1563
|
+
return;
|
|
1564
|
+
}
|
|
1565
|
+
if (typeof denominator === "number" && Number.isInteger(denominator)) {
|
|
1566
|
+
const [num2, den2] = reducePair(BigInt(numerator), BigInt(denominator));
|
|
1567
|
+
this.numerator = num2;
|
|
1568
|
+
this.denominator = den2;
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
if (typeof numerator === "bigint" && typeof denominator === "number" && Number.isInteger(denominator)) {
|
|
1573
|
+
const [num2, den2] = reducePair(numerator, BigInt(denominator));
|
|
1574
|
+
this.numerator = num2;
|
|
1575
|
+
this.denominator = den2;
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1491
1578
|
const toRatio = (x) => {
|
|
1492
1579
|
if (isFraction2(x)) {
|
|
1493
1580
|
return [x.numerator, x.denominator];
|
|
@@ -1684,6 +1771,9 @@ var Fraction = class _Fraction {
|
|
|
1684
1771
|
*/
|
|
1685
1772
|
add(other) {
|
|
1686
1773
|
if (other instanceof _Fraction) {
|
|
1774
|
+
if (this.denominator === other.denominator) {
|
|
1775
|
+
return new _Fraction(this.numerator + other.numerator, this.denominator);
|
|
1776
|
+
}
|
|
1687
1777
|
const num = this.numerator * other.denominator + other.numerator * this.denominator;
|
|
1688
1778
|
const den = this.denominator * other.denominator;
|
|
1689
1779
|
return new _Fraction(num, den);
|
|
@@ -1695,6 +1785,9 @@ var Fraction = class _Fraction {
|
|
|
1695
1785
|
*/
|
|
1696
1786
|
subtract(other) {
|
|
1697
1787
|
if (other instanceof _Fraction) {
|
|
1788
|
+
if (this.denominator === other.denominator) {
|
|
1789
|
+
return new _Fraction(this.numerator - other.numerator, this.denominator);
|
|
1790
|
+
}
|
|
1698
1791
|
const num = this.numerator * other.denominator - other.numerator * this.denominator;
|
|
1699
1792
|
const den = this.denominator * other.denominator;
|
|
1700
1793
|
return new _Fraction(num, den);
|
|
@@ -2033,6 +2126,9 @@ var BigNumber = class _BigNumber {
|
|
|
2033
2126
|
if (n === 0) {
|
|
2034
2127
|
return new _BigNumber(0, 0n, 0);
|
|
2035
2128
|
}
|
|
2129
|
+
if (Number.isSafeInteger(n)) {
|
|
2130
|
+
return _BigNumber.fromBigInt(BigInt(n));
|
|
2131
|
+
}
|
|
2036
2132
|
return _BigNumber.parse(n.toString());
|
|
2037
2133
|
}
|
|
2038
2134
|
/**
|
|
@@ -2097,19 +2193,13 @@ var BigNumber = class _BigNumber {
|
|
|
2097
2193
|
return new _BigNumber(0, 0n, 0);
|
|
2098
2194
|
}
|
|
2099
2195
|
const sign2 = n < 0n ? -1 : 1;
|
|
2100
|
-
let
|
|
2101
|
-
let
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
} else {
|
|
2106
|
-
break;
|
|
2107
|
-
}
|
|
2108
|
-
}
|
|
2109
|
-
if (trailingZeros > 0) {
|
|
2110
|
-
str = str.slice(0, -trailingZeros);
|
|
2196
|
+
let coef = n < 0n ? -n : n;
|
|
2197
|
+
let exp = 0;
|
|
2198
|
+
while (coef % 10n === 0n) {
|
|
2199
|
+
coef /= 10n;
|
|
2200
|
+
exp++;
|
|
2111
2201
|
}
|
|
2112
|
-
return new _BigNumber(sign2,
|
|
2202
|
+
return new _BigNumber(sign2, coef, exp);
|
|
2113
2203
|
}
|
|
2114
2204
|
/**
|
|
2115
2205
|
* Create a BigNumber from a JSON object
|
|
@@ -4459,83 +4549,87 @@ var createUnitClass = /* @__PURE__ */ factory(
|
|
|
4459
4549
|
"LUMINOUS_INTENSITY",
|
|
4460
4550
|
"AMOUNT_OF_SUBSTANCE",
|
|
4461
4551
|
"ANGLE",
|
|
4462
|
-
"BIT"
|
|
4552
|
+
"BIT",
|
|
4553
|
+
"SOLID_ANGLE"
|
|
4463
4554
|
];
|
|
4464
4555
|
const BASE_UNITS = {
|
|
4465
4556
|
NONE: {
|
|
4466
|
-
dimensions: [0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
4557
|
+
dimensions: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
4467
4558
|
},
|
|
4468
4559
|
MASS: {
|
|
4469
|
-
dimensions: [1, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
4560
|
+
dimensions: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
4470
4561
|
},
|
|
4471
4562
|
LENGTH: {
|
|
4472
|
-
dimensions: [0, 1, 0, 0, 0, 0, 0, 0, 0]
|
|
4563
|
+
dimensions: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
4473
4564
|
},
|
|
4474
4565
|
TIME: {
|
|
4475
|
-
dimensions: [0, 0, 1, 0, 0, 0, 0, 0, 0]
|
|
4566
|
+
dimensions: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
|
|
4476
4567
|
},
|
|
4477
4568
|
CURRENT: {
|
|
4478
|
-
dimensions: [0, 0, 0, 1, 0, 0, 0, 0, 0]
|
|
4569
|
+
dimensions: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
|
|
4479
4570
|
},
|
|
4480
4571
|
TEMPERATURE: {
|
|
4481
|
-
dimensions: [0, 0, 0, 0, 1, 0, 0, 0, 0]
|
|
4572
|
+
dimensions: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
|
|
4482
4573
|
},
|
|
4483
4574
|
LUMINOUS_INTENSITY: {
|
|
4484
|
-
dimensions: [0, 0, 0, 0, 0, 1, 0, 0, 0]
|
|
4575
|
+
dimensions: [0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
|
|
4485
4576
|
},
|
|
4486
4577
|
AMOUNT_OF_SUBSTANCE: {
|
|
4487
|
-
dimensions: [0, 0, 0, 0, 0, 0, 1, 0, 0]
|
|
4578
|
+
dimensions: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
|
|
4488
4579
|
},
|
|
4489
4580
|
FORCE: {
|
|
4490
|
-
dimensions: [1, 1, -2, 0, 0, 0, 0, 0, 0]
|
|
4581
|
+
dimensions: [1, 1, -2, 0, 0, 0, 0, 0, 0, 0]
|
|
4491
4582
|
},
|
|
4492
4583
|
SURFACE: {
|
|
4493
|
-
dimensions: [0, 2, 0, 0, 0, 0, 0, 0, 0]
|
|
4584
|
+
dimensions: [0, 2, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
4494
4585
|
},
|
|
4495
4586
|
VOLUME: {
|
|
4496
|
-
dimensions: [0, 3, 0, 0, 0, 0, 0, 0, 0]
|
|
4587
|
+
dimensions: [0, 3, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
4497
4588
|
},
|
|
4498
4589
|
ENERGY: {
|
|
4499
|
-
dimensions: [1, 2, -2, 0, 0, 0, 0, 0, 0]
|
|
4590
|
+
dimensions: [1, 2, -2, 0, 0, 0, 0, 0, 0, 0]
|
|
4500
4591
|
},
|
|
4501
4592
|
POWER: {
|
|
4502
|
-
dimensions: [1, 2, -3, 0, 0, 0, 0, 0, 0]
|
|
4593
|
+
dimensions: [1, 2, -3, 0, 0, 0, 0, 0, 0, 0]
|
|
4503
4594
|
},
|
|
4504
4595
|
PRESSURE: {
|
|
4505
|
-
dimensions: [1, -1, -2, 0, 0, 0, 0, 0, 0]
|
|
4596
|
+
dimensions: [1, -1, -2, 0, 0, 0, 0, 0, 0, 0]
|
|
4506
4597
|
},
|
|
4507
4598
|
ELECTRIC_CHARGE: {
|
|
4508
|
-
dimensions: [0, 0, 1, 1, 0, 0, 0, 0, 0]
|
|
4599
|
+
dimensions: [0, 0, 1, 1, 0, 0, 0, 0, 0, 0]
|
|
4509
4600
|
},
|
|
4510
4601
|
ELECTRIC_CAPACITANCE: {
|
|
4511
|
-
dimensions: [-1, -2, 4, 2, 0, 0, 0, 0, 0]
|
|
4602
|
+
dimensions: [-1, -2, 4, 2, 0, 0, 0, 0, 0, 0]
|
|
4512
4603
|
},
|
|
4513
4604
|
ELECTRIC_POTENTIAL: {
|
|
4514
|
-
dimensions: [1, 2, -3, -1, 0, 0, 0, 0, 0]
|
|
4605
|
+
dimensions: [1, 2, -3, -1, 0, 0, 0, 0, 0, 0]
|
|
4515
4606
|
},
|
|
4516
4607
|
ELECTRIC_RESISTANCE: {
|
|
4517
|
-
dimensions: [1, 2, -3, -2, 0, 0, 0, 0, 0]
|
|
4608
|
+
dimensions: [1, 2, -3, -2, 0, 0, 0, 0, 0, 0]
|
|
4518
4609
|
},
|
|
4519
4610
|
ELECTRIC_INDUCTANCE: {
|
|
4520
|
-
dimensions: [1, 2, -2, -2, 0, 0, 0, 0, 0]
|
|
4611
|
+
dimensions: [1, 2, -2, -2, 0, 0, 0, 0, 0, 0]
|
|
4521
4612
|
},
|
|
4522
4613
|
ELECTRIC_CONDUCTANCE: {
|
|
4523
|
-
dimensions: [-1, -2, 3, 2, 0, 0, 0, 0, 0]
|
|
4614
|
+
dimensions: [-1, -2, 3, 2, 0, 0, 0, 0, 0, 0]
|
|
4524
4615
|
},
|
|
4525
4616
|
MAGNETIC_FLUX: {
|
|
4526
|
-
dimensions: [1, 2, -2, -1, 0, 0, 0, 0, 0]
|
|
4617
|
+
dimensions: [1, 2, -2, -1, 0, 0, 0, 0, 0, 0]
|
|
4527
4618
|
},
|
|
4528
4619
|
MAGNETIC_FLUX_DENSITY: {
|
|
4529
|
-
dimensions: [1, 0, -2, -1, 0, 0, 0, 0, 0]
|
|
4620
|
+
dimensions: [1, 0, -2, -1, 0, 0, 0, 0, 0, 0]
|
|
4530
4621
|
},
|
|
4531
4622
|
FREQUENCY: {
|
|
4532
|
-
dimensions: [0, 0, -1, 0, 0, 0, 0, 0, 0]
|
|
4623
|
+
dimensions: [0, 0, -1, 0, 0, 0, 0, 0, 0, 0]
|
|
4533
4624
|
},
|
|
4534
4625
|
ANGLE: {
|
|
4535
|
-
dimensions: [0, 0, 0, 0, 0, 0, 0, 1, 0]
|
|
4626
|
+
dimensions: [0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
|
|
4536
4627
|
},
|
|
4537
4628
|
BIT: {
|
|
4538
|
-
dimensions: [0, 0, 0, 0, 0, 0, 0, 0, 1]
|
|
4629
|
+
dimensions: [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
|
|
4630
|
+
},
|
|
4631
|
+
SOLID_ANGLE: {
|
|
4632
|
+
dimensions: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
|
|
4539
4633
|
}
|
|
4540
4634
|
};
|
|
4541
4635
|
for (const key in BASE_UNITS) {
|
|
@@ -5450,9 +5544,21 @@ var createUnitClass = /* @__PURE__ */ factory(
|
|
|
5450
5544
|
value: 1,
|
|
5451
5545
|
offset: 0
|
|
5452
5546
|
},
|
|
5453
|
-
//
|
|
5454
|
-
|
|
5455
|
-
|
|
5547
|
+
// Solid angle
|
|
5548
|
+
sr: {
|
|
5549
|
+
name: "sr",
|
|
5550
|
+
base: BASE_UNITS.SOLID_ANGLE,
|
|
5551
|
+
prefixes: PREFIXES.NONE,
|
|
5552
|
+
value: 1,
|
|
5553
|
+
offset: 0
|
|
5554
|
+
},
|
|
5555
|
+
steradian: {
|
|
5556
|
+
name: "steradian",
|
|
5557
|
+
base: BASE_UNITS.SOLID_ANGLE,
|
|
5558
|
+
prefixes: PREFIXES.LONG,
|
|
5559
|
+
value: 1,
|
|
5560
|
+
offset: 0
|
|
5561
|
+
},
|
|
5456
5562
|
// Force
|
|
5457
5563
|
N: {
|
|
5458
5564
|
name: "N",
|
|
@@ -5962,6 +6068,7 @@ var createUnitClass = /* @__PURE__ */ factory(
|
|
|
5962
6068
|
LUMINOUS_INTENSITY: { unit: UNITS.cd, prefix: PREFIXES.SHORT[""] },
|
|
5963
6069
|
AMOUNT_OF_SUBSTANCE: { unit: UNITS.mol, prefix: PREFIXES.SHORT[""] },
|
|
5964
6070
|
ANGLE: { unit: UNITS.rad, prefix: PREFIXES.SHORT[""] },
|
|
6071
|
+
SOLID_ANGLE: { unit: UNITS.sr, prefix: PREFIXES.NONE[""] },
|
|
5965
6072
|
BIT: { unit: UNITS.bits, prefix: PREFIXES.SHORT[""] },
|
|
5966
6073
|
// Derived units
|
|
5967
6074
|
FORCE: { unit: UNITS.N, prefix: PREFIXES.SHORT[""] },
|
|
@@ -6174,7 +6281,7 @@ var createUnitClass = /* @__PURE__ */ factory(
|
|
|
6174
6281
|
} else {
|
|
6175
6282
|
prefixes = PREFIXES.NONE;
|
|
6176
6283
|
}
|
|
6177
|
-
let newUnit
|
|
6284
|
+
let newUnit;
|
|
6178
6285
|
if (!defUnit) {
|
|
6179
6286
|
baseName = baseName || name2 + "_STUFF";
|
|
6180
6287
|
if (BASE_DIMENSIONS.indexOf(baseName) >= 0) {
|
package/dist/index.d.ts
CHANGED
|
@@ -258,8 +258,11 @@ declare class Complex implements IComplex {
|
|
|
258
258
|
*/
|
|
259
259
|
inverse(): Complex;
|
|
260
260
|
/**
|
|
261
|
-
* Square root using principal branch
|
|
262
|
-
*
|
|
261
|
+
* Square root using the principal branch (Re ≥ 0; Im has the sign of `this.im`).
|
|
262
|
+
*
|
|
263
|
+
* Algebraic form, not polar: one hypot + one sqrt instead of hypot + atan2 +
|
|
264
|
+
* cos + sin. Same branch cut as C99 / the previous polar implementation,
|
|
265
|
+
* including `sqrt(-x - 0i) = −√x · i`.
|
|
263
266
|
*/
|
|
264
267
|
sqrt(): Complex;
|
|
265
268
|
/**
|
|
@@ -299,11 +302,13 @@ declare class Complex implements IComplex {
|
|
|
299
302
|
*/
|
|
300
303
|
cos(): Complex;
|
|
301
304
|
/**
|
|
302
|
-
* Tangent: tan(
|
|
305
|
+
* Tangent: tan(x+iy) = (sin 2x + i sinh 2y) / (cos 2x + cosh 2y)
|
|
306
|
+
*
|
|
307
|
+
* Closed form — no intermediate `sin`/`cos` Complex allocations.
|
|
303
308
|
*/
|
|
304
309
|
tan(): Complex;
|
|
305
310
|
/**
|
|
306
|
-
* Cotangent: cot(
|
|
311
|
+
* Cotangent: cot(x+iy) = (sin 2x − i sinh 2y) / (cosh 2y − cos 2x)
|
|
307
312
|
*/
|
|
308
313
|
cot(): Complex;
|
|
309
314
|
/**
|
|
@@ -323,11 +328,11 @@ declare class Complex implements IComplex {
|
|
|
323
328
|
*/
|
|
324
329
|
cosh(): Complex;
|
|
325
330
|
/**
|
|
326
|
-
* Hyperbolic tangent: tanh(
|
|
331
|
+
* Hyperbolic tangent: tanh(x+iy) = (sinh 2x + i sin 2y) / (cosh 2x + cos 2y)
|
|
327
332
|
*/
|
|
328
333
|
tanh(): Complex;
|
|
329
334
|
/**
|
|
330
|
-
* Hyperbolic cotangent: coth(
|
|
335
|
+
* Hyperbolic cotangent: coth(x+iy) = (sinh 2x − i sin 2y) / (cosh 2x − cos 2y)
|
|
331
336
|
*/
|
|
332
337
|
coth(): Complex;
|
|
333
338
|
/**
|
|
@@ -2558,6 +2563,9 @@ declare function scaledDistance(a: ArrayLike<number>, b: ArrayLike<number>): num
|
|
|
2558
2563
|
* Measured on 1e9-pedestal data: the plain naive two-pass (what shipped) lands ~1e-7 relative error;
|
|
2559
2564
|
* this lands ~1e-16 — better than `np.var`, which uses the uncorrected two-pass (~1e-13).
|
|
2560
2565
|
*
|
|
2566
|
+
* The deviation vector is never materialised: both pairwise sums walk `xs` in
|
|
2567
|
+
* registers, so variance/std no longer pay an extra n-long allocation.
|
|
2568
|
+
*
|
|
2561
2569
|
* Divide the result by `n` (uncorrected), `n − 1` (unbiased/sample), or `n + 1` (biased) for the
|
|
2562
2570
|
* corresponding variance. Returns 0 for fewer than two elements.
|
|
2563
2571
|
*/
|
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
round,
|
|
45
45
|
sign,
|
|
46
46
|
subtractScalar
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-L5MWGOLB.js";
|
|
48
48
|
|
|
49
49
|
// src/types/matrix/Range.ts
|
|
50
50
|
var name = "Range";
|
|
@@ -1301,13 +1301,60 @@ function sumSquaredDeviations(xs) {
|
|
|
1301
1301
|
const n = xs.length;
|
|
1302
1302
|
if (n < 2) return 0;
|
|
1303
1303
|
const mean = pairwiseSum(xs) / n;
|
|
1304
|
-
const
|
|
1305
|
-
for (let i = 0; i < n; i++) d[i] = xs[i] - mean;
|
|
1306
|
-
const sumD = pairwiseSum(d);
|
|
1307
|
-
const sumDD = pairwiseDot(d, d);
|
|
1304
|
+
const { sumD, sumDD } = pairwiseDeviationSums(xs, mean, 0, n);
|
|
1308
1305
|
const corrected = sumDD - sumD * sumD / n;
|
|
1309
1306
|
return corrected < 0 ? 0 : corrected;
|
|
1310
1307
|
}
|
|
1308
|
+
function pairwiseDeviationSums(xs, mean, start, end) {
|
|
1309
|
+
const n = end - start;
|
|
1310
|
+
if (n <= PAIRWISE_BLOCK) {
|
|
1311
|
+
let d0 = 0, d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0, d7 = 0;
|
|
1312
|
+
let q0 = 0, q1 = 0, q2 = 0, q3 = 0, q4 = 0, q5 = 0, q6 = 0, q7 = 0;
|
|
1313
|
+
let i = start;
|
|
1314
|
+
const limit = start + (n - n % 8);
|
|
1315
|
+
for (; i < limit; i += 8) {
|
|
1316
|
+
const a0 = xs[i] - mean;
|
|
1317
|
+
const a1 = xs[i + 1] - mean;
|
|
1318
|
+
const a2 = xs[i + 2] - mean;
|
|
1319
|
+
const a3 = xs[i + 3] - mean;
|
|
1320
|
+
const a4 = xs[i + 4] - mean;
|
|
1321
|
+
const a5 = xs[i + 5] - mean;
|
|
1322
|
+
const a6 = xs[i + 6] - mean;
|
|
1323
|
+
const a7 = xs[i + 7] - mean;
|
|
1324
|
+
d0 += a0;
|
|
1325
|
+
q0 += a0 * a0;
|
|
1326
|
+
d1 += a1;
|
|
1327
|
+
q1 += a1 * a1;
|
|
1328
|
+
d2 += a2;
|
|
1329
|
+
q2 += a2 * a2;
|
|
1330
|
+
d3 += a3;
|
|
1331
|
+
q3 += a3 * a3;
|
|
1332
|
+
d4 += a4;
|
|
1333
|
+
q4 += a4 * a4;
|
|
1334
|
+
d5 += a5;
|
|
1335
|
+
q5 += a5 * a5;
|
|
1336
|
+
d6 += a6;
|
|
1337
|
+
q6 += a6 * a6;
|
|
1338
|
+
d7 += a7;
|
|
1339
|
+
q7 += a7 * a7;
|
|
1340
|
+
}
|
|
1341
|
+
let tailD = 0;
|
|
1342
|
+
let tailDD = 0;
|
|
1343
|
+
for (; i < end; i++) {
|
|
1344
|
+
const a = xs[i] - mean;
|
|
1345
|
+
tailD += a;
|
|
1346
|
+
tailDD += a * a;
|
|
1347
|
+
}
|
|
1348
|
+
return {
|
|
1349
|
+
sumD: d0 + d1 + (d2 + d3) + (d4 + d5 + (d6 + d7)) + tailD,
|
|
1350
|
+
sumDD: q0 + q1 + (q2 + q3) + (q4 + q5 + (q6 + q7)) + tailDD
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1353
|
+
const half = (n >> 1) - (n >> 1) % 8;
|
|
1354
|
+
const left = pairwiseDeviationSums(xs, mean, start, start + half);
|
|
1355
|
+
const right = pairwiseDeviationSums(xs, mean, start + half, end);
|
|
1356
|
+
return { sumD: left.sumD + right.sumD, sumDD: left.sumDD + right.sumDD };
|
|
1357
|
+
}
|
|
1311
1358
|
function neumaierCumsum(xs, out) {
|
|
1312
1359
|
let sum = 0;
|
|
1313
1360
|
let c = 0;
|
|
@@ -1321,7 +1368,7 @@ function neumaierCumsum(xs, out) {
|
|
|
1321
1368
|
}
|
|
1322
1369
|
|
|
1323
1370
|
// src/index.ts
|
|
1324
|
-
var VERSION = "0.14.
|
|
1371
|
+
var VERSION = "0.14.3";
|
|
1325
1372
|
export {
|
|
1326
1373
|
ALL_UNITS,
|
|
1327
1374
|
BASE_UNITS,
|
package/dist/internal.js
CHANGED
|
@@ -78,7 +78,7 @@ import {
|
|
|
78
78
|
typeOf,
|
|
79
79
|
unitDependencies,
|
|
80
80
|
warnOnce
|
|
81
|
-
} from "./chunk-
|
|
81
|
+
} from "./chunk-L5MWGOLB.js";
|
|
82
82
|
|
|
83
83
|
// src/error/DimensionError.ts
|
|
84
84
|
var DimensionError = class _DimensionError extends RangeError {
|
|
@@ -232,7 +232,7 @@ function format2(value, options) {
|
|
|
232
232
|
let str;
|
|
233
233
|
const rounded = v.toSignificantDigits(precision);
|
|
234
234
|
const exp = rounded.e;
|
|
235
|
-
let condition
|
|
235
|
+
let condition;
|
|
236
236
|
if (isBigNumber(lowerExp) && isBigNumber(upperExp)) {
|
|
237
237
|
const lowerExpBn = lowerExp;
|
|
238
238
|
const upperExpBn = upperExp;
|
|
@@ -559,7 +559,9 @@ function reshape(array, sizes) {
|
|
|
559
559
|
return _reshape(flatArray, processedSizes);
|
|
560
560
|
} catch (e) {
|
|
561
561
|
if (e instanceof DimensionError) {
|
|
562
|
-
|
|
562
|
+
const dimErr = new DimensionError(newLength, currentLength, "!=");
|
|
563
|
+
dimErr.cause = e;
|
|
564
|
+
throw dimErr;
|
|
563
565
|
}
|
|
564
566
|
throw e;
|
|
565
567
|
}
|
package/package.json
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@danielsimonjr/mathts-core",
|
|
3
|
-
"version": "0.14.
|
|
4
|
-
"description": "Core types, utilities, and configuration for MathTS",
|
|
5
|
-
"author": "Daniel Simon Jr.",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"main": "./dist/index.js",
|
|
9
|
-
"module": "./dist/index.js",
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"import": "./dist/index.js",
|
|
14
|
-
"types": "./dist/index.d.ts"
|
|
15
|
-
},
|
|
16
|
-
"./internal": {
|
|
17
|
-
"import": "./dist/internal.js",
|
|
18
|
-
"types": "./dist/internal.d.ts"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"files": [
|
|
22
|
-
"dist",
|
|
23
|
-
"README.md"
|
|
24
|
-
],
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "tsup",
|
|
27
|
-
"dev": "tsup --watch",
|
|
28
|
-
"test": "vitest run",
|
|
29
|
-
"test:watch": "vitest",
|
|
30
|
-
"test:coverage": "vitest run --coverage",
|
|
31
|
-
"typecheck": "tsc --noEmit",
|
|
32
|
-
"lint": "eslint src --ext .ts",
|
|
33
|
-
"lint:fix": "eslint src --ext .ts --fix",
|
|
34
|
-
"clean": "rm -rf dist",
|
|
35
|
-
"build:prod": "tsup --minify --treeshake"
|
|
36
|
-
},
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"typed-function": "github:danielsimonjr/typed-function"
|
|
39
|
-
},
|
|
40
|
-
"devDependencies": {
|
|
41
|
-
"@types/node": "^
|
|
42
|
-
"tsup": "^8.0.0",
|
|
43
|
-
"typescript": "^5.3.0",
|
|
44
|
-
"vitest": "^4.1.
|
|
45
|
-
},
|
|
46
|
-
"publishConfig": {
|
|
47
|
-
"access": "public"
|
|
48
|
-
},
|
|
49
|
-
"repository": {
|
|
50
|
-
"type": "git",
|
|
51
|
-
"url": "git+https://github.com/danielsimonjr/MathTS.git",
|
|
52
|
-
"directory": "core"
|
|
53
|
-
},
|
|
54
|
-
"keywords": [
|
|
55
|
-
"math",
|
|
56
|
-
"typescript",
|
|
57
|
-
"core"
|
|
58
|
-
]
|
|
59
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@danielsimonjr/mathts-core",
|
|
3
|
+
"version": "0.14.3",
|
|
4
|
+
"description": "Core types, utilities, and configuration for MathTS",
|
|
5
|
+
"author": "Daniel Simon Jr.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./internal": {
|
|
17
|
+
"import": "./dist/internal.js",
|
|
18
|
+
"types": "./dist/internal.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"dev": "tsup --watch",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:watch": "vitest",
|
|
30
|
+
"test:coverage": "vitest run --coverage",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"lint": "eslint src --ext .ts",
|
|
33
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
34
|
+
"clean": "rm -rf dist",
|
|
35
|
+
"build:prod": "tsup --minify --treeshake"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"typed-function": "github:danielsimonjr/typed-function"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^26.4.0",
|
|
42
|
+
"tsup": "^8.0.0",
|
|
43
|
+
"typescript": "^5.3.0",
|
|
44
|
+
"vitest": "^4.1.10"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/danielsimonjr/MathTS.git",
|
|
52
|
+
"directory": "core"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"math",
|
|
56
|
+
"typescript",
|
|
57
|
+
"core"
|
|
58
|
+
]
|
|
59
|
+
}
|