]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/include/bits/random.tcc
libstdc++: Add assertions for preconditions in sampling distributions [PR 82584]
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / random.tcc
index f67b2fe48f44373f8d8a0848cecc8a99b20b06e8..a921b9bf815c9ee8f852ff0c06283d86178e4dc9 100644 (file)
@@ -2630,6 +2630,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       const double __sum = std::accumulate(_M_prob.begin(),
                                           _M_prob.end(), 0.0);
+      __glibcxx_assert(__sum > 0);
       // Now normalize the probabilites.
       __detail::__normalize(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
                            __sum);
@@ -2794,6 +2795,7 @@ namespace __detail
 
       const double __sum = std::accumulate(_M_den.begin(),
                                           _M_den.end(), 0.0);
+      __glibcxx_assert(__sum > 0);
 
       __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
                            __sum);
@@ -3016,6 +3018,7 @@ namespace __detail
          _M_cp.push_back(__sum);
          _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
        }
+      __glibcxx_assert(__sum > 0);
 
       //  Now normalize the densities...
       __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),