@danielsimonjr/mathts-core 0.3.1 → 0.4.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/dist/chunk-ZPGSJR5L.js +6258 -0
- package/dist/index-DpOizJsa.d.ts +337 -0
- package/dist/index.d.ts +212 -186
- package/dist/index.js +140 -2746
- package/dist/internal.d.ts +510 -0
- package/dist/internal.js +144 -0
- package/package.json +7 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { U as Unit, a as UnitInstance, i as isUnitValue } from './index-DpOizJsa.js';
|
|
1
2
|
import { TypedInstance, ReferTo, ReferToSelf, TypedFunction, SignatureFunction } from 'typed-function';
|
|
2
3
|
export { ReferTo, ReferToSelf, SignatureFunction, TypedFunction, TypedInstance, create, default as typed } from 'typed-function';
|
|
3
4
|
|
|
@@ -416,19 +417,6 @@ declare const COMPLEX_ZERO: Complex;
|
|
|
416
417
|
declare const COMPLEX_ONE: Complex;
|
|
417
418
|
declare const COMPLEX_NEG_ONE: Complex;
|
|
418
419
|
|
|
419
|
-
/**
|
|
420
|
-
* Dual number for forward-mode automatic differentiation.
|
|
421
|
-
*
|
|
422
|
-
* A dual number `a + b·ε` (with ε² = 0) carries a value and its first
|
|
423
|
-
* derivative. Evaluating a function built from the overloaded elementary
|
|
424
|
-
* operations on `Dual.variable(x)` propagates the derivative automatically:
|
|
425
|
-
*
|
|
426
|
-
* derivative(x => multiply(sin(x), x), 2)
|
|
427
|
-
* // sin(2)·1 + 2·cos(2) — exact, no finite differences
|
|
428
|
-
*
|
|
429
|
-
* The derivative rules live here as methods so the typed-function signatures in
|
|
430
|
-
* the `functions` package are one-liners (e.g. `Dual: (a) => a.sin()`).
|
|
431
|
-
*/
|
|
432
420
|
declare class Dual {
|
|
433
421
|
/** Function value (the real part). */
|
|
434
422
|
readonly value: number;
|
|
@@ -448,6 +436,7 @@ declare class Dual {
|
|
|
448
436
|
powConst(k: number): Dual;
|
|
449
437
|
/** General power a^b: d = a^b·(b'·ln a + b·a'/a). */
|
|
450
438
|
pow(o: Dual): Dual;
|
|
439
|
+
private unary;
|
|
451
440
|
sin(): Dual;
|
|
452
441
|
cos(): Dual;
|
|
453
442
|
tan(): Dual;
|
|
@@ -464,6 +453,135 @@ declare class Dual {
|
|
|
464
453
|
/** Type guard for {@link Dual}. */
|
|
465
454
|
declare function isDual(x: unknown): x is Dual;
|
|
466
455
|
|
|
456
|
+
/**
|
|
457
|
+
* Canonical elementary-function derivative rules for forward-mode automatic
|
|
458
|
+
* differentiation. This is the single source of truth for the chain rules,
|
|
459
|
+
* shared by the scalar {@link Dual} (core) and the tensor `DualTensor`
|
|
460
|
+
* (autograd) so neither reinvents them.
|
|
461
|
+
*
|
|
462
|
+
* Each rule is a pair of pure `number → number` functions:
|
|
463
|
+
* - `primal(x)` — f(x)
|
|
464
|
+
* - `deriv(x, y)` — f′(x), given both x and the already-computed y = f(x),
|
|
465
|
+
* so output-reusing derivatives (exp, tanh, sqrt, cbrt, expm1) stay cheap.
|
|
466
|
+
*
|
|
467
|
+
* Keeping these as plain scalar functions (no `Dual`/`Tensor` allocation) is
|
|
468
|
+
* what lets autograd's `Float64Array` element-wise loop stay allocation-free.
|
|
469
|
+
* It is also the propagation path: a future accelerated `primal` in the
|
|
470
|
+
* standard layer (WASM/SIMD batch kernels) can be swapped in here and every
|
|
471
|
+
* consumer inherits the speedup without touching this contract.
|
|
472
|
+
*/
|
|
473
|
+
/** A forward-mode derivative rule for a unary elementary function. */
|
|
474
|
+
interface DualUnaryRule {
|
|
475
|
+
/** f(x). */
|
|
476
|
+
readonly primal: (x: number) => number;
|
|
477
|
+
/** f′(x), given x and y = f(x) (y lets exp/tanh/sqrt/… avoid recomputation). */
|
|
478
|
+
readonly deriv: (x: number, y: number) => number;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* The canonical table. Derivatives are stated in the cheapest exact form
|
|
482
|
+
* (reusing y where that avoids a redundant transcendental call).
|
|
483
|
+
*/
|
|
484
|
+
declare const DUAL_UNARY_RULES: {
|
|
485
|
+
exp: {
|
|
486
|
+
primal: (x: number) => number;
|
|
487
|
+
deriv: (_x: number, y: number) => number;
|
|
488
|
+
};
|
|
489
|
+
expm1: {
|
|
490
|
+
primal: (x: number) => number;
|
|
491
|
+
deriv: (_x: number, y: number) => number;
|
|
492
|
+
};
|
|
493
|
+
log: {
|
|
494
|
+
primal: (x: number) => number;
|
|
495
|
+
deriv: (x: number) => number;
|
|
496
|
+
};
|
|
497
|
+
log2: {
|
|
498
|
+
primal: (x: number) => number;
|
|
499
|
+
deriv: (x: number) => number;
|
|
500
|
+
};
|
|
501
|
+
log10: {
|
|
502
|
+
primal: (x: number) => number;
|
|
503
|
+
deriv: (x: number) => number;
|
|
504
|
+
};
|
|
505
|
+
log1p: {
|
|
506
|
+
primal: (x: number) => number;
|
|
507
|
+
deriv: (x: number) => number;
|
|
508
|
+
};
|
|
509
|
+
sin: {
|
|
510
|
+
primal: (x: number) => number;
|
|
511
|
+
deriv: (x: number) => number;
|
|
512
|
+
};
|
|
513
|
+
cos: {
|
|
514
|
+
primal: (x: number) => number;
|
|
515
|
+
deriv: (x: number) => number;
|
|
516
|
+
};
|
|
517
|
+
tan: {
|
|
518
|
+
primal: (x: number) => number;
|
|
519
|
+
deriv: (x: number) => number;
|
|
520
|
+
};
|
|
521
|
+
asin: {
|
|
522
|
+
primal: (x: number) => number;
|
|
523
|
+
deriv: (x: number) => number;
|
|
524
|
+
};
|
|
525
|
+
acos: {
|
|
526
|
+
primal: (x: number) => number;
|
|
527
|
+
deriv: (x: number) => number;
|
|
528
|
+
};
|
|
529
|
+
atan: {
|
|
530
|
+
primal: (x: number) => number;
|
|
531
|
+
deriv: (x: number) => number;
|
|
532
|
+
};
|
|
533
|
+
sinh: {
|
|
534
|
+
primal: (x: number) => number;
|
|
535
|
+
deriv: (x: number) => number;
|
|
536
|
+
};
|
|
537
|
+
cosh: {
|
|
538
|
+
primal: (x: number) => number;
|
|
539
|
+
deriv: (x: number) => number;
|
|
540
|
+
};
|
|
541
|
+
tanh: {
|
|
542
|
+
primal: (x: number) => number;
|
|
543
|
+
deriv: (_x: number, y: number) => number;
|
|
544
|
+
};
|
|
545
|
+
asinh: {
|
|
546
|
+
primal: (x: number) => number;
|
|
547
|
+
deriv: (x: number) => number;
|
|
548
|
+
};
|
|
549
|
+
acosh: {
|
|
550
|
+
primal: (x: number) => number;
|
|
551
|
+
deriv: (x: number) => number;
|
|
552
|
+
};
|
|
553
|
+
atanh: {
|
|
554
|
+
primal: (x: number) => number;
|
|
555
|
+
deriv: (x: number) => number;
|
|
556
|
+
};
|
|
557
|
+
sqrt: {
|
|
558
|
+
primal: (x: number) => number;
|
|
559
|
+
deriv: (_x: number, y: number) => number;
|
|
560
|
+
};
|
|
561
|
+
cbrt: {
|
|
562
|
+
primal: (x: number) => number;
|
|
563
|
+
deriv: (_x: number, y: number) => number;
|
|
564
|
+
};
|
|
565
|
+
square: {
|
|
566
|
+
primal: (x: number) => number;
|
|
567
|
+
deriv: (x: number) => number;
|
|
568
|
+
};
|
|
569
|
+
reciprocal: {
|
|
570
|
+
primal: (x: number) => number;
|
|
571
|
+
deriv: (x: number) => number;
|
|
572
|
+
};
|
|
573
|
+
abs: {
|
|
574
|
+
primal: (x: number) => number;
|
|
575
|
+
deriv: (x: number) => number;
|
|
576
|
+
};
|
|
577
|
+
sign: {
|
|
578
|
+
primal: (x: number) => number;
|
|
579
|
+
deriv: () => number;
|
|
580
|
+
};
|
|
581
|
+
};
|
|
582
|
+
/** Name of a rule in {@link DUAL_UNARY_RULES}. */
|
|
583
|
+
type DualUnaryRuleName = keyof typeof DUAL_UNARY_RULES;
|
|
584
|
+
|
|
467
585
|
/**
|
|
468
586
|
* Named mathematical constants (plain `number`).
|
|
469
587
|
*
|
|
@@ -512,7 +630,7 @@ declare class Fraction implements IFraction {
|
|
|
512
630
|
readonly type = "Fraction";
|
|
513
631
|
readonly numerator: bigint;
|
|
514
632
|
readonly denominator: bigint;
|
|
515
|
-
constructor(numerator: bigint | number | string, denominator?: bigint | number | string);
|
|
633
|
+
constructor(numerator: bigint | number | string | Fraction, denominator?: bigint | number | string | Fraction);
|
|
516
634
|
/**
|
|
517
635
|
* Create a Fraction from a number (with optional precision)
|
|
518
636
|
*/
|
|
@@ -861,10 +979,18 @@ declare class BigNumber implements MathTSValue {
|
|
|
861
979
|
* Alias for multiply — mathjs / Decimal.js compatibility.
|
|
862
980
|
*/
|
|
863
981
|
mul(other: Scalar | BigNumber | number | string): BigNumber;
|
|
982
|
+
/**
|
|
983
|
+
* Alias for multiply — Decimal.js calling convention (used by the Unit).
|
|
984
|
+
*/
|
|
985
|
+
times(other: Scalar | BigNumber | number | string): BigNumber;
|
|
864
986
|
/**
|
|
865
987
|
* Division
|
|
866
988
|
*/
|
|
867
989
|
divide(other: Scalar | BigNumber | number | string): BigNumber;
|
|
990
|
+
/**
|
|
991
|
+
* Alias for divide — Decimal.js calling convention (used by the Unit).
|
|
992
|
+
*/
|
|
993
|
+
div(other: Scalar | BigNumber | number | string): BigNumber;
|
|
868
994
|
/**
|
|
869
995
|
* Negation
|
|
870
996
|
*/
|
|
@@ -1068,6 +1194,77 @@ declare const BIGNUMBER_E: BigNumber;
|
|
|
1068
1194
|
declare const BIGNUMBER_LN2: BigNumber;
|
|
1069
1195
|
declare const BIGNUMBER_LN10: BigNumber;
|
|
1070
1196
|
|
|
1197
|
+
/** Any scalar core can do arithmetic on. */
|
|
1198
|
+
type NumericScalar = number | bigint | Complex | Fraction | BigNumber;
|
|
1199
|
+
/** Add two scalar values, `x + y`. */
|
|
1200
|
+
declare function addScalar(x: NumericScalar, y: NumericScalar): NumericScalar;
|
|
1201
|
+
/** Subtract two scalar values, `x − y` (order preserved through promotion). */
|
|
1202
|
+
declare function subtractScalar(x: NumericScalar, y: NumericScalar): NumericScalar;
|
|
1203
|
+
/** Multiply two scalar values, `x · y`. */
|
|
1204
|
+
declare function multiplyScalar(x: NumericScalar, y: NumericScalar): NumericScalar;
|
|
1205
|
+
/** Divide two scalar values, `x ÷ y` (order preserved through promotion). */
|
|
1206
|
+
declare function divideScalar(x: NumericScalar, y: NumericScalar): NumericScalar;
|
|
1207
|
+
/**
|
|
1208
|
+
* Raise `base` to the power `exp`, treating `exp` as a real exponent.
|
|
1209
|
+
*
|
|
1210
|
+
* The exact `.pow()` of an exact type (Fraction/BigNumber) only supports INTEGER
|
|
1211
|
+
* exponents. A non-integer exponent of an exact base is generally irrational, so
|
|
1212
|
+
* it cannot stay exact — those cases fall back to double-precision `Math.pow`,
|
|
1213
|
+
* returning a plain `number`. (Without this guard, `BigNumber.pow(0.5)` silently
|
|
1214
|
+
* returned 1 and `Fraction.pow(0.5)` threw `BigInt(0.5)`.)
|
|
1215
|
+
*/
|
|
1216
|
+
declare function pow(base: NumericScalar, exp: NumericScalar): NumericScalar;
|
|
1217
|
+
/** Absolute value. `abs(Complex)` returns the magnitude (a real number). */
|
|
1218
|
+
declare function abs(x: NumericScalar): NumericScalar;
|
|
1219
|
+
/** Round toward zero (truncate). Complex components are truncated independently. */
|
|
1220
|
+
declare function fix(x: NumericScalar): NumericScalar;
|
|
1221
|
+
/**
|
|
1222
|
+
* Round to the nearest integer, half toward +∞ — matching `Math.round` and
|
|
1223
|
+
* `Fraction.round`. `BigNumber.round` defaults to half-away-from-zero, so it is
|
|
1224
|
+
* given `'halfCeil'` explicitly; otherwise negative half-integers would round
|
|
1225
|
+
* type-dependently (`round(-2.5)` = −2 for number/Fraction but −3 for BigNumber).
|
|
1226
|
+
* Complex components are rounded independently.
|
|
1227
|
+
*/
|
|
1228
|
+
declare function round(x: NumericScalar): NumericScalar;
|
|
1229
|
+
/**
|
|
1230
|
+
* Equality. Floating-point operands compare with the configured tolerance
|
|
1231
|
+
* (`relTol`/`absTol`); exact types (Fraction, BigNumber) compare exactly —
|
|
1232
|
+
* tolerance is meaningless for an exact rational/decimal.
|
|
1233
|
+
*/
|
|
1234
|
+
declare function equal(x: NumericScalar, y: NumericScalar, relTol?: number, absTol?: number): boolean;
|
|
1235
|
+
/**
|
|
1236
|
+
* True for values math treats as real-numeric: `number`, `bigint`, `boolean`,
|
|
1237
|
+
* `Fraction`, `BigNumber`. Mirrors mathjs semantics — `boolean` counts (it
|
|
1238
|
+
* coerces to 0/1), while `Complex` is intentionally NOT numeric (callers test it
|
|
1239
|
+
* separately), so `isNumeric(complex)` is `false`. The relocated Unit uses this as
|
|
1240
|
+
* its value-type gate (`isNumeric(value) || isComplex(value)`), and mathjs accepts
|
|
1241
|
+
* `new Unit(true)` — so booleans must pass.
|
|
1242
|
+
*/
|
|
1243
|
+
declare function isNumeric(x: unknown): boolean;
|
|
1244
|
+
/**
|
|
1245
|
+
* Convert any scalar to a plain JS `number`. A non-real `Complex` (nonzero
|
|
1246
|
+
* imaginary part) has no real-number value and throws.
|
|
1247
|
+
*/
|
|
1248
|
+
declare function number(x: NumericScalar): number;
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* Typed error classes for the Unit. Kept in their own module (with no Unit
|
|
1252
|
+
* imports) so both the merged `Unit` (`Unit.ts`) and the `core/src/types/unit.ts`
|
|
1253
|
+
* compatibility surface can import them without a circular dependency, and so
|
|
1254
|
+
* callers can `catch (e) { if (e instanceof UnitParseError) … }` as before the
|
|
1255
|
+
* two Unit implementations merged.
|
|
1256
|
+
*/
|
|
1257
|
+
/** Thrown when a unit notation string cannot be parsed against the registry. */
|
|
1258
|
+
declare class UnitParseError extends Error {
|
|
1259
|
+
readonly name = "UnitParseError";
|
|
1260
|
+
constructor(message: string);
|
|
1261
|
+
}
|
|
1262
|
+
/** Thrown when an operation requires two units to share a base dimension and they do not. */
|
|
1263
|
+
declare class DimensionMismatchError extends Error {
|
|
1264
|
+
readonly name = "DimensionMismatchError";
|
|
1265
|
+
constructor(message: string);
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1071
1268
|
/**
|
|
1072
1269
|
* Unit definitions for the Unit type.
|
|
1073
1270
|
*
|
|
@@ -1147,177 +1344,6 @@ declare const UNIT_ALIASES: Record<string, string>;
|
|
|
1147
1344
|
*/
|
|
1148
1345
|
declare function getUnitDef(name: string): UnitDef | undefined;
|
|
1149
1346
|
|
|
1150
|
-
/**
|
|
1151
|
-
* Unit type — dimensional analysis, composition, conversion, and pretty-print.
|
|
1152
|
-
*
|
|
1153
|
-
* A {@link Unit} couples a numeric magnitude to a dimensional signature derived
|
|
1154
|
-
* from a registry of named units (see {@link ./unit-definitions}). Units are
|
|
1155
|
-
* **immutable**: every operation returns a new instance. The canonical
|
|
1156
|
-
* representation always stores the value in SI base units, regardless of how
|
|
1157
|
-
* the unit was constructed — so `new Unit(5, 'km').value === 5000` (metres).
|
|
1158
|
-
* The original notation is preserved on the instance for round-trip display.
|
|
1159
|
-
*
|
|
1160
|
-
* Design notes (intentional differences from mathjs's `Unit` class):
|
|
1161
|
-
* - **Immutable value semantics** instead of mutable JS prototype-class style.
|
|
1162
|
-
* - **No closure over a `math` instance.** Unit is self-contained — no
|
|
1163
|
-
* dependency on `addScalar`, `format`, `BigNumber`, etc. Values are plain
|
|
1164
|
-
* JS numbers.
|
|
1165
|
-
* - **`dimensions` is a struct** (a record over the seven SI bases) rather
|
|
1166
|
-
* than mathjs's array indexed by `BASE_DIMENSIONS`. Cheaper to work with in
|
|
1167
|
-
* TS, and lets the field be `Readonly<Dimensions>`.
|
|
1168
|
-
* - **Temperature offsets are honoured only for single-temperature-degree
|
|
1169
|
-
* units** (e.g. `°C` alone, not `°C/s`), matching mathjs but stated
|
|
1170
|
-
* explicitly here.
|
|
1171
|
-
*
|
|
1172
|
-
* @module @danielsimonjr/mathts-core/types/unit
|
|
1173
|
-
*/
|
|
1174
|
-
|
|
1175
|
-
/**
|
|
1176
|
-
* Thrown when a unit operation requires matching dimensions but the operands
|
|
1177
|
-
* disagree. Carries the offending dimension vectors for debugging.
|
|
1178
|
-
*/
|
|
1179
|
-
declare class DimensionMismatchError extends Error {
|
|
1180
|
-
readonly left: Dimensions;
|
|
1181
|
-
readonly right: Dimensions;
|
|
1182
|
-
readonly name = "DimensionMismatchError";
|
|
1183
|
-
constructor(left: Dimensions, right: Dimensions, op: string);
|
|
1184
|
-
}
|
|
1185
|
-
/** Thrown when a notation string cannot be parsed against the registry. */
|
|
1186
|
-
declare class UnitParseError extends Error {
|
|
1187
|
-
readonly name = "UnitParseError";
|
|
1188
|
-
constructor(notation: string, reason: string);
|
|
1189
|
-
}
|
|
1190
|
-
/**
|
|
1191
|
-
* A physical quantity: a numeric magnitude paired with a dimensional
|
|
1192
|
-
* signature derived from named units.
|
|
1193
|
-
*
|
|
1194
|
-
* Construction examples:
|
|
1195
|
-
* ```ts
|
|
1196
|
-
* new Unit(5, 'm'); // 5 metres
|
|
1197
|
-
* new Unit(3.5, 'km/h'); // 3.5 km/h
|
|
1198
|
-
* new Unit(20, '°C'); // 20 °C
|
|
1199
|
-
* new Unit(1, 'kg·m/s²'); // 1 newton (composed)
|
|
1200
|
-
* ```
|
|
1201
|
-
*
|
|
1202
|
-
* All instances are immutable; every operation returns a new {@link Unit}.
|
|
1203
|
-
* The `value` field is always in SI base units, so:
|
|
1204
|
-
*
|
|
1205
|
-
* ```ts
|
|
1206
|
-
* new Unit(5, 'km').value; // 5000 (canonical metres)
|
|
1207
|
-
* new Unit(20, '°C').value; // 293.15 (canonical kelvin)
|
|
1208
|
-
* ```
|
|
1209
|
-
*/
|
|
1210
|
-
declare class Unit {
|
|
1211
|
-
/** Discriminator (matches the prototype-flag convention). */
|
|
1212
|
-
readonly type = "Unit";
|
|
1213
|
-
/** Used by `isUnit()` and typed-function dispatch. */
|
|
1214
|
-
readonly isUnit = true;
|
|
1215
|
-
/** Numeric magnitude in **SI base units**. */
|
|
1216
|
-
readonly value: number;
|
|
1217
|
-
/** Dimensional signature. */
|
|
1218
|
-
readonly dimensions: Readonly<Dimensions>;
|
|
1219
|
-
/** Original notation string, preserved for `toString()` round-trip. */
|
|
1220
|
-
readonly notation: string;
|
|
1221
|
-
/**
|
|
1222
|
-
* Construct a Unit from a numeric value and a notation string.
|
|
1223
|
-
*
|
|
1224
|
-
* The notation is parsed against the registered unit definitions in
|
|
1225
|
-
* {@link ./unit-definitions}. SI prefixes are applied automatically when
|
|
1226
|
-
* the bare notation doesn't match a registered unit. Compound expressions
|
|
1227
|
-
* like `"m/s²"`, `"kg·m/s²"`, and `"1/s"` are supported.
|
|
1228
|
-
*
|
|
1229
|
-
* @throws {UnitParseError} if `notation` cannot be parsed against the
|
|
1230
|
-
* registered unit definitions.
|
|
1231
|
-
*/
|
|
1232
|
-
constructor(value: number, notation: string);
|
|
1233
|
-
/**
|
|
1234
|
-
* Internal construction shortcut from already-canonical fields. **Not
|
|
1235
|
-
* intended for direct use** — most callers should use the `(value,
|
|
1236
|
-
* notation)` form.
|
|
1237
|
-
*/
|
|
1238
|
-
constructor(value: number, dimensions: Readonly<Dimensions>, notation: string);
|
|
1239
|
-
/**
|
|
1240
|
-
* Add two units. Requires identical dimensions.
|
|
1241
|
-
*
|
|
1242
|
-
* @throws {DimensionMismatchError} if dimensions differ.
|
|
1243
|
-
*/
|
|
1244
|
-
add(other: Unit): Unit;
|
|
1245
|
-
/**
|
|
1246
|
-
* Subtract two units. Requires identical dimensions.
|
|
1247
|
-
*
|
|
1248
|
-
* @throws {DimensionMismatchError} if dimensions differ.
|
|
1249
|
-
*/
|
|
1250
|
-
sub(other: Unit): Unit;
|
|
1251
|
-
/**
|
|
1252
|
-
* Multiply by another unit or a scalar. Dimensions add when multiplying by
|
|
1253
|
-
* another unit; unchanged when multiplying by a scalar.
|
|
1254
|
-
*/
|
|
1255
|
-
mul(other: Unit | number): Unit;
|
|
1256
|
-
/**
|
|
1257
|
-
* Divide by another unit or a scalar. Dimensions subtract when dividing by
|
|
1258
|
-
* another unit; unchanged when dividing by a scalar.
|
|
1259
|
-
*/
|
|
1260
|
-
div(other: Unit | number): Unit;
|
|
1261
|
-
/**
|
|
1262
|
-
* Raise to an integer or rational power. Dimensions scale by `n`.
|
|
1263
|
-
*/
|
|
1264
|
-
pow(n: number): Unit;
|
|
1265
|
-
/**
|
|
1266
|
-
* Convert to a target unit. Dimensions must match.
|
|
1267
|
-
*
|
|
1268
|
-
* @throws {DimensionMismatchError} if `targetNotation`'s dimensions differ
|
|
1269
|
-
* from this unit's.
|
|
1270
|
-
*/
|
|
1271
|
-
to(targetNotation: string): Unit;
|
|
1272
|
-
/**
|
|
1273
|
-
* Pick a unit (with SI prefix) that gives a magnitude closest to 1.
|
|
1274
|
-
*
|
|
1275
|
-
* Searches the unit registry for entries matching this unit's dimensions,
|
|
1276
|
-
* then applies each SI prefix in {@link BEST_PREFIXES} to find the
|
|
1277
|
-
* representation minimising `|log10(displayed value)|`.
|
|
1278
|
-
*
|
|
1279
|
-
* If no registered unit matches the dimensions, falls back to a synthetic
|
|
1280
|
-
* notation describing the dimensional vector.
|
|
1281
|
-
*/
|
|
1282
|
-
toBest(): Unit;
|
|
1283
|
-
/** True iff dimensions and canonical value are equal. */
|
|
1284
|
-
equals(other: Unit): boolean;
|
|
1285
|
-
/** True iff dimensions match (values may differ). */
|
|
1286
|
-
dimensionsEqual(other: Unit): boolean;
|
|
1287
|
-
/**
|
|
1288
|
-
* Pretty-print. If `notation` is set (the common case), display the value
|
|
1289
|
-
* in that notation — otherwise emit a dimensional signature.
|
|
1290
|
-
*/
|
|
1291
|
-
toString(): string;
|
|
1292
|
-
/** JSON-serialisable record. */
|
|
1293
|
-
toJSON(): {
|
|
1294
|
-
mathts: 'Unit';
|
|
1295
|
-
value: number;
|
|
1296
|
-
notation: string;
|
|
1297
|
-
};
|
|
1298
|
-
/**
|
|
1299
|
-
* Rehydrate from a JSON record produced by {@link toJSON}.
|
|
1300
|
-
*
|
|
1301
|
-
* @throws {UnitParseError} if `json.notation` cannot be parsed.
|
|
1302
|
-
*/
|
|
1303
|
-
static fromJSON(json: {
|
|
1304
|
-
value: number;
|
|
1305
|
-
notation: string;
|
|
1306
|
-
}): Unit;
|
|
1307
|
-
/**
|
|
1308
|
-
* Parse a full unit expression (with optional leading numeric coefficient).
|
|
1309
|
-
*
|
|
1310
|
-
* Example: `Unit.parse('5 km/h')`.
|
|
1311
|
-
*/
|
|
1312
|
-
static parse(input: string): Unit;
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1315
|
-
/**
|
|
1316
|
-
* Duck-typing guard for {@link Unit}. Mirrors the convention used by
|
|
1317
|
-
* {@link Complex}, {@link Fraction}, and {@link BigNumber}.
|
|
1318
|
-
*/
|
|
1319
|
-
declare function isUnit$1(value: unknown): value is Unit;
|
|
1320
|
-
|
|
1321
1347
|
/**
|
|
1322
1348
|
* SI prefixes for the Unit type.
|
|
1323
1349
|
*
|
|
@@ -1713,4 +1739,4 @@ declare const math: {
|
|
|
1713
1739
|
|
|
1714
1740
|
declare const VERSION = "0.1.0";
|
|
1715
1741
|
|
|
1716
|
-
export { ALL_UNITS, BASE_UNITS, BEST_PREFIXES, BIGNUMBER_E, BIGNUMBER_LN10, BIGNUMBER_LN2, BIGNUMBER_NEG_ONE, BIGNUMBER_ONE, BIGNUMBER_PI, BIGNUMBER_TEN, BIGNUMBER_ZERO, type BackendType, BigNumber, type BigNumberConfig, COMPLEX_NEG_ONE, COMPLEX_ONE, COMPLEX_ZERO, Complex, type ConversionDef, DEFAULT_CONFIG, DERIVED_UNITS, DIMENSIONLESS, DimensionMismatchError, type Dimensions, Dual, E, FRACTION_HALF, FRACTION_NEG_ONE, FRACTION_ONE, FRACTION_QUARTER, FRACTION_THIRD, FRACTION_ZERO, type FactoryDependencies, type FactoryFunction, type FactoryImport, Fraction, FunctionRegistry, I, type IBigNumber, type IComplex, type IFraction, type IMatrix, LN10, LN2, LOG10E, LOG2E, MATHTS_CONVERSIONS, MATHTS_TYPES, type MathTSConfig, type MathTSValue, type MatrixBackend, type MatrixDimensions, type NumericType, PHI, PI, type RoundingMode, SI_PREFIXES, SQRT1_2, SQRT2, type Scalar, TAU, type TypeDef, TypeRegistry, UNIT_ALIASES,
|
|
1742
|
+
export { ALL_UNITS, BASE_UNITS, BEST_PREFIXES, BIGNUMBER_E, BIGNUMBER_LN10, BIGNUMBER_LN2, BIGNUMBER_NEG_ONE, BIGNUMBER_ONE, BIGNUMBER_PI, BIGNUMBER_TEN, BIGNUMBER_ZERO, type BackendType, BigNumber, type BigNumberConfig, COMPLEX_NEG_ONE, COMPLEX_ONE, COMPLEX_ZERO, Complex, type ConversionDef, DEFAULT_CONFIG, DERIVED_UNITS, DIMENSIONLESS, DUAL_UNARY_RULES, DimensionMismatchError, type Dimensions, Dual, type DualUnaryRule, type DualUnaryRuleName, E, FRACTION_HALF, FRACTION_NEG_ONE, FRACTION_ONE, FRACTION_QUARTER, FRACTION_THIRD, FRACTION_ZERO, type FactoryDependencies, type FactoryFunction, type FactoryImport, Fraction, FunctionRegistry, I, type IBigNumber, type IComplex, type IFraction, type IMatrix, LN10, LN2, LOG10E, LOG2E, MATHTS_CONVERSIONS, MATHTS_TYPES, type MathTSConfig, type MathTSValue, type MatrixBackend, type MatrixDimensions, type NumericScalar, type NumericType, PHI, PI, type RoundingMode, SI_PREFIXES, SQRT1_2, SQRT2, type Scalar, TAU, type TypeDef, TypeRegistry, UNIT_ALIASES, type UnitDef, UnitParseError, VERSION, abs, addScalar, createFactory, createMathTSTyped, createTypedFunction, dim, divideScalar, equal, fix, getPrefix, getUnitDef, initTypedWasm, isArray, isBigInt, isBigNumber, isBoolean, isComplex, isDenseMatrix, isDual, isFraction, isFunction, isMatrix, isNull, isNumber, isNumeric, isObject, isSparseMatrix, isString, isTypedWasmAvailable, isUndefined, isUnit, math, mathTyped, multiplyScalar, number, pow, registerNativeTypes, registry, round, subtractScalar };
|