Skip to content

Update MersenneTwisterEngine template signature to match C++11 standard#14

Merged
9il merged 3 commits intolibmir:masterfrom
WebDrake:mt-template-signature
Jan 7, 2017
Merged

Update MersenneTwisterEngine template signature to match C++11 standard#14
9il merged 3 commits intolibmir:masterfrom
WebDrake:mt-template-signature

Conversation

@WebDrake
Copy link
Contributor

@WebDrake WebDrake commented Jan 7, 2017

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 original static if would not have covered all possible instantiations of the generator.

Finally, a basic unittest has been added for Mt19937_64 both to validate the generator and ensure that its behaviour does not change as a result of these updates.

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.
@WebDrake
Copy link
Contributor Author

WebDrake commented Jan 7, 2017

@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).

@9il
Copy link
Member

9il commented Jan 7, 2017

Thanks @WebDrake !

@9il 9il merged commit 56472ef into libmir:master Jan 7, 2017
@WebDrake WebDrake deleted the mt-template-signature branch January 7, 2017 16:24
@WebDrake
Copy link
Contributor Author

WebDrake commented Jan 7, 2017

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.

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.

2 participants