[libcxx-commits] [libcxx] linear_congruential_engine: add using more precision to prevent overflow (PR #81583)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Feb 13 00:55:48 PST 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 0e16950e741aee7ffec865c81596e1411471475e fc0789f40cd1b413e684a1fbde5ee3136de3ee22 -- libcxx/include/__random/linear_congruential_engine.h libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/alg.pass.cpp libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/assign.pass.cpp libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/copy.pass.cpp libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/default.pass.cpp libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/include/__random/linear_congruential_engine.h b/libcxx/include/__random/linear_congruential_engine.h
index e32f0a9d05..26f3b820f7 100644
--- a/libcxx/include/__random/linear_congruential_engine.h
+++ b/libcxx/include/__random/linear_congruential_engine.h
@@ -30,10 +30,10 @@ template <unsigned long long __a,
unsigned long long __c,
unsigned long long __m,
unsigned long long _Mp,
- bool _HasOverflow = (__a != 0ull && (__m & (__m - 1ull)) != 0ull), // a != 0, m != 0, m != 2^n
- bool _Full = (!_HasOverflow || __m - 1ull <= (_Mp - __c) / __a), // (a * x + c) % m works
- bool _Part = (!_HasOverflow || __m - 1ull <= _Mp / __a), // (a * x) % m works
- bool _Schrage = (_HasOverflow && __m % __a <= __m / __a)> // r <= q
+ bool _HasOverflow = (__a != 0ull && (__m & (__m - 1ull)) != 0ull), // a != 0, m != 0, m != 2^n
+ bool _Full = (!_HasOverflow || __m - 1ull <= (_Mp - __c) / __a), // (a * x + c) % m works
+ bool _Part = (!_HasOverflow || __m - 1ull <= _Mp / __a), // (a * x) % m works
+ bool _Schrage = (_HasOverflow && __m % __a <= __m / __a)> // r <= q
struct __lce_alg_picker {
static _LIBCPP_CONSTEXPR const int __mode = _Full ? 0 : _Part ? 1 : _Schrage ? 2 : 3;
``````````
</details>
https://github.com/llvm/llvm-project/pull/81583
More information about the libcxx-commits
mailing list