Support % for Constant inputs
#653
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.
Getting a correct answer was easy, thanks to the underlying support for
%inMagnitude. Just as withQuantity, we simply convert theinputs to their common unit, and then perform the usual
%operation onthose (necessarily integer) inputs.
The label was unexpectedly subtle. I wrote the tests in terms of my
human a priori expectations, which say, for example, that 40 inches mod
2 feet should get a label of
"[16 in]". Instead, the answer I got was"[2 EQUIV{[(2 / 3) ft], [8 in]}]"! Now, clearly this is equivalent,so the program was not "wrong"; the label was just strange and
inconvenient.
Ultimately, I realized that human readers will be looking at the
unscaled version of the units associated with each constant. So we
should start by finding the common unit of the unscaled input units.
We still perform the modulus in the common unit of the direct inputs,
as we must. But then we make the answer right by multiplying by the
ratio between these different common units. This way, the common
unscaled unit is what determines the label, and everything else is
just a simple multiplicative
Magnitudeapplied to it.Includes doc updates. Helps #607.