@danielsimonjr/mathts-core 0.16.0 → 0.17.0

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 CHANGED
@@ -17,6 +17,8 @@ export { addScalar, subtractScalar, multiplyScalar, divideScalar, pow, abs, fix,
17
17
  export type { NumericScalar } from './arithmetic/scalar.js';
18
18
  export { Unit, isUnit as isUnitValue, DimensionMismatchError, UnitParseError, DIMENSIONLESS, dim, } from './types/unit.js';
19
19
  export type { Dimensions, UnitDef, UnitInstance } from './types/unit.js';
20
+ export { UNIT_EXACT_SCALE, PI_EXACT_SCALE, decimalExactScale, exactScaleOf, binaryExactScale, ratioExactScale, multiplyExactScales, divideExactScales, powerExactScale, addExactScales, exactScalesEqual, exactScaleToNumber, formatExactScale, readScaleExpression, NAMED_SCALES, UNIT_ROWS, UNIT_ROW_ALIASES, namedExactScale, readUnitScale, getUnitRow, unitRowExactScale, unitRowValue, unitRowExactOffset, UNIT_PREFIX_SETS, unitPrefixExactScale, getUnitPrefix, } from './types/unit.js';
21
+ export type { ExactScale, UnitRow, UnitBaseKey, UnitPrefixSetKey, UnitPrefix, } from './types/unit.js';
20
22
  export { UNIT_DIMENSION_LENGTH, SI_DIMENSION_LENGTH, toSiDimensions, toSiDimensionVector, fromSiDimensions, fromSiDimensionVector, } from './types/unit.js';
21
23
  export type { SiDimensionVector, SiDimensionOptions } from './types/unit.js';
22
24
  export { BASE_UNITS, DERIVED_UNITS, ALL_UNITS, UNIT_ALIASES, getUnitDef, } from './types/unit-definitions.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,YAAY,EACV,WAAW,EACX,MAAM,EACN,WAAW,EACX,WAAW,EACX,aAAa,EACb,OAAO,EACP,QAAQ,EACR,SAAS,EACT,UAAU,EACV,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAG/B,OAA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AAMjF,OAAO,EAEL,SAAS,EACT,iBAAiB,EACjB,KAAK,EACL,MAAM,EACN,mBAAmB,EACnB,YAAY,EAGZ,YAAY,EACZ,kBAAkB,EAGlB,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,UAAU,EACV,QAAQ,EACR,MAAM,EACN,WAAW,EAGX,QAAQ,EACR,aAAa,EACb,cAAc,EAGd,MAAM,EAGN,aAAa,EACb,oBAAoB,EAGpB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,aAAa,EACb,aAAa,EACb,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAM1B,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,cAAc,GACf,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAW5B,eAAO,MAAM,OAAO,EAAE,MAAwB,CAAC;AAI/C,OAAO,EACL,WAAW,EACX,WAAW,EACX,KAAK,EACL,WAAW,EACX,cAAc,EACd,cAAc,EACd,oBAAoB,GACrB,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -21,15 +21,31 @@ import {
21
21
  FRACTION_ZERO,
22
22
  Fraction,
23
23
  I,
24
+ NAMED_SCALES,
25
+ PI_EXACT_SCALE,
26
+ UNIT_EXACT_SCALE,
27
+ UNIT_PREFIX_SETS,
28
+ UNIT_ROWS,
29
+ UNIT_ROW_ALIASES,
24
30
  Unit,
25
31
  UnitParseError,
26
32
  abs,
33
+ addExactScales,
27
34
  addScalar,
35
+ binaryExactScale,
36
+ decimalExactScale,
37
+ divideExactScales,
28
38
  divideScalar,
29
39
  equal,
40
+ exactScaleOf,
41
+ exactScaleToNumber,
42
+ exactScalesEqual,
30
43
  factory,
31
44
  fix,
32
45
  format,
46
+ formatExactScale,
47
+ getUnitPrefix,
48
+ getUnitRow,
33
49
  isBigInt,
34
50
  isBigNumber,
35
51
  isBigNumber2,
@@ -37,14 +53,24 @@ import {
37
53
  isFraction2 as isFraction,
38
54
  isNumeric,
39
55
  isUnit,
56
+ multiplyExactScales,
40
57
  multiplyScalar,
58
+ namedExactScale,
41
59
  nearlyEqual,
42
60
  number,
43
61
  pow,
62
+ powerExactScale,
63
+ ratioExactScale,
64
+ readScaleExpression,
65
+ readUnitScale,
44
66
  round,
45
67
  sign,
46
- subtractScalar
47
- } from "./chunk-MBKU4LYX.js";
68
+ subtractScalar,
69
+ unitPrefixExactScale,
70
+ unitRowExactOffset,
71
+ unitRowExactScale,
72
+ unitRowValue
73
+ } from "./chunk-YS7US6LQ.js";
48
74
 
