This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/51795] linear_congruential_engine doesn't work correctly
- From: "spoon.reloaded at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 27 Jan 2012 21:21:40 +0000
- Subject: [Bug libstdc++/51795] linear_congruential_engine doesn't work correctly
- Auto-submitted: auto-generated
- References: <bug-51795-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51795
--- Comment #19 from spoon.reloaded at gmail dot com 2012-01-27 21:21:40 UTC ---
Paulo, in response to your suggestion to simply do multiplication and modulo in
#7 and #8, I don't think that would work in general. The example I gave
happened to have m = a power of 2 (namely 2^31), and so the truncation that we
would get from integer overflow (whether by 2^32 if we use uint32_t or 2^64 if
we use uint64_t) does not affect the result. However, if we choose any other
number as a modulo (e.g. 2^31 - 1) and say we use uint32_t as the type, it will
not work:
(1103515245 * 1103527590 + 12345) % 2147483647 = 944465040
but in uint32_t arithmetic:
(1103515245 * 1103527590 + 12345) % (1 << 32) % 2147483647 = 377401576
This is why I think we still need something like the Schrage's algorithm