multprec.cpp
: Simplify with _Unsigned128
#5473
Merged
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.
Followup to #5436, which reimplemented
linear_congruential_engine
in<random>
by using our modern_Unsigned128
. This PR shrinks our separately compiled, now-retained-for-bincompatmultprec.cpp
by also using_Unsigned128
. Ordinarily we don't put a lot of effort into simplifying retained-for-bincompat code because the benefit is low and the risk is unnecessary. In this case, it's worth the risk because this fixes #1008 by removing squirrelly code that needed an/analyze
suppression. (Being/analyze
-clean is very important now, and keeping suppressions around in our codebase is a minor debt.)My new comments do a hopefully better job than before of explaining
_MP_arr
's representation, and the assumptions behind the various functions. I am aiming for simplicity here, not micro-optimizations; e.g._MP_Rem()
is computing modulo a 64-bit value, so only the lower 64 bits will be non-zero, but I'm still going through the generalassign_mp_from_u128()
helper function.Retained-for-bincompat code isn't something that we expend effort on testing (the idea is that we don't mess with it and it keeps working). In this case, I performed manual randomized testing. I wrote a test case to generate random values, subject to the conditions in
linear_congruential_engine
, and compared not only the ultimate output but also the intermediate_MP_arr
contents. I compared the new implementation (after building the STL and runningset_environment.bat
, of course) to a copy of the old classic implementation, for 12.8 billion trials, and everything agreed.Click to expand test case: