added more testing of value_cast
conversion accuracy when using integral types
#579
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.
I had some doubts regarding the
number * val(num) / val(den) * val(irr)
computation path insudo_cast<Q>
, where I see two potential risks:* val(num)
)/ val(den) * val(irr)
may lead to more truncation than necessary (i.e. compared to* val(irr) / val(den)
), depending on the exact values there.However, so far, I was unable to find an actual edge case. Risk 1 seems to be mitigated through the use of
std::intmax_t
as the intermediate type of computation,. Risk 2 appears to be mitigated by selecting the other (floating-point) computation path whenever irrational factors are involved.So instead of a bug report, this is now just a PR containing the additional test-cases I used to verify that those issues are indeed not present. I believe there is value in keeping those in the code-base, in case the implementation of
sudo_cast
is touched for some reason or another in the future. For example,std::intmax_t
may be excessive if both input ant output representation are in fact quite small integers.