Skip to content

Conversation

@chiphogg
Copy link
Member

We update :quantity so that it simply asks for the right conversion,
and applies it. Then, now that we know that :quantity is using
operations, we can update :conversion_policy to use those operations
to check for overflow and truncation risk.

This lets us get rid of the :apply_rational_magnitude_to_integral,
:apply_magnitude, and :static_cast_checkers libraries, because we no
longer use them anywhere. However, we retain their test files, by
sticking a very short implementation (based on the new libraries) at the
top of each test file. This way, we still get value from all those old
test cases: they give us confidence that we executed the switch
correctly.

Fixes #349.

chiphogg added 3 commits July 20, 2025 17:37
We update `:quantity` so that it simply asks for the right conversion,
and applies it.  Then, now that we know that `:quantity` is using
operations, we can update `:conversion_policy` to use those operations
to check for overflow and truncation risk.

This lets us get rid of the `:apply_rational_magnitude_to_integral`,
`:apply_magnitude`, and `:static_cast_checkers` libraries, because we no
longer use them anywhere.  However, we retain their _test files_, by
sticking a very short implementation (based on the new libraries) at the
top of each test file.  This way, we still get value from all those old
test cases: they give us confidence that we executed the switch
correctly.

Fixes #349.
@chiphogg chiphogg marked this pull request as draft July 20, 2025 21:46
@chiphogg chiphogg marked this pull request as ready for review July 20, 2025 21:47
namespace detail {
namespace {

// `NewOverflowChecker<Op>::would_product_overflow(x)` checks whether the value `x` would exceed the
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a similar comment about these being from an older library? Obviously git history can be used to check that out, but that would explain the differing idiom for the unit tests (normally they have a corresponding library that they are testing).

Copy link
Member Author

Choose a reason for hiding this comment

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

Great point! These files would look really weird otherwise. Done.


namespace detail {

template <typename U, typename T>
Copy link
Member

Choose a reason for hiding this comment

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

Comment about the previous library implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@chiphogg chiphogg merged commit be01249 into main Jul 21, 2025
14 checks passed
@chiphogg chiphogg deleted the chiphogg/use-ops-to-convert#349 branch July 21, 2025 13:08
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.

Improve efficiency of explicit-rep overflow checkers

3 participants