49
75
  // src/types/matrix/Range.ts
50
76
  var name = "Range";
@@ -530,116 +556,99 @@ var BASE_UNITS = {
530
556
  mol: { multiplier: 1, dimensions: dim({ amount: 1 }), prefixable: true },
531
557
  cd: { multiplier: 1, dimensions: dim({ luminosity: 1 }), prefixable: true }
532
558
  };
559
+ function tableUnit(name2, dimensions, prefixable) {
560
+ const row = getUnitRow(name2);
561
+ if (row === void 0) throw new Error(`unit-definitions: '${name2}' is not in the unit table`);
562
+ const scale = readUnitScale(row.scale);
563
+ const def = { multiplier: exactScaleToNumber(scale), dimensions };
564
+ if (row.offset !== void 0) {
565
+ def.offset = exactScaleToNumber(multiplyExactScales(scale, readUnitScale(row.offset)));
566
+ }
567
+ if (prefixable) def.prefixable = true;
568
+ return def;
569
+ }
533
570
  var DERIVED_UNITS = {
534
571
  // --- Length ---------------------------------------------------------------
535
572
  // Note: 'm' is a base unit (above), already prefixable.
536
- ft: { multiplier: 0.3048, dimensions: dim({ length: 1 }) },
537
- foot: { multiplier: 0.3048, dimensions: dim({ length: 1 }) },
538
- in: { multiplier: 0.0254, dimensions: dim({ length: 1 }) },
539
- inch: { multiplier: 0.0254, dimensions: dim({ length: 1 }) },
540
- yd: { multiplier: 0.9144, dimensions: dim({ length: 1 }) },
541
- yard: { multiplier: 0.9144, dimensions: dim({ length: 1 }) },
542
- mi: { multiplier: 1609.344, dimensions: dim({ length: 1 }) },
543
- mile: { multiplier: 1609.344, dimensions: dim({ length: 1 }) },
573
+ ft: tableUnit("ft", dim({ length: 1 })),
574
+ foot: tableUnit("foot", dim({ length: 1 })),
575
+ in: tableUnit("in", dim({ length: 1 })),
576
+ inch: tableUnit("inch", dim({ length: 1 })),
577
+ yd: tableUnit("yd", dim({ length: 1 })),
578
+ yard: tableUnit("yard", dim({ length: 1 })),
579
+ mi: tableUnit("mi", dim({ length: 1 })),
580
+ mile: tableUnit("mile", dim({ length: 1 })),
544
581
  // --- Mass -----------------------------------------------------------------
545
582
  // The "g" entry is gram (0.001 kg). It is prefixable, so kg/mg/µg work via
546
583
  // prefix application on this entry rather than the base "kg".
547
- g: { multiplier: 1e-3, dimensions: dim({ mass: 1 }), prefixable: true },
548
- lb: { multiplier: 0.45359237, dimensions: dim({ mass: 1 }) },
549
- lbm: { multiplier: 0.45359237, dimensions: dim({ mass: 1 }) },
550
- oz: { multiplier: 0.028349523125, dimensions: dim({ mass: 1 }) },
551
- ton: { multiplier: 907.18474, dimensions: dim({ mass: 1 }) },
584
+ g: tableUnit("g", dim({ mass: 1 }), true),
585
+ lb: tableUnit("lb", dim({ mass: 1 })),
586
+ lbm: tableUnit("lbm", dim({ mass: 1 })),
587
+ oz: tableUnit("oz", dim({ mass: 1 })),
588
+ ton: tableUnit("ton", dim({ mass: 1 })),
552
589
  // US short ton
553
- tonne: { multiplier: 1e3, dimensions: dim({ mass: 1 }) },
590
+ tonne: tableUnit("tonne", dim({ mass: 1 })),
554
591
  // metric ton
555
592
  // --- Time -----------------------------------------------------------------
556
- min: { multiplier: 60, dimensions: dim({ time: 1 }) },
557
- h: { multiplier: 3600, dimensions: dim({ time: 1 }) },
558
- hr: { multiplier: 3600, dimensions: dim({ time: 1 }) },
559
- day: { multiplier: 86400, dimensions: dim({ time: 1 }) },
560
- week: { multiplier: 604800, dimensions: dim({ time: 1 }) },
561
- year: { multiplier: 31557600, dimensions: dim({ time: 1 }) },
593
+ min: tableUnit("min", dim({ time: 1 })),
594
+ h: tableUnit("h", dim({ time: 1 })),
595
+ hr: tableUnit("hr", dim({ time: 1 })),
596
+ day: tableUnit("day", dim({ time: 1 })),
597
+ week: tableUnit("week", dim({ time: 1 })),
598
+ year: tableUnit("year", dim({ time: 1 })),
562
599
  // Julian year
563
600
  // --- Temperature ----------------------------------------------------------
564
601
  // K is the base.
565
602
  // °C → K is offset by 273.15 (no multiplicative factor change).
566
603
  // °F → K is more complex (offset & scale).
567
- degC: { multiplier: 1, offset: 273.15, dimensions: dim({ temperature: 1 }) },
568
- degF: { multiplier: 5 / 9, offset: 459.67 * (5 / 9), dimensions: dim({ temperature: 1 }) },
569
- degR: { multiplier: 5 / 9, dimensions: dim({ temperature: 1 }) },
604
+ degC: tableUnit("degC", dim({ temperature: 1 })),
605
+ degF: tableUnit("degF", dim({ temperature: 1 })),
606
+ degR: tableUnit("degR", dim({ temperature: 1 })),
570
607
  // Rankine
571
608
  // --- Plane angle (dimensionless, but often treated as units) --------------
572
- rad: { multiplier: 1, dimensions: dim({}), prefixable: true },
573
- deg: { multiplier: Math.PI / 180, dimensions: dim({}) },
574
- grad: { multiplier: Math.PI / 200, dimensions: dim({}) },
609
+ rad: tableUnit("rad", dim({}), true),
610
+ deg: tableUnit("deg", dim({})),
611
+ grad: tableUnit("grad", dim({})),
575
612
  // --- Force ----------------------------------------------------------------
576
613
  // N = kg·m·s^-2 = 1 kg·m·s^-2; in our base-units representation that's
577
614
  // value=1, dim {length: 1, mass: 1, time: -2}.
578
- N: { multiplier: 1, dimensions: dim({ length: 1, mass: 1, time: -2 }), prefixable: true },
579
- dyn: { multiplier: 1e-5, dimensions: dim({ length: 1, mass: 1, time: -2 }) },
580
- lbf: { multiplier: 4.4482216152605, dimensions: dim({ length: 1, mass: 1, time: -2 }) },
615
+ N: tableUnit("N", dim({ length: 1, mass: 1, time: -2 }), true),
616
+ dyn: tableUnit("dyn", dim({ length: 1, mass: 1, time: -2 })),
617
+ lbf: tableUnit("lbf", dim({ length: 1, mass: 1, time: -2 })),
581
618
  // --- Energy ---------------------------------------------------------------
582
- J: { multiplier: 1, dimensions: dim({ length: 2, mass: 1, time: -2 }), prefixable: true },
583
- erg: { multiplier: 1e-7, dimensions: dim({ length: 2, mass: 1, time: -2 }) },
584
- cal: { multiplier: 4.184, dimensions: dim({ length: 2, mass: 1, time: -2 }) },
585
- eV: {
586
- multiplier: 1602176634e-28,
587
- dimensions: dim({ length: 2, mass: 1, time: -2 }),
588
- prefixable: true
589
- },
590
- BTU: { multiplier: 1055.05585262, dimensions: dim({ length: 2, mass: 1, time: -2 }) },
619
+ J: tableUnit("J", dim({ length: 2, mass: 1, time: -2 }), true),
620
+ erg: tableUnit("erg", dim({ length: 2, mass: 1, time: -2 })),
621
+ cal: tableUnit("cal", dim({ length: 2, mass: 1, time: -2 })),
622
+ eV: tableUnit("eV", dim({ length: 2, mass: 1, time: -2 }), true),
623
+ BTU: tableUnit("BTU", dim({ length: 2, mass: 1, time: -2 })),
591
624
  // --- Power ----------------------------------------------------------------
592
- W: { multiplier: 1, dimensions: dim({ length: 2, mass: 1, time: -3 }), prefixable: true },
593
- hp: { multiplier: 745.6998715822702, dimensions: dim({ length: 2, mass: 1, time: -3 }) },
625
+ W: tableUnit("W", dim({ length: 2, mass: 1, time: -3 }), true),
626
+ hp: tableUnit("hp", dim({ length: 2, mass: 1, time: -3 })),
594
627
  // --- Pressure -------------------------------------------------------------
595
- Pa: { multiplier: 1, dimensions: dim({ length: -1, mass: 1, time: -2 }), prefixable: true },
596
- bar: { multiplier: 1e5, dimensions: dim({ length: -1, mass: 1, time: -2 }), prefixable: true },
597
- atm: { multiplier: 101325, dimensions: dim({ length: -1, mass: 1, time: -2 }) },
598
- psi: { multiplier: 6894.757293168361, dimensions: dim({ length: -1, mass: 1, time: -2 }) },
599
- torr: { multiplier: 133.322368421, dimensions: dim({ length: -1, mass: 1, time: -2 }) },
600
- mmHg: { multiplier: 133.322387415, dimensions: dim({ length: -1, mass: 1, time: -2 }) },
628
+ Pa: tableUnit("Pa", dim({ length: -1, mass: 1, time: -2 }), true),
629
+ bar: tableUnit("bar", dim({ length: -1, mass: 1, time: -2 }), true),
630
+ atm: tableUnit("atm", dim({ length: -1, mass: 1, time: -2 })),
631
+ psi: tableUnit("psi", dim({ length: -1, mass: 1, time: -2 })),
632
+ torr: tableUnit("torr", dim({ length: -1, mass: 1, time: -2 })),
633
+ mmHg: tableUnit("mmHg", dim({ length: -1, mass: 1, time: -2 })),
601
634
  // --- Electric -------------------------------------------------------------
602
- C: {
603
- multiplier: 1,
604
- dimensions: dim({ time: 1, current: 1 }),
605
- prefixable: true
606
- },
607
- V: {
608
- multiplier: 1,
609
- dimensions: dim({ length: 2, mass: 1, time: -3, current: -1 }),
610
- prefixable: true
611
- },
612
- ohm: {
613
- multiplier: 1,
614
- dimensions: dim({ length: 2, mass: 1, time: -3, current: -2 }),
615
- prefixable: true
616
- },
617
- \u03A9: {
618
- multiplier: 1,
619
- dimensions: dim({ length: 2, mass: 1, time: -3, current: -2 }),
620
- prefixable: true
621
- },
622
- F: {
623
- multiplier: 1,
624
- dimensions: dim({ length: -2, mass: -1, time: 4, current: 2 }),
625
- prefixable: true
626
- },
627
- H: {
628
- multiplier: 1,
629
- dimensions: dim({ length: 2, mass: 1, time: -2, current: -2 }),
630
- prefixable: true
631
- },
635
+ C: tableUnit("C", dim({ time: 1, current: 1 }), true),
636
+ V: tableUnit("V", dim({ length: 2, mass: 1, time: -3, current: -1 }), true),
637
+ ohm: tableUnit("ohm", dim({ length: 2, mass: 1, time: -3, current: -2 }), true),
638
+ \u03A9: tableUnit("ohm", dim({ length: 2, mass: 1, time: -3, current: -2 }), true),
639
+ F: tableUnit("F", dim({ length: -2, mass: -1, time: 4, current: 2 }), true),
640
+ H: tableUnit("H", dim({ length: 2, mass: 1, time: -2, current: -2 }), true),
632
641
  // --- Frequency ------------------------------------------------------------
633
- Hz: { multiplier: 1, dimensions: dim({ time: -1 }), prefixable: true },
642
+ Hz: tableUnit("Hz", dim({ time: -1 }), true),
634
643
  // --- Volume ---------------------------------------------------------------
635
- L: { multiplier: 1e-3, dimensions: dim({ length: 3 }), prefixable: true },
636
- l: { multiplier: 1e-3, dimensions: dim({ length: 3 }), prefixable: true },
637
- gal: { multiplier: 0.003785411784, dimensions: dim({ length: 3 }) },
644
+ L: tableUnit("L", dim({ length: 3 }), true),
645
+ l: tableUnit("l", dim({ length: 3 }), true),
646
+ gal: tableUnit("gal", dim({ length: 3 })),
638
647
  // US gallon
639
648
  // --- Area -----------------------------------------------------------------
640
- ha: { multiplier: 1e4, dimensions: dim({ length: 2 }) },
649
+ ha: tableUnit("hectare", dim({ length: 2 })),
641
650
  // hectare
642
- acre: { multiplier: 4046.8564224, dimensions: dim({ length: 2 }) }
651
+ acre: tableUnit("acre", dim({ length: 2 }))
643
652
  };
