Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add labels for integer and rational magnitudes #331

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

chiphogg
Copy link
Contributor

Think of this as "just enough of #85 to unblock #105". The fact that
our common unit labels don't tell you the size of the unit (#105) has
really, really been bugging me for a long time. Recently, I realized we
don't need to do all of #85 to get it! Instead, all we need to do is:

  1. Build a mechanism that we can easily extend.

  2. Cover the most important use cases.

This PR creates the MagnitudeLabel trait mechanism (also accessible
via a function/value interface as mag_label). We enumerate the
various categories of magnitudes that we can label, defaulting to
"unsupported". The first two supported categories are integers (that
fit in std::uintmax_t), and rationals.

We also add a trait, has_exposed_slash, looking forward to the obvious
use case of auto-generating labels for scaled units. Those labels will
have the form "[M U]" for a unit of label "U" scaled by a magnitude
of label "M". If has_exposed_slash is true for a given magnitude
label, then we'll know to make this "[(M) U]" instead.

Finally, we move a couple of StringConstant-ish utilities into
"string_constant.hh", so that we can use them in our implementation.

Helps #85.

Think of this as "just enough of #85 to unblock #105".  The fact that
our common unit labels don't tell you the _size_ of the unit (#105) has
really, really been bugging me for a long time.  Recently, I realized we
don't need to do all of #85 to get it!  Instead, all we need to do is:

1. Build a _mechanism_ that we can easily _extend_.

2. Cover the most important use cases.

This PR creates the `MagnitudeLabel` trait mechanism (also accessible
via a function/value interface as `mag_label`).  We enumerate the
various categories of magnitudes that we can label, defaulting to
"unsupported".  The first two supported categories are _integers_ (that
fit in `std::uintmax_t`), and _rationals_.

We also add a trait, `has_exposed_slash`, looking forward to the obvious
use case of auto-generating labels for scaled units.  Those labels will
have the form `"[M U]"` for a unit of label `"U"` scaled by a magnitude
of label `"M"`.  If `has_exposed_slash` is `true` for a given magnitude
label, then we'll know to make this `"[(M) U]"` instead.

Finally, we move a couple of `StringConstant`-ish utilities into
`"string_constant.hh"`, so that we can use them in our implementation.

Helps #85.
@chiphogg chiphogg added the release notes: ✨ lib (enhancement) PR enhancing the library code label Nov 27, 2024
@chiphogg chiphogg requested a review from geoffviola November 27, 2024 19:25
Copy link
Contributor

@geoffviola geoffviola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation, tests and documentation looks good. Thanks!

@chiphogg chiphogg merged commit 28a7d8c into main Nov 29, 2024
13 checks passed
@chiphogg chiphogg deleted the chiphogg/mag-label-basics#85 branch November 29, 2024 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: ✨ lib (enhancement) PR enhancing the library code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants