aurora-opensource/au

Permit integer division between quantities of quantity-equivalent units

chiphogg opened this issue · 0 comments

Integer division for quantity types has scary pitfalls (see: slides; video).

Initially, we always prevented integer division when quantities were involved.

We later realized that we had forgotten to handle divisions involving one quantity and one raw number, so we tried tightening the policy.
After surveying a bunch of use cases, we found a lot of places where the denominator was a raw integer number. And these actually seemed fine! So we refined our policy to only prevent cases where the denominator has units.

And now we have #248, and its code example suggests yet another carve-out. If we integer-divide two quantities, but their units are quantity-equivalent, then this should be completely fine. The integer-division problems for quantities come when we can independently adjust the units for one quantity, such that the actual numeric variable we're dividing by can become arbitrarily different. If the units are constrained to be equivalent, then this can't happen, and we're unlikely to violate users' intuition. But if we continue to prevent this, we'll also prevent legitimate use cases like the example in #248!

So let's add this carve-out to the policy.