[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
Mon Mar 4 10:24:32 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;
----------------
mordante wrote:

To me `1ull << 32` is easier to parse. With `0x100000000ull` I need to count the zeros. (Since the code is used in C++11 we can't write `0x1'0000'0000ull`.) So personally I really like the shifted version better.

https://github.com/llvm/llvm-project/pull/81583


More information about the libcxx-commits mailing list