Add UnitSumPack, with labels
#654
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The hardest part about adding and subtracting
Constantinstances isthat we need a unit type to represent this sum, and a readable,
automatically generated unit label to go along with it. The strategy is
to break this into two parts:
UnitSumPack<...>will be the actual type to hold unit suminstances. End users will never form this directly. We will not
bother validating weird edge cases for this, because we will assume
that every instance the library forms is valid and well formed (at
least two units, properly ordered, etc.).
UnitSum<...>is the utility that takes multiple unit instances asinputs, and produces the canonical
UnitSumPack<...>output. Thatmeans unpacking any inputs that are already
UnitSumPack<...>;identifying unique "unscaled units"; collecting like terms;
eliminating unscaled units that get "zeroed out"; putting what's left
in the right order; and, handling cases where only 0 or 1 units are
left.
This PR provides the first prong of this strategy. We make sure that,
given well formed
UnitSumPackinstances, the result has the rightmagnitude, and right unit label.
Helps #607.