Check that every magnitude fits in its target type #211
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
get_value<T>(m)
converts a magnitudem
to its representation in typeT
. It produces a hard compiler error if the value can't fit. Itsrelative
get_value_result<T>(m)
always returns a result, but producesan error code if the value can't be represented.
Previously, there was a hole in this system. We assumed that each
magnitude could be represented in
std::uintmax_t
. Of course, if itcouldn't,
get_value
would fail to compile as it should. Butget_value_result
would also fail to compile, instead of producing anerror condition.
To fix this, we need to move our checking utilities further up in the
file, so that all of our utilities can use them.
product
,int_pow
,base_power_value
--- they all need to check their computations atevery step. When we do this, we're able to gracefully detect the
non-representability of huge numbers even for the biggest types.