@danielsimonjr/mathts-core 0.1.3 → 0.1.5
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/index.d.ts +29 -0
- package/dist/index.js +83 -0
- package/package.json +55 -55
package/dist/index.d.ts
CHANGED
|
@@ -243,6 +243,10 @@ declare class Complex implements IComplex {
|
|
|
243
243
|
* Division: (a + bi)/(c + di) = ((ac + bd) + (bc - ad)i) / (c² + d²)
|
|
244
244
|
*/
|
|
245
245
|
divide(other: Scalar): Complex;
|
|
246
|
+
sub(other: Scalar): Complex;
|
|
247
|
+
mul(other: Scalar): Complex;
|
|
248
|
+
div(other: Scalar): Complex;
|
|
249
|
+
neg(): Complex;
|
|
246
250
|
/**
|
|
247
251
|
* Negation: -(a + bi) = -a - bi
|
|
248
252
|
*/
|
|
@@ -502,6 +506,9 @@ declare class Fraction implements IFraction {
|
|
|
502
506
|
* Division: a/b ÷ c/d = ad / bc
|
|
503
507
|
*/
|
|
504
508
|
divide(other: Scalar): Fraction;
|
|
509
|
+
mul(other: Scalar): Fraction;
|
|
510
|
+
sub(other: Scalar): Fraction;
|
|
511
|
+
div(other: Scalar): Fraction;
|
|
505
512
|
/**
|
|
506
513
|
* Negation: -(a/b) = -a/b
|
|
507
514
|
*/
|
|
@@ -734,6 +741,28 @@ declare class BigNumber implements MathTSValue {
|
|
|
734
741
|
* Convert to bigint (truncated)
|
|
735
742
|
*/
|
|
736
743
|
toBigInt(): bigint;
|
|
744
|
+
/**
|
|
745
|
+
* Binary string representation, e.g. `255 -> '0b11111111'`, `0.5 -> '0b0.1'`.
|
|
746
|
+
* Mirrors Decimal.js `toBinary()`. Negatives carry a leading `-`.
|
|
747
|
+
*/
|
|
748
|
+
toBinary(): string;
|
|
749
|
+
/**
|
|
750
|
+
* Octal string representation, e.g. `8 -> '0o10'`.
|
|
751
|
+
* Mirrors Decimal.js `toOctal()`.
|
|
752
|
+
*/
|
|
753
|
+
toOctal(): string;
|
|
754
|
+
/**
|
|
755
|
+
* Hexadecimal string representation, e.g. `255 -> '0xff'`, `10.5 -> '0xa.8'`.
|
|
756
|
+
* Mirrors Decimal.js `toHexadecimal()`.
|
|
757
|
+
*/
|
|
758
|
+
toHexadecimal(): string;
|
|
759
|
+
/**
|
|
760
|
+
* Shared radix formatter for {@link toBinary}/{@link toOctal}/{@link toHexadecimal}.
|
|
761
|
+
* Integers and terminating fractions are exact; a non-terminating fraction is
|
|
762
|
+
* truncated at `maxFractionDigits` radix digits (a safety bound — the common
|
|
763
|
+
* use is integer formatting).
|
|
764
|
+
*/
|
|
765
|
+
private toRadixString;
|
|
737
766
|
/**
|
|
738
767
|
* Addition
|
|
739
768
|
*/
|
package/dist/index.js
CHANGED
|
@@ -217,6 +217,27 @@ var Complex = class _Complex {
|
|
|
217
217
|
}
|
|
218
218
|
return new _Complex(this.re / n, this.im / n);
|
|
219
219
|
}
|
|
220
|
+
// ------------------------------------------------------------
|
|
221
|
+
// Short-name aliases (mathjs-functions calling convention)
|
|
222
|
+
//
|
|
223
|
+
// The functions-package typed-function arithmetic (subtractScalar,
|
|
224
|
+
// multiplyScalar, divideScalar, …) invokes `.add/.sub/.mul/.div/.neg`
|
|
225
|
+
// on scalars. A core Complex (e.g. produced by `sqrt(-4)`) can flow into
|
|
226
|
+
// those code paths, so it must answer to the short names too — otherwise
|
|
227
|
+
// `x.sub is not a function`. Mirrors the Fraction short-alias fix.
|
|
228
|
+
// ------------------------------------------------------------
|
|
229
|
+
sub(other) {
|
|
230
|
+
return this.subtract(other);
|
|
231
|
+
}
|
|
232
|
+
mul(other) {
|
|
233
|
+
return this.multiply(other);
|
|
234
|
+
}
|
|
235
|
+
div(other) {
|
|
236
|
+
return this.divide(other);
|
|
237
|
+
}
|
|
238
|
+
neg() {
|
|
239
|
+
return this.negate();
|
|
240
|
+
}
|
|
220
241
|
/**
|
|
221
242
|
* Negation: -(a + bi) = -a - bi
|
|
222
243
|
*/
|
|
@@ -773,6 +794,19 @@ var Fraction = class _Fraction {
|
|
|
773
794
|
}
|
|
774
795
|
return this.divide(_Fraction.fromNumber(Number(other.valueOf())));
|
|
775
796
|
}
|
|
797
|
+
// Short-name aliases (mathjs Fraction API). Ported mathjs functions such as
|
|
798
|
+
// multiplyScalar/subtractScalar/divideScalar call x.mul/x.sub/x.div; without
|
|
799
|
+
// these, mixed number/Fraction dispatch (e.g. affine unit conversion like
|
|
800
|
+
// celsius→fahrenheit) threw "x.mul is not a function".
|
|
801
|
+
mul(other) {
|
|
802
|
+
return this.multiply(other);
|
|
803
|
+
}
|
|
804
|
+
sub(other) {
|
|
805
|
+
return this.subtract(other);
|
|
806
|
+
}
|
|
807
|
+
div(other) {
|
|
808
|
+
return this.divide(other);
|
|
809
|
+
}
|
|
776
810
|
/**
|
|
777
811
|
* Negation: -(a/b) = -a/b
|
|
778
812
|
*/
|
|
@@ -1359,6 +1393,55 @@ var BigNumber = class _BigNumber {
|
|
|
1359
1393
|
}
|
|
1360
1394
|
return 0n;
|
|
1361
1395
|
}
|
|
1396
|
+
/**
|
|
1397
|
+
* Binary string representation, e.g. `255 -> '0b11111111'`, `0.5 -> '0b0.1'`.
|
|
1398
|
+
* Mirrors Decimal.js `toBinary()`. Negatives carry a leading `-`.
|
|
1399
|
+
*/
|
|
1400
|
+
toBinary() {
|
|
1401
|
+
return this.toRadixString(2, "0b");
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Octal string representation, e.g. `8 -> '0o10'`.
|
|
1405
|
+
* Mirrors Decimal.js `toOctal()`.
|
|
1406
|
+
*/
|
|
1407
|
+
toOctal() {
|
|
1408
|
+
return this.toRadixString(8, "0o");
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Hexadecimal string representation, e.g. `255 -> '0xff'`, `10.5 -> '0xa.8'`.
|
|
1412
|
+
* Mirrors Decimal.js `toHexadecimal()`.
|
|
1413
|
+
*/
|
|
1414
|
+
toHexadecimal() {
|
|
1415
|
+
return this.toRadixString(16, "0x");
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Shared radix formatter for {@link toBinary}/{@link toOctal}/{@link toHexadecimal}.
|
|
1419
|
+
* Integers and terminating fractions are exact; a non-terminating fraction is
|
|
1420
|
+
* truncated at `maxFractionDigits` radix digits (a safety bound — the common
|
|
1421
|
+
* use is integer formatting).
|
|
1422
|
+
*/
|
|
1423
|
+
toRadixString(radix, prefix, maxFractionDigits = 1100) {
|
|
1424
|
+
if (this._isNaN) return "NaN";
|
|
1425
|
+
if (this._isInfinite) return (this._sign < 0 ? "-" : "") + "Infinity";
|
|
1426
|
+
if (this._sign === 0) return prefix + "0";
|
|
1427
|
+
const negative = this._sign < 0;
|
|
1428
|
+
const absVal = this.abs();
|
|
1429
|
+
const intPart = absVal.toBigInt();
|
|
1430
|
+
let out = prefix + intPart.toString(radix);
|
|
1431
|
+
let frac = absVal.subtract(_BigNumber.fromBigInt(intPart));
|
|
1432
|
+
if (!frac.isZero()) {
|
|
1433
|
+
const radixBN = _BigNumber.fromNumber(radix);
|
|
1434
|
+
let digits = "";
|
|
1435
|
+
for (let i = 0; i < maxFractionDigits && !frac.isZero(); i++) {
|
|
1436
|
+
frac = frac.multiply(radixBN);
|
|
1437
|
+
const digit = frac.toBigInt();
|
|
1438
|
+
digits += Number(digit).toString(radix);
|
|
1439
|
+
frac = frac.subtract(_BigNumber.fromBigInt(digit));
|
|
1440
|
+
}
|
|
1441
|
+
out += "." + digits;
|
|
1442
|
+
}
|
|
1443
|
+
return (negative ? "-" : "") + out;
|
|
1444
|
+
}
|
|
1362
1445
|
// ============================================================
|
|
1363
1446
|
// Arithmetic Operations
|
|
1364
1447
|
// ============================================================
|
package/package.json
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@danielsimonjr/mathts-core",
|
|
3
|
-
"version": "0.1.
|
|
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
|
-
},
|
|
17
|
-
"files": [
|
|
18
|
-
"dist",
|
|
19
|
-
"README.md"
|
|
20
|
-
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
23
|
-
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
24
|
-
"test": "vitest run",
|
|
25
|
-
"test:watch": "vitest",
|
|
26
|
-
"test:coverage": "vitest run --coverage",
|
|
27
|
-
"typecheck": "tsc --noEmit",
|
|
28
|
-
"lint": "eslint src --ext .ts",
|
|
29
|
-
"lint:fix": "eslint src --ext .ts --fix",
|
|
30
|
-
"clean": "rm -rf dist",
|
|
31
|
-
"build:prod": "tsup src/index.ts --format esm --dts --clean --minify --treeshake"
|
|
32
|
-
},
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"typed-function": "github:danielsimonjr/typed-function"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@types/node": "^25.5.2",
|
|
38
|
-
"tsup": "^8.0.0",
|
|
39
|
-
"typescript": "^5.3.0",
|
|
40
|
-
"vitest": "^4.1.5"
|
|
41
|
-
},
|
|
42
|
-
"publishConfig": {
|
|
43
|
-
"access": "public"
|
|
44
|
-
},
|
|
45
|
-
"repository": {
|
|
46
|
-
"type": "git",
|
|
47
|
-
"url": "https://github.com/danielsimonjr/mathts",
|
|
48
|
-
"directory": "core"
|
|
49
|
-
},
|
|
50
|
-
"keywords": [
|
|
51
|
-
"math",
|
|
52
|
-
"typescript",
|
|
53
|
-
"core"
|
|
54
|
-
]
|
|
55
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@danielsimonjr/mathts-core",
|
|
3
|
+
"version": "0.1.5",
|
|
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
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
23
|
+
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"test:coverage": "vitest run --coverage",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"lint": "eslint src --ext .ts",
|
|
29
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
30
|
+
"clean": "rm -rf dist",
|
|
31
|
+
"build:prod": "tsup src/index.ts --format esm --dts --clean --minify --treeshake"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"typed-function": "github:danielsimonjr/typed-function"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^25.5.2",
|
|
38
|
+
"tsup": "^8.0.0",
|
|
39
|
+
"typescript": "^5.3.0",
|
|
40
|
+
"vitest": "^4.1.5"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/danielsimonjr/mathts",
|
|
48
|
+
"directory": "core"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"math",
|
|
52
|
+
"typescript",
|
|
53
|
+
"core"
|
|
54
|
+
]
|
|
55
|
+
}
|