[libcxx-commits] [libcxx] linear_congruential_engine: add using more precision to prevent overflow (PR #81583)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Mar 4 10:17:40 PST 2024
================
@@ -38,12 +38,12 @@ int main(int, char**)
// m might overflow. The overflow is not OK and result will be in bounds
// so we should use Schrage's algorithm
- typedef std::linear_congruential_engine<T, (1ull << 32), 0, (1ull << 63) + 1> E2;
+ typedef std::linear_congruential_engine<T, 0x100000000ull, 0, (1ull << 63) + 1ull> E2;
----------------
LRFLEW wrote:
No *specific* reason. Mostly, I was trying to make this code a little cleaner and consistent. I figured that the `(1ull << 63) - 0x1ffffffffull` I added a few lines down would be longer and less clear if written as `(1ull << 63) - (1ull << 33) + 1ull`, and if I'm writing the 31-bit hex literal there, then I might as well do it here as well. I don't mind changing this back if that's what's preferred, though.
https://github.com/llvm/llvm-project/pull/81583
More information about the libcxx-commits
mailing list