Skip to content

Conversation

@chiphogg
Copy link
Member

@chiphogg chiphogg commented Feb 3, 2026

Getting a correct answer was easy, thanks to the underlying support for
% in Magnitude. Just as with Quantity, we simply convert the
inputs to their common unit, and then perform the usual % operation on
those (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 Magnitude applied to it.

Includes doc updates. Helps #607.

chiphogg and others added 2 commits February 3, 2026 10:25
Getting a correct answer was easy, thanks to the underlying support for
`%` in `Magnitude`.  Just as with `Quantity`, we simply convert the
inputs to their common unit, and then perform the usual `%` operation on
those (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 `Magnitude` applied to it.

Includes doc updates.  Helps #607.
@chiphogg chiphogg merged commit 2a7ac86 into main Feb 3, 2026
27 checks passed
@chiphogg chiphogg deleted the chiphogg/mod-constant#607 branch February 3, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants