( value: number, fromUnit: UnitExpression, toUnit: UnitExpression )
| 639 | } |
| 640 | |
| 641 | for (const sym of members) { |
| 642 | if (sym === rep) continue; |
| 643 | const e = result.get(sym)!; |
| 644 | const s = getUnitScale(sym)!; |
| 645 | magnitudeScale *= (s / repScale) ** e; |
| 646 | result.set(rep, result.get(rep)! + e); |
| 647 | result.delete(sym); |
| 648 | } |
| 649 | if (result.get(rep) === 0) result.delete(rep); |
| 650 | } |
| 651 | |
| 652 | return { factors: result, magnitudeScale }; |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * Rebuild a canonical `UnitExpression` from a factor map (symbol → exponent). |
| 657 | * |
| 658 | * Numerator factors (positive exponents) become a bare symbol, a `Power`, or |
| 659 | * a `Multiply`; denominator factors (negative exponents) go under a `Divide`. |
| 660 | * When there are only denominator factors, negative `Power` forms are emitted |
| 661 | * directly (matching what `quantityDivide`'s scalar/Quantity path produces), |
| 662 | * since a numeric `1` is not a valid unit symbol. |
| 663 | * |
| 664 | * Returns `null` for an empty map (fully cancelled → dimensionless). |
no test coverage detected