[libcxx-commits] [libcxx] linear_congruential_engine: add using more precision to prevent overflow (PR #81583)
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Apr 13 06:34:57 PDT 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, (1ull << 32), 0, (1ull << 63) + 1ull> E2;
E2 e2;
// make sure Schrage's algorithm is used (it would be 0s after the first otherwise)
- assert(e2() == (1ull << 32));
+ assert(e2() == 0x100000000ull);
----------------
mordante wrote:
Please keep the original code here; it's easier to mentally parse `1ull <<32` than counting the number of zero's in `0x100000000ull`.
https://github.com/llvm/llvm-project/pull/81583
More information about the libcxx-commits
mailing list