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

Rename Magnitude numerator/denominator traits #83

Closed
chiphogg opened this issue Feb 4, 2023 · 0 comments · Fixed by #138
Closed

Rename Magnitude numerator/denominator traits #83

chiphogg opened this issue Feb 4, 2023 · 0 comments · Fixed by #138
Labels
⬇️ affects: code (interfaces) Affects the way end users will interact with the library 📁 kind: cleanup Making the library nicer in some way, without affecting functionality much or at all 💪 effort: small
Milestone

Comments

@chiphogg
Copy link
Contributor

chiphogg commented Feb 4, 2023

numerator(m) gives the integer part of the numerator. This is counterintuitive. It should instead correspond to "the parts that a human would put on top of the fraction". Similar reasoning applies to denominator(m).

To fill the role played by the current versions of numerator and denominator, we can either make "integer"-named versions, or a generic integer_part(m) function which can compose with them.

@chiphogg chiphogg added 📁 kind: bug Something isn't working correctly, or there's a mistake 📁 kind: cleanup Making the library nicer in some way, without affecting functionality much or at all and removed 📁 kind: bug Something isn't working correctly, or there's a mistake labels Feb 4, 2023
@chiphogg chiphogg added ⬇️ affects: code (interfaces) Affects the way end users will interact with the library 💪 effort: small labels Mar 26, 2023
chiphogg added a commit that referenced this issue Jun 19, 2023
The current definitions of numerator and denominator assume we're
talking about the integer part only.  This policy is error-prone and
unclear from the callsite.  It also holds us back from automatically
generating labels for `Magnitude<...>` types, which would improve basic
library usability significantly at the margins.

Of course, we need the current definitions, which is why we added them
in the first place.  To continue meeting our needs, we add a new trait
operation: `integer_part(m)`.  This is equivalent to the old behaviour
of `numerator(m)`: it pulls out the _integer part_ of the numerator of
`m`.  But it frees up `numerator(m)` for a more natural interpretation.

On the implementation side, I took the opportunity to replace a
recursive implementation with one which is expanded inline, which may be
slightly more efficient.  This new approach exposed a bug in our
parameter pack handling: apparently, the unary product only actually
worked for single-element packs.  I added a test to expose this and
made the test pass.

I also grepped for `numerator`, `NumeratorT`, `denominator`, and
`DenominatorT`, to make sure we updated all of our old uses.  This
grepping caught a use case which we can't currently test for: rational
exponents (#116).  There _is_ a commented-out test case here, in the
`sqrt.CanConvertIfConversionFactorRational` case from `//au:math_test`,
which is commented out because it currently fails to compile.  (Note
that even if we had missed this update, it still wouldn't have compiled
because of a safeguard in `magnitude.hh`.)  In any case, I did find and
update this use case, which will save a little work in case we ever
attempt #116.

Testing plan:
- [x] New unit tests
- [x] Grepped existing uses
- [ ] Compile time impact measurements

Fixes #83.
chiphogg added a commit that referenced this issue Jun 20, 2023
The current definitions of numerator and denominator assume we're
talking about the integer part only.  This policy is error-prone and
unclear from the callsite.  It also holds us back from automatically
generating labels for `Magnitude<...>` types, which would improve basic
library usability significantly at the margins.

Of course, we need the current definitions, which is why we added them
in the first place.  To continue meeting our needs, we add a new trait
operation: `integer_part(m)`.  This is equivalent to the old behaviour
of `numerator(m)`: it pulls out the _integer part_ of the numerator of
`m`.  But it frees up `numerator(m)` for a more natural interpretation.

On the implementation side, I took the opportunity to replace a
recursive implementation with one which is expanded inline, which may be
slightly more efficient.  This new approach exposed a bug in our
parameter pack handling: apparently, the unary product only actually
worked for single-element packs.  I added a test to expose this and made
the test pass.

I also grepped for `numerator`, `NumeratorT`, `denominator`, and
`DenominatorT`, to make sure we updated all of our old uses.  This
grepping caught a use case which we can't currently test for: rational
exponents (#116).  There _is_ a commented-out test case here, in the
`sqrt.CanConvertIfConversionFactorRational` case from `//au:math_test`,
which is commented out because it currently fails to compile.  (Note
that even if we had missed this update, it still wouldn't have compiled
because of a safeguard in `magnitude.hh`.)  In any case, I did find and
update this use case, which will save a little work in case we ever
attempt #116.

Testing plan:
- [x] New unit tests
- [x] Grepped existing uses
- [x] Compile time impact measurements

Fixes #83.
@chiphogg chiphogg added this to the 0.3.3 milestone Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⬇️ affects: code (interfaces) Affects the way end users will interact with the library 📁 kind: cleanup Making the library nicer in some way, without affecting functionality much or at all 💪 effort: small
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant