Skip to content

Conversation

@chiphogg
Copy link
Member

@chiphogg chiphogg commented Feb 3, 2026

The hardest part about adding and subtracting Constant instances is
that we need a unit type to represent this sum, and a readable,
automatically generated unit label to go along with it. The strategy is
to break this into two parts:

  1. UnitSumPack<...> will be the actual type to hold unit sum
    instances. End users will never form this directly. We will not
    bother validating weird edge cases for this, because we will assume
    that every instance the library forms is valid and well formed (at
    least two units, properly ordered, etc.).

  2. UnitSum<...> is the utility that takes multiple unit instances as
    inputs, and produces the canonical UnitSumPack<...> output. That
    means unpacking any inputs that are already UnitSumPack<...>;
    identifying unique "unscaled units"; collecting like terms;
    eliminating unscaled units that get "zeroed out"; putting what's left
    in the right order; and, handling cases where only 0 or 1 units are
    left.

This PR provides the first prong of this strategy. We make sure that,
given well formed UnitSumPack instances, the result has the right
magnitude, and right unit label.

Helps #607.

The hardest part about adding and subtracting `Constant` instances is
that we need a unit type to represent this sum, and a readable,
automatically generated unit label to go along with it.  The strategy is
to break this into two parts:

1. `UnitSumPack<...>` will be the actual type to hold unit sum
   instances.  End users will _never_ form this directly.  We will not
   bother validating weird edge cases for this, because we will assume
   that every instance the _library_ forms is valid and well formed (at
   least two units, properly ordered, etc.).

2. `UnitSum<...>` is the utility that takes multiple unit instances as
   inputs, and produces the canonical `UnitSumPack<...>` output.  That
   means unpacking any inputs that are already `UnitSumPack<...>`;
   identifying unique "unscaled units"; collecting like terms;
   eliminating unscaled units that get "zeroed out"; putting what's left
   in the right order; and, handling cases where only 0 or 1 units are
   left.

This PR provides the first prong of this strategy.  We make sure that,
given well formed `UnitSumPack` instances, the result has the right
magnitude, and right unit label.

Helps #607.
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