Skip to content

Conversation

@chiphogg
Copy link
Member

Formerly, in Quantity, we used a CompareUnderlyingValues helper,
and a UnitSign enum. The helper was responsible for taking two
identical Quantity types, and extracting their values. (We built
out this machinery to support negative units.)

Now, we refactor to use a new helper, SignAwareComparison. This
brings two simplifications and one generalization.

  • Simplification: stop doing the extraction in the helper; let the
    callers extract and pass the values. (This gives the helper just one
    responsibility: namely, take the unit sign into account when deciding
    which order to pass the parameters.)

  • Simplification: lose the enum; just use the new UnitSign trait.

  • Generalization: accept heterogeneous parameters.

This last change will allow us to detect when we are passing mixed
signed and unsigned integral arguments. Of course, this PR is a no-op
refactor, so we're not actually taking advantage of this yet. That will
come in a follow-on PR.

Helps #428.

Formerly, in `Quantity`, we used a `CompareUnderlyingValues` helper,
and a `UnitSign` enum.  The helper was responsible for taking two
_identical_ `Quantity` types, and extracting their values.  (We built
out this machinery to support negative units.)

Now, we refactor to use a new helper, `SignAwareComparison`.  This
brings two simplifications and one generalization.

- **Simplification:** stop doing the extraction in the helper; let the
  callers extract and pass the values.  (This gives the helper just one
  responsibility: namely, take the unit sign into account when deciding
  which order to pass the parameters.)

- **Simplification:** lose the enum; just use the new `UnitSign` trait.

- **Generalization:** accept _heterogeneous_ parameters.

This last change will allow us to detect when we are passing mixed
signed and unsigned integral arguments.  Of course, this PR is a no-op
refactor, so we're not actually taking advantage of this yet.  That will
come in a follow-on PR.
chiphogg and others added 2 commits May 20, 2025 12:08
Co-authored-by: Michael Hordijk <hordijk@aurora.tech>
@chiphogg chiphogg requested a review from hoffbrinkle May 20, 2025 16:12
@chiphogg chiphogg merged commit abf10ad into main May 21, 2025
15 checks passed
@chiphogg chiphogg deleted the chiphogg/compare-underlying-vals#428 branch May 21, 2025 20:23
chiphogg added a commit that referenced this pull request Aug 19, 2025
We did not mean to disable these in #432.  Maybe my excuse is that my
brain was already living in the glorious future where #122 is landed.
At any rate, thank goodness for those policy argument overloads!  This
would have been a much more complicated fix without them.

I tested this by uncommenting the "feeters" test case, and verifying
that it now produces a compiler error, as it should.  I also uncommented
the quantity point test case where we check inheriting the overflow
safety surface.

Fixes #516.
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.

3 participants