Update MersenneTwisterEngine template signature to match C++11 standard#14
Merged
9il merged 3 commits intolibmir:masterfrom Jan 7, 2017
Merged
Update MersenneTwisterEngine template signature to match C++11 standard#149il merged 3 commits intolibmir:masterfrom
9il merged 3 commits intolibmir:masterfrom
Conversation
This test checks the 10,000th variate generated from Mt19937_64 when seeded with the default seed 5489. See e.g. http://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine for spec on the expected 10,000th value.
This patch reworks the existing Mersenne Twister template parameters to match the names and types specified in the C++11 standard, replacing `Uint` with `UIntType` and `uint` with `size_t`. Besides bringing the design closer to the C++11 standard, these changes also reduce ambiguity: `Uint` as a type name is visually easy to confuse with `uint`, which can lead to typos and confusion about intentions. `UIntType` may be more verbose, but it is much clearer in meaning and intent. Ordering and placement of the parameters in the specific 32- and 64-bit instantiations of the template has been updated to match the standard.
In the C++11 standard the 'initialization multiplier' `f` is included as one of the template parameters, since the correct choice of value does not depend solely on the unsigned integer type used.
Contributor
Author
|
@9il I'm submitting this PR among other things because I think these changes will create an easier basis from which to address the issues raised in dlang/phobos#5011 (comment) (it means we can more easily make a direct comparison of behaviour to C++11 implementations). |
Member
|
Thanks @WebDrake ! |
Contributor
Author
|
You're welcome. Give me a few minutes and I'll write up an issue on the seeding/word size issue mentioned in the Phobos PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The original template signature diverges from the C++11 standard both in names and types of template parameters. While not producing a functional difference, matching the standard allows for a less ambiguous declaration and makes for easier adaptation on the part of users used to C++ code.
These patches also introduce the previously-missing "initialization multiplier" template parameter
f. Since the correct value for this parameter is not solely dependent on the unsigned integer type in use, the originalstatic ifwould not have covered all possible instantiations of the generator.Finally, a basic unittest has been added for
Mt19937_64both to validate the generator and ensure that its behaviour does not change as a result of these updates.