644
653
  var ALL_UNITS = { ...BASE_UNITS, ...DERIVED_UNITS };
645
654
  var UNIT_ALIASES = {
@@ -741,52 +750,16 @@ function fromSiDimensionVector(vector) {
741
750
  }
742
751
 
743
752
  // src/types/unit-prefixes.ts
744
- var SI_PREFIXES = {
745
- // Positive powers of ten
746
- Y: 1e24,
747
- // yotta
748
- Z: 1e21,
749
- // zetta
750
- E: 1e18,
751
- // exa
752
- P: 1e15,
753
- // peta
754
- T: 1e12,
755
- // tera
756
- G: 1e9,
757
- // giga
758
- M: 1e6,
759
- // mega
760
- k: 1e3,
761
- // kilo
762
- h: 100,
763
- // hecto
764
- da: 10,
765
- // deka (two-letter)
766
- // Negative powers of ten
767
- d: 0.1,
768
- // deci
769
- c: 0.01,
770
- // centi
771
- m: 1e-3,
772
- // milli
773
- u: 1e-6,
774
- // micro (ASCII fallback)
775
- \u00B5: 1e-6,
776
- // micro (Unicode)
777
- n: 1e-9,
778
- // nano
779
- p: 1e-12,
780
- // pico
781
- f: 1e-15,
782
- // femto
783
- a: 1e-18,
784
- // atto
785
- z: 1e-21,
786
- // zepto
787
- y: 1e-24
788
- // yocto
789
- };
753
+ var SI_PREFIXES = (() => {
754
+ const prefixes = {};
755
+ const short = UNIT_PREFIX_SETS.SHORT;
756
+ for (const name2 of Object.keys(short)) {
757
+ if (name2 === "") continue;
758
+ prefixes[name2] = exactScaleToNumber(unitPrefixExactScale(short[name2]));
759
+ }
760
+ prefixes["\xB5"] = prefixes.u;
761
+ return prefixes;
762
+ })();
790
763
  var BEST_PREFIXES = [
791
764
  "Y",
792
765
  "Z",
@@ -1473,7 +1446,7 @@ function neumaierCumsum(xs, out) {
1473
1446
  }
1474
1447
 
1475
1448
  // src/index.ts
1476
- var VERSION = "0.16.0";
1449
+ var VERSION = "0.17.0";
1477
1450
  export {
1478
1451
  ALL_UNITS,
1479
1452
  BASE_UNITS,
@@ -1513,8 +1486,10 @@ export {
1513
1486
  LOG2E,
1514
1487
  MATHTS_CONVERSIONS,
1515
1488
  MATHTS_TYPES,
1489
+ NAMED_SCALES,
1516
1490
  PHI,
1517
1491
  PI,
1492
+ PI_EXACT_SCALE,
1518
1493
  Range,
1519
1494
  SI_DIMENSION_LENGTH,
1520
1495
  SI_PREFIXES,
@@ -1524,24 +1499,38 @@ export {
1524
1499
  TypeRegistry,
1525
1500
  UNIT_ALIASES,
1526
1501
  UNIT_DIMENSION_LENGTH,
1502
+ UNIT_EXACT_SCALE,
1503
+ UNIT_PREFIX_SETS,
1504
+ UNIT_ROWS,
1505
+ UNIT_ROW_ALIASES,
1527
1506
  Unit,
1528
1507
  UnitParseError,
1529
1508
  VERSION,
1530
1509
  abs,
1510
+ addExactScales,
1531
1511
  addScalar,
1512
+ binaryExactScale,
1532
1513
  create,
1533
1514
  createFactory,
1534
1515
  createMathTSTyped,
1535
1516
  createRangeClass,
1536
1517
  createTypedFunction,
1518
+ decimalExactScale,
1537
1519
  dim,
1520
+ divideExactScales,
1538
1521
  divideScalar,
1539
1522
  equal,
1523
+ exactScaleOf,
1524
+ exactScaleToNumber,
1525
+ exactScalesEqual,
1540
1526
  fix,
1527
+ formatExactScale,
1541
1528
  fromSiDimensionVector,
1542
1529
  fromSiDimensions,
1543
1530
  getPrefix,
1544
1531
  getUnitDef,
1532
+ getUnitPrefix,
1533
+ getUnitRow,
1545
1534
  initTypedWasm,
1546
1535
  isArray,
1547
1536
  isBigInt2 as isBigInt,
@@ -1565,7 +1554,9 @@ export {
1565
1554
  isUnit as isUnitValue,
1566
1555
  math,
1567
1556
  mathTyped,
1557
+ multiplyExactScales,
1568
1558
  multiplyScalar,
1559
+ namedExactScale,
1569
1560
  neumaierCumsum,
1570
1561
  neumaierSum,
1571
1562
  norm2,
@@ -1573,6 +1564,10 @@ export {
1573
1564
  pairwiseDot,
1574
1565
  pairwiseSum,
1575
1566
  pow,
1567
+ powerExactScale,
1568
+ ratioExactScale,
1569
+ readScaleExpression,
1570
+ readUnitScale,
1576
1571
  registerNativeTypes,
1577
1572
  registry,
1578
1573
  round,
@@ -1581,5 +1576,9 @@ export {
1581
1576
  sumSquaredDeviations,
1582
1577
  toSiDimensionVector,
1583
1578
  toSiDimensions,
1584
- typed
1579
+ typed,
1580
+ unitPrefixExactScale,
1581
+ unitRowExactOffset,
1582
+ unitRowExactScale,
1583
+ unitRowValue
1585
1584
  };
package/dist/internal.js CHANGED
@@ -78,7 +78,7 @@ import {
78
78
  typeOf,
79
79
  unitDependencies,
80
80
  warnOnce
81
- } from "./chunk-MBKU4LYX.js";
81
+ } from "./chunk-YS7US6LQ.js";
82
82
 
83
83
  // src/error/DimensionError.ts
84
84
  var DimensionError = class _DimensionError extends RangeError {
@@ -1 +1 @@
1
- {"version":3,"file":"Unit.d.ts","sourceRoot":"","sources":["../../../src/types/unit/Unit.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAcV,eAAe,EAQhB,MAAM,iBAAiB,CAAC;AAkCzB,eAAO,MAAM,eAAe,6DAgvH3B,CAAC"}
1
+ {"version":3,"file":"Unit.d.ts","sourceRoot":"","sources":["../../../src/types/unit/Unit.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAcV,eAAe,EAQhB,MAAM,iBAAiB,CAAC;AAoGzB,eAAO,MAAM,eAAe,6DA67E3B,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Exact unit scales.
3
+ *
4
+ * A unit's scale to SI is a rational number times an integer power of π:
5
+ * `num / den × π^pi`. Products, quotients and integer powers stay exact, so a
6
+ * scale is rounded to a double once, at the end, by {@link exactScaleToNumber}.
7
+ * `psi` stated as `lbf/inch^2` is therefore the double nearest
8
+ * 0.45359237 × 9.80665 / 0.0254², not the result of three rounded float steps.
9
+ *
10
+ * A decimal literal (`'0.0254'`, `'1.602176634e-19'`) is read digit for digit.
11
+ * A JavaScript number is read through its shortest round-trip decimal
12
+ * (`String(x)`), which is the literal it was written as.
13
+ *
14
+ * Scale expressions (the form the unit table states its rows in) are factors
15
+ * joined by `*`, optionally followed by one `/` and the denominator's factors.
16
+ * Each factor is a decimal literal, `pi`, or a named scale, with an optional
17
+ * integer power `^n`. Everything after the first `/` is the denominator
18
+ * (ISO 80000-1 single-solidus reading): `a/b*c` is a/(b·c).
19
+ *
20
+ * @module @danielsimonjr/mathts-core/types/unit/exact-scale
21
+ */
22
+ /** `num / den × π^pi`, with `den > 0`, the fraction in lowest terms, and `pi` an integer. */
23
+ export interface ExactScale {
24
+ readonly num: bigint;
25
+ readonly den: bigint;
26
+ /** The integer power of π (1 for `deg = pi/180`, -1 for the parsec, 0 for a rational scale). */
27
+ readonly pi: number;
28
+ }
29
+ /** The scale 1. */
30
+ export declare const UNIT_EXACT_SCALE: ExactScale;
31
+ /** π itself, as a scale. */
32
+ export declare const PI_EXACT_SCALE: ExactScale;
33
+ /** The exact value of a decimal literal, or null when `text` is not one. */
34
+ export declare function decimalExactScale(text: string): ExactScale | null;
35
+ /** The exact decimal a finite JavaScript number prints as (its shortest round-trip form). */
36
+ export declare function exactScaleOf(x: number): ExactScale;
37
+ /**
38
+ * The exact binary value of a finite double (`0.1` is 3602879701896397 / 2^55).
39
+ * This is the value a computed double holds, where {@link exactScaleOf} reads
40
+ * the decimal a typed number was meant as.
41
+ */
42
+ export declare function binaryExactScale(x: number): ExactScale;
43
+ /** `num / den`, exactly. */
44
+ export declare function ratioExactScale(num: number | bigint, den?: number | bigint): ExactScale;
45
+ /** `a × b × …`. */
46
+ export declare function multiplyExactScales(...factors: readonly ExactScale[]): ExactScale;
47
+ /** `a / b`. */
48
+ export declare function divideExactScales(a: ExactScale, b: ExactScale): ExactScale;
49
+ /** `a ^ n` for an integer `n`. A fractional power has no exact form and throws. */
50
+ export declare function powerExactScale(a: ExactScale, n: number): ExactScale;
51
+ /** Whether two exact scales are the same number. */
52
+ export declare function exactScalesEqual(a: ExactScale, b: ExactScale): boolean;
53
+ /** `a + b`, when both carry the same power of π; null otherwise (π is transcendental). */
54
+ export declare function addExactScales(a: ExactScale, b: ExactScale): ExactScale | null;
55
+ /** The scale as a double, rounded once. */
56
+ export declare function exactScaleToNumber(s: ExactScale): number;
57
+ /** The scale as text: `num/den`, with `*pi^k` when π is a factor. For messages and tests. */
58
+ export declare function formatExactScale(s: ExactScale): string;
59
+ /**
60
+ * The exact value of a scale expression (`'lbf/inch^2'`, `'648000*astronomical_unit/pi'`,
61
+ * `'101325/760'`). `resolve` gives a name its scale and returns undefined for a
62
+ * name it does not know, which throws here. `pi` always means π.
63
+ */
64
+ export declare function readScaleExpression(text: string, resolve?: (name: string) => ExactScale | undefined): ExactScale;
65
+ //# sourceMappingURL=exact-scale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exact-scale.d.ts","sourceRoot":"","sources":["../../../src/types/unit/exact-scale.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,6FAA6F;AAC7F,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAA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AAC,EAAE,UAAU,GAAG,MAAM,CAItD;AAID;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,GAAG,SAA2B,GAClE,UAAU,CAsBZ"}
@@ -2,6 +2,10 @@ import type { UnitConstructor } from './unit-types.js';
2
2
  export { createUnitClass } from './Unit.js';
3
3
  export { unitDependencies } from './dependencies.js';
4
4
  export type * from './unit-types.js';
5
+ export { UNIT_EXACT_SCALE, PI_EXACT_SCALE, decimalExactScale, exactScaleOf, binaryExactScale, ratioExactScale, multiplyExactScales, divideExactScales, powerExactScale, addExactScales, exactScalesEqual, exactScaleToNumber, formatExactScale, readScaleExpression, } from './exact-scale.js';
6
+ export type { ExactScale } from './exact-scale.js';
7
+ export { NAMED_SCALES, UNIT_ROWS, UNIT_ROW_ALIASES, namedExactScale, readUnitScale, getUnitRow, unitRowExactScale, unitRowValue, unitRowExactOffset, UNIT_PREFIX_SETS, unitPrefixExactScale, getUnitPrefix, } from './unit-table.js';
8
+ export type { UnitRow, UnitBaseKey, UnitPrefixSetKey, UnitPrefix } from './unit-table.js';
5
9
  /** The core `Unit` class, pre-wired to core's numeric primitives. */
6
10
  export declare const Unit: UnitConstructor;
7
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/unit/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,mBAAmB,iBAAiB,CAAC;AAErC,qEAAqE;AACrE,eAAO,MAAM,IAAI,EAAE,eAEC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/unit/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,mBAAmB,iBAAiB,CAAC;AACrC,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EACL,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE1F,qEAAqE;AACrE,eAAO,MAAM,IAAI,EAAE,eAEC,CAAC"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * The built-in unit table: one row per unit, each stating its scale to SI as an
3
+ * exact expression, plus the aliases that copy a row under another name.
4
+ *
5
+ * This is the only place a built-in unit's size is written. `Unit` builds its
6
+ * `UNITS` from these rows, the flat registry in `unit-definitions.ts` reads its
7
+ * multipliers from them, and every row's double is the exact scale rounded
8
+ * once (`exact-scale.ts`). A unit defined in terms of others says so
9
+ * (`psi: 'lbf/inch^2'`, `hp: '550*foot*lbf'`), so no hand-rounded literal can
10
+ * drift from its definition.
11
+ *
12
+ * Scale expressions: factors joined by `*`, optionally `/` and the
13
+ * denominator's factors (everything after the first `/` is the denominator);
14
+ * each factor is a decimal literal, `pi`, or a name in {@link NAMED_SCALES},
15
+ * with an optional integer power `^n`.
16
+ *
17
+ * Sources: the SI Brochure (9th ed., 2019); NIST SP 811 (2008) Appendix B and
18
+ * NIST SP 330 (2019); the International Yard and Pound Agreement (1959);
19
+ * IAU 2012 Resolution B2 (astronomical unit) and IAU 2015 Resolution B2
20
+ * (parsec); the Fifth International Conference on the Properties of Steam
21
+ * (1956) for the International Table calorie.
22
+ *
23
+ * @module @danielsimonjr/mathts-core/types/unit/unit-table
24
+ */
25
+ import { type ExactScale } from './exact-scale.js';
26
+ /** The base-dimension keys a row may name (the `BASE_UNITS` of the Unit class). */
27
+ export type UnitBaseKey = 'MASS' | 'LENGTH' | 'TIME' | 'CURRENT' | 'TEMPERATURE' | 'LUMINOUS_INTENSITY' | 'AMOUNT_OF_SUBSTANCE' | 'FORCE' | 'SURFACE' | 'VOLUME' | 'ENERGY' | 'POWER' | 'PRESSURE' | 'ELECTRIC_CHARGE' | 'ELECTRIC_CAPACITANCE' | 'ELECTRIC_POTENTIAL' | 'ELECTRIC_RESISTANCE' | 'ELECTRIC_INDUCTANCE' | 'ELECTRIC_CONDUCTANCE' | 'MAGNETIC_FLUX' | 'MAGNETIC_FLUX_DENSITY' | 'FREQUENCY' | 'ANGLE' | 'BIT' | 'SOLID_ANGLE';
28
+ /** The prefix-set keys a row may name (the `PREFIXES` of the Unit class). */
29
+ export type UnitPrefixSetKey = 'NONE' | 'SHORT' | 'LONG' | 'SHORTLONG' | 'SQUARED' | 'CUBIC' | 'BINARY_SHORT' | 'BINARY_LONG' | 'BTU' | 'SHORT_UP_ONLY';
30
+ /** One built-in unit. */
31
+ export interface UnitRow {
32
+ /** The base dimension. */
33
+ readonly base: UnitBaseKey;
34
+ /** The prefixes the unit takes. */
35
+ readonly prefixes: UnitPrefixSetKey;
36
+ /** The exact scale to SI, as a scale expression. */
37
+ readonly scale: string;
38
+ /** Additive offset in the unit's own degrees, for an affine scale: SI = (x + offset) × scale. */
39
+ readonly offset?: string;
40
+ /** The unit's display name, when it differs from its key. */
41
+ readonly name?: string;
42
+ /** Prefer this unit in the reciprocal of its base (Hz for 1/s). */
43
+ readonly reciprocal?: true;
44
+ /** The value is the imaginary unit times the scale (reactive power, VAR). */
45
+ readonly imaginary?: true;
46
+ }
47
+ /** One prefix: the factor `radix^power`, and whether `toBest` may pick it. */
48
+ export interface UnitPrefix {
49
+ /** 10 for an SI prefix, 1024 for an IEC binary prefix. */
50
+ readonly radix: 10 | 1024;
51
+ /** The power of the radix. */
52
+ readonly power: number;
53
+ /** Whether automatic prefix selection may use it (false for da, h, d, c). */
54
+ readonly scientific: boolean;
55
+ }
56
+ type PrefixSet = Readonly<Record<string, UnitPrefix>>;
57
+ /**
58
+ * The prefix sets a row's `prefixes` names, each prefix stated as `radix^power`.
59
+ * `SQUARED` and `CUBIC` are the SI prefixes applied to an area or volume unit
60
+ * (cm² = 10⁻⁴ m²). The binary sets are the SI prefixes from kilo to yotta
61
+ * plus the IEC prefixes; `SHORT_UP_ONLY` (ly, pc) is the SI prefixes from k up.
62
+ */
63
+ export declare const UNIT_PREFIX_SETS: Readonly<Record<UnitPrefixSetKey, PrefixSet>>;
64
+ /** The exact factor of a prefix (`radix^power`). */
65
+ export declare function unitPrefixExactScale(prefix: UnitPrefix): ExactScale;
66
+ /**
67
+ * The prefix `name` in the set a built-in unit takes, or undefined when the
68
+ * unit is unknown or does not take that prefix. `''` is the unprefixed unit.
69
+ */
70
+ export declare function getUnitPrefix(unit: string, name: string): UnitPrefix | undefined;
71
+ /**
72
+ * Named exact scales the rows share. Each is a defining value or follows from
73
+ * named ones, so a derived unit cites its definition instead of a decimal.
74
+ */
75
+ export declare const NAMED_SCALES: Readonly<Record<string, string>>;
76
+ /** The built-in units, keyed by the name a unit text spells. */
77
+ export declare const UNIT_ROWS: Readonly<Record<string, UnitRow>>;
78
+ /**
79
+ * Further spellings of a row (plurals, long names, symbols). Each copies the
80
+ * row it names, so it has that row's scale, dimension and prefixes.
81
+ */
82
+ export declare const UNIT_ROW_ALIASES: Readonly<Record<string, string>>;
83
+ /** The exact value of a name in {@link NAMED_SCALES}, or undefined for an unknown name. */
84
+ export declare function namedExactScale(name: string): ExactScale | undefined;
85
+ /** The exact value of a scale expression over {@link NAMED_SCALES}. */
86
+ export declare function readUnitScale(expression: string): ExactScale;
87
+ /** The table row a built-in name or alias spells, or undefined. */
88
+ export declare function getUnitRow(name: string): UnitRow | undefined;
89
+ /** The exact scale of a built-in unit name or alias (no prefix), or undefined. */
90
+ export declare function unitRowExactScale(name: string): ExactScale | undefined;
91
+ /** The double a built-in unit's scale rounds to, or undefined for an unknown name. */
92
+ export declare function unitRowValue(name: string): number | undefined;
93
+ /**
94
+ * The additive offset of a built-in affine unit, exactly, in the unit's own
95
+ * degrees: SI = (x + offset) × scale (`degF`: 459.67, `degC`: 273.15). Zero
96
+ * for a unit with no offset; undefined for an unknown name.
97
+ */
98
+ export declare function unitRowExactOffset(name: string): ExactScale | undefined;
99
+ export {};
100
+ //# sourceMappingURL=unit-table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unit-table.d.ts","sourceRoot":"","sources":["../../../src/types/unit/unit-table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EACL,KAAK,UAAU,EAKhB,MAAM,kBAAkB,CAAC;AAE1B,mFAAmF;AACnF,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,QAAQ,GACR,MAAM,GACN,SAAS,GACT,aAAa,GACb,oBAAoB,GACpB,qBAAqB,GACrB,OAAO,GACP,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,UAAU,GACV,iBAAiB,GACjB,sBAAsB,GACtB,oBAAoB,GACpB,qBAAqB,GACrB,qBAAqB,GACrB,sBAAsB,GACtB,eAAe,GACf,uBAAuB,GACvB,WAAW,GACX,OAAO,GACP,KAAK,GACL,aAAa,CAAC;AAElB,6EAA6E;AAC7E,MAAM,MAAM,gBAAgB,GACxB,M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