Implement UnitSum machinery
#656
Merged
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.
UnitSum<...>takes a bunch of input units, and produces the canonicaltype that represents their sum. Usually, this will be a unit, but it
could also be
Zero. Core tasks include:UnitSumPack<...>;The main subtlety has to do with when the overall unit completely
cancels out. The result is not-a-unit: it is equivalent to
Zero.When every individual group of unscaled units cancels out, then it's
very easy for us to actually return
Zero. But, philosophically, wehave avoided the implementation complexity of looking "extra hard" for
cancellation in cases such as
s * Hz, for example. Taking a similartack here means that we could produce a result like
(ft - 12 in),which is 0, but is not
Zero, and which would act really weird if weused it like a unit.
For now, I think the conservative approach is to make this a compiler
error. I really doubt there are true use cases for this. I plan to
simply tell users not to form any
Constantsum that adds to zero,regardless of whether or not the library would call it
Zero. We canchange this later if we come up with an elegant and simple formulation,
and/or if somebody provides a really compelling use case. But starting
out with this pathway means that we won't break any existing code, and
a future upgrade that would allow this would also not break any
existing code.
Helps #607.