@lakuna/umath 2.0.0 → 3.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/LICENSE +1 -1
- package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.js +14 -4
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +158 -158
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +173 -165
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix.d.ts +24 -24
- package/dist/linalg/Matrix.d.ts.map +1 -1
- package/dist/linalg/Matrix2.d.ts +85 -85
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +92 -88
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +134 -134
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +147 -138
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +245 -246
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +272 -251
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +147 -146
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +175 -161
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +12 -12
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +12 -12
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +7 -7
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js +15 -15
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SlowVector.d.ts +77 -77
- package/dist/linalg/SlowVector.d.ts.map +1 -1
- package/dist/linalg/SlowVector.js +153 -153
- package/dist/linalg/SlowVector.js.map +1 -1
- package/dist/linalg/SquareMatrix.d.ts +8 -8
- package/dist/linalg/SquareMatrix.d.ts.map +1 -1
- package/dist/linalg/Vector.d.ts +85 -84
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +143 -143
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +145 -143
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +173 -173
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +176 -173
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +137 -137
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +144 -140
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/types/AxisAngle.d.ts +11 -1
- package/dist/types/AxisAngle.d.ts.map +1 -1
- package/dist/types/FieldOfView.d.ts +2 -2
- package/dist/types/FieldOfView.d.ts.map +1 -1
- package/dist/utility/BigNumber.d.ts +21 -11
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +49 -31
- package/dist/utility/BigNumber.js.map +1 -1
- package/dist/utility/createAxisAngleLike.d.ts.map +1 -1
- package/dist/utility/createAxisAngleLike.js.map +1 -1
- package/package.json +13 -12
- package/src/algorithms/greatestCommonDivisor.ts +19 -7
- package/src/index.ts +21 -14
- package/src/linalg/DualQuaternion.ts +264 -238
- package/src/linalg/Matrix.ts +31 -28
- package/src/linalg/Matrix2.ts +157 -137
- package/src/linalg/Matrix3.ts +222 -191
- package/src/linalg/Matrix4.ts +464 -412
- package/src/linalg/Quaternion.ts +267 -234
- package/src/linalg/SlowMatrix.ts +31 -27
- package/src/linalg/SlowSquareMatrix.ts +19 -18
- package/src/linalg/SlowVector.ts +175 -174
- package/src/linalg/SquareMatrix.ts +9 -9
- package/src/linalg/Vector.ts +91 -89
- package/src/linalg/Vector2.ts +250 -217
- package/src/linalg/Vector3.ts +309 -269
- package/src/linalg/Vector4.ts +246 -206
- package/src/types/AxisAngle.ts +13 -1
- package/src/types/FieldOfView.ts +3 -3
- package/src/utility/BigNumber.ts +71 -38
- package/src/utility/createAxisAngleLike.ts +1 -0
|
@@ -4,6 +4,10 @@ import greatestCommonDivisor from "../algorithms/greatestCommonDivisor.js";
|
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
6
|
export default class BigNumber {
|
|
7
|
+
/** The dividend of this fraction. */
|
|
8
|
+
dividend;
|
|
9
|
+
/** The divisor of this fraction. */
|
|
10
|
+
divisor;
|
|
7
11
|
/**
|
|
8
12
|
* Create a number.
|
|
9
13
|
* @param dividend - The dividend of the number.
|
|
@@ -13,30 +17,27 @@ export default class BigNumber {
|
|
|
13
17
|
if (divisor === 0) {
|
|
14
18
|
throw new Error("Cannot divide by zero.");
|
|
15
19
|
}
|
|
20
|
+
if (BigNumber.is(dividend)) {
|
|
21
|
+
this.dividend = dividend.dividend;
|
|
22
|
+
this.divisor = dividend.divisor;
|
|
23
|
+
this.divide(divisor);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
16
26
|
this.dividend = BigInt(dividend);
|
|
27
|
+
if (BigNumber.is(divisor)) {
|
|
28
|
+
this.divisor = 1n;
|
|
29
|
+
this.divide(divisor);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
17
32
|
this.divisor = BigInt(divisor);
|
|
18
33
|
this.simplify();
|
|
19
34
|
}
|
|
20
|
-
/** The dividend of this fraction. */
|
|
21
|
-
dividend;
|
|
22
|
-
/** The divisor of this fraction. */
|
|
23
|
-
divisor;
|
|
24
35
|
/**
|
|
25
|
-
*
|
|
36
|
+
* Utility function for narrowing `Readonly<BigNumberLike>` to `Readonly<BigNumber>` or `BigIntLike`, since `Readonly` breaks the type narrowing for TypeScript.
|
|
26
37
|
* @internal
|
|
27
38
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (this.divisor < 0) {
|
|
31
|
-
this.dividend = -this.dividend;
|
|
32
|
-
this.divisor = -this.divisor;
|
|
33
|
-
}
|
|
34
|
-
// Divide both by their greatest common divisor.
|
|
35
|
-
const gcd = greatestCommonDivisor(this.dividend, this.divisor);
|
|
36
|
-
if (gcd > 1) {
|
|
37
|
-
this.dividend /= gcd;
|
|
38
|
-
this.divisor /= gcd;
|
|
39
|
-
}
|
|
39
|
+
static is(value) {
|
|
40
|
+
return value instanceof BigNumber;
|
|
40
41
|
}
|
|
41
42
|
/**
|
|
42
43
|
* Add a number to this number.
|
|
@@ -44,7 +45,7 @@ export default class BigNumber {
|
|
|
44
45
|
* @returns This number.
|
|
45
46
|
*/
|
|
46
47
|
add(n) {
|
|
47
|
-
if (n
|
|
48
|
+
if (BigNumber.is(n)) {
|
|
48
49
|
this.dividend = this.dividend * n.divisor + n.dividend * this.divisor;
|
|
49
50
|
this.divisor *= n.divisor;
|
|
50
51
|
}
|
|
@@ -55,17 +56,17 @@ export default class BigNumber {
|
|
|
55
56
|
return this;
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
|
-
*
|
|
59
|
+
* Divide this number by a number.
|
|
59
60
|
* @param n - The other number.
|
|
60
61
|
* @returns This number.
|
|
61
62
|
*/
|
|
62
|
-
|
|
63
|
-
if (n
|
|
64
|
-
this.dividend
|
|
65
|
-
this.divisor *= n.
|
|
63
|
+
divide(n) {
|
|
64
|
+
if (BigNumber.is(n)) {
|
|
65
|
+
this.dividend *= n.divisor;
|
|
66
|
+
this.divisor *= n.dividend;
|
|
66
67
|
}
|
|
67
68
|
else {
|
|
68
|
-
this.
|
|
69
|
+
this.divisor *= BigInt(n);
|
|
69
70
|
}
|
|
70
71
|
this.simplify();
|
|
71
72
|
return this;
|
|
@@ -76,7 +77,7 @@ export default class BigNumber {
|
|
|
76
77
|
* @returns This number.
|
|
77
78
|
*/
|
|
78
79
|
multiply(n) {
|
|
79
|
-
if (n
|
|
80
|
+
if (BigNumber.is(n)) {
|
|
80
81
|
this.dividend *= n.dividend;
|
|
81
82
|
this.divisor *= n.divisor;
|
|
82
83
|
}
|
|
@@ -87,17 +88,17 @@ export default class BigNumber {
|
|
|
87
88
|
return this;
|
|
88
89
|
}
|
|
89
90
|
/**
|
|
90
|
-
*
|
|
91
|
+
* Subtract a number from this number.
|
|
91
92
|
* @param n - The other number.
|
|
92
93
|
* @returns This number.
|
|
93
94
|
*/
|
|
94
|
-
|
|
95
|
-
if (n
|
|
96
|
-
this.dividend
|
|
97
|
-
this.divisor *= n.
|
|
95
|
+
subtract(n) {
|
|
96
|
+
if (BigNumber.is(n)) {
|
|
97
|
+
this.dividend = this.dividend * n.divisor - n.dividend * this.divisor;
|
|
98
|
+
this.divisor *= n.divisor;
|
|
98
99
|
}
|
|
99
100
|
else {
|
|
100
|
-
this.
|
|
101
|
+
this.dividend -= BigInt(n) * this.divisor;
|
|
101
102
|
}
|
|
102
103
|
this.simplify();
|
|
103
104
|
return this;
|
|
@@ -117,5 +118,22 @@ export default class BigNumber {
|
|
|
117
118
|
toString() {
|
|
118
119
|
return `${this.dividend.toLocaleString()}/${this.divisor.toLocaleString()}`;
|
|
119
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Simplify this fraction.
|
|
123
|
+
* @internal
|
|
124
|
+
*/
|
|
125
|
+
simplify() {
|
|
126
|
+
// Switch signs such that only the dividend can be negative.
|
|
127
|
+
if (this.divisor < 0) {
|
|
128
|
+
this.dividend = -this.dividend;
|
|
129
|
+
this.divisor = -this.divisor;
|
|
130
|
+
}
|
|
131
|
+
// Divide both by their greatest common divisor.
|
|
132
|
+
const gcd = greatestCommonDivisor(this.dividend, this.divisor);
|
|
133
|
+
if (gcd > 1) {
|
|
134
|
+
this.dividend /= gcd;
|
|
135
|
+
this.divisor /= gcd;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
120
138
|
}
|
|
121
139
|
//# sourceMappingURL=BigNumber.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BigNumber.js","sourceRoot":"","sources":["../../src/utility/BigNumber.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"BigNumber.js","sourceRoot":"","sources":["../../src/utility/BigNumber.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,wCAAwC,CAAC;AAc3E;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAC7B,qCAAqC;IAC9B,QAAQ,CAAS;IAExB,oCAAoC;IAC7B,OAAO,CAAS;IAEvB;;;;OAIG;IACH,YACC,WAAoC,CAAC,EACrC,UAAmC,CAAC;QAEpC,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC3C,CAAC;QAED,IAAI,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;YAClC,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACrB,OAAO;QACR,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;QACjC,IAAI,SAAS,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACrB,OAAO;QACR,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;QAC/B,IAAI,CAAC,QAAQ,EAAE,CAAC;IACjB,CAAC;IAED;;;OAGG;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IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/D,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;YACb,IAAI,CAAC,QAAQ,IAAI,GAAG,CAAC;YACrB,IAAI,CAAC,OAAO,IAAI,GAAG,CAAC;QACrB,CAAC;IACF,CAAC;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAxisAngleLike.d.ts","sourceRoot":"","sources":["../../src/utility/createAxisAngleLike.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"createAxisAngleLike.d.ts","sourceRoot":"","sources":["../../src/utility/createAxisAngleLike.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AAInD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,IAAI,SAAS,GAAG;IAC1D,IAAI,EAAE,YAAY,CAAC;CACnB,CAEA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAxisAngleLike.js","sourceRoot":"","sources":["../../src/utility/createAxisAngleLike.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createAxisAngleLike.js","sourceRoot":"","sources":["../../src/utility/createAxisAngleLike.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB;IAG1C,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,CAAC;AAChD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakuna/umath",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "A lightweight math library.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"math"
|
|
@@ -30,24 +30,25 @@
|
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsc",
|
|
33
|
-
"lint": "eslint src",
|
|
34
33
|
"doc": "typedoc",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
34
|
+
"fix": "eslint src --fix",
|
|
35
|
+
"lint": "eslint src",
|
|
36
|
+
"test": "node --test"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@eslint/js": "^
|
|
39
|
+
"@eslint/js": "^10.0.1",
|
|
40
40
|
"@types/eslint": "^9.6.1",
|
|
41
41
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
42
|
-
"@types/node": "^25.0
|
|
43
|
-
"eslint": "^
|
|
42
|
+
"@types/node": "^25.5.0",
|
|
43
|
+
"eslint": "^10.0.3",
|
|
44
44
|
"eslint-config-prettier": "^10.1.8",
|
|
45
|
-
"eslint-plugin-
|
|
46
|
-
"eslint-plugin-
|
|
47
|
-
"
|
|
48
|
-
"
|
|
45
|
+
"eslint-plugin-perfectionist": "^5.7.0",
|
|
46
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
47
|
+
"eslint-plugin-tsdoc": "^0.5.2",
|
|
48
|
+
"prettier": "^3.8.1",
|
|
49
|
+
"typedoc": "^0.28.17",
|
|
49
50
|
"typescript": "^5.9.3",
|
|
50
|
-
"typescript-eslint": "^8.
|
|
51
|
+
"typescript-eslint": "^8.57.1"
|
|
51
52
|
},
|
|
52
53
|
"exports": {
|
|
53
54
|
".": "./dist/index.js",
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* @public
|
|
8
8
|
*/
|
|
9
9
|
export default function greatestCommonDivisor(a: bigint, b: bigint): bigint;
|
|
10
|
-
|
|
11
10
|
/**
|
|
12
11
|
* Determine the greatest common divisor of two integers.
|
|
13
12
|
* @param a - The first integer.
|
|
@@ -17,21 +16,34 @@ export default function greatestCommonDivisor(a: bigint, b: bigint): bigint;
|
|
|
17
16
|
* @public
|
|
18
17
|
*/
|
|
19
18
|
export default function greatestCommonDivisor(a: number, b: number): number;
|
|
20
|
-
|
|
21
19
|
export default function greatestCommonDivisor(
|
|
22
20
|
a: bigint | number,
|
|
23
21
|
b: bigint | number
|
|
24
|
-
) {
|
|
22
|
+
): bigint | number {
|
|
23
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
24
|
+
// Ensure that both of the integers are positive.
|
|
25
|
+
let c = Math.abs(a);
|
|
26
|
+
let d = Math.abs(b);
|
|
27
|
+
|
|
28
|
+
// Apply the Euclidean algorithm.
|
|
29
|
+
while (d) {
|
|
30
|
+
[c, d] = [d, c % d];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return c;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof a === "number" || typeof b === "number") {
|
|
37
|
+
throw new Error("Mismatched argument types.");
|
|
38
|
+
}
|
|
39
|
+
|
|
25
40
|
// Ensure that both of the integers are positive. Can't use `Math.abs` in case `a` and `b` are `bigint`s.
|
|
26
41
|
let c = a < 0 ? -a : a;
|
|
27
42
|
let d = b < 0 ? -b : b;
|
|
28
43
|
|
|
29
44
|
// Apply the Euclidean algorithm.
|
|
30
45
|
while (d) {
|
|
31
|
-
|
|
32
|
-
const temp = c;
|
|
33
|
-
c = d;
|
|
34
|
-
d = (temp as number) % (d as number);
|
|
46
|
+
[c, d] = [d, c % d];
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
return c;
|
package/src/index.ts
CHANGED
|
@@ -19,32 +19,39 @@ export { default as summation } from "./algorithms/summation.js";
|
|
|
19
19
|
|
|
20
20
|
// Linear Algebra
|
|
21
21
|
export {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
default as DualQuaternion,
|
|
23
|
+
type DualQuaternionLike
|
|
24
24
|
} from "./linalg/DualQuaternion.js";
|
|
25
|
-
export
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export
|
|
25
|
+
export { default as Matrix2, type Matrix2Like } from "./linalg/Matrix2.js";
|
|
26
|
+
export { default as Matrix3, type Matrix3Like } from "./linalg/Matrix3.js";
|
|
27
|
+
export { default as Matrix4, type Matrix4Like } from "./linalg/Matrix4.js";
|
|
28
|
+
export type { default as Matrix, MatrixLike } from "./linalg/Matrix.js";
|
|
29
29
|
export {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
default as Quaternion,
|
|
31
|
+
type QuaternionLike
|
|
32
32
|
} from "./linalg/Quaternion.js";
|
|
33
33
|
export { default as SlowMatrix } from "./linalg/SlowMatrix.js";
|
|
34
34
|
export { default as SlowSquareMatrix } from "./linalg/SlowSquareMatrix.js";
|
|
35
35
|
export { default as SlowVector } from "./linalg/SlowVector.js";
|
|
36
36
|
export type { default as SquareMatrix } from "./linalg/SquareMatrix.js";
|
|
37
|
-
export
|
|
38
|
-
export {
|
|
39
|
-
export {
|
|
40
|
-
export
|
|
37
|
+
export { default as Vector2, type Vector2Like } from "./linalg/Vector2.js";
|
|
38
|
+
export { default as Vector3, type Vector3Like } from "./linalg/Vector3.js";
|
|
39
|
+
export { default as Vector4, type Vector4Like } from "./linalg/Vector4.js";
|
|
40
|
+
export type { default as Vector, VectorLike } from "./linalg/Vector.js";
|
|
41
41
|
|
|
42
42
|
// Types
|
|
43
|
-
export type {
|
|
43
|
+
export type {
|
|
44
|
+
default as AxisAngle,
|
|
45
|
+
ReadonlyAxisAngle
|
|
46
|
+
} from "./types/AxisAngle.js";
|
|
44
47
|
export type { default as FieldOfView } from "./types/FieldOfView.js";
|
|
45
48
|
|
|
46
49
|
// Utility
|
|
47
|
-
export {
|
|
50
|
+
export {
|
|
51
|
+
type BigIntLike,
|
|
52
|
+
default as BigNumber,
|
|
53
|
+
type BigNumberLike
|
|
54
|
+
} from "./utility/BigNumber.js";
|
|
48
55
|
export { default as createAxisAngleLike } from "./utility/createAxisAngleLike.js";
|
|
49
56
|
export { default as epsilon } from "./utility/epsilon.js";
|
|
50
57
|
export { default as MagnitudeError } from "./utility/MagnitudeError.js";
|