[libcxx-commits] [PATCH] D74997: [libc++] Bugfix to std::binomial_distribution<int>
Atmn Patel via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 21 16:02:31 PST 2020
atmnpatel created this revision.
atmnpatel added reviewers: ldionne, mclow.lists.
Herald added a reviewer: EricWF.
Herald added subscribers: libcxx-commits, dexonsmith.
Herald added a project: libc++.
The current implementation is not guaranteed to converge. This
adds a break condition where 0 is returned if it is impossible for
the method to converge. This should only affect extreme edge cases.
Fixes: https://bugs.llvm.org/show_bug.cgi?id=44847
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D74997
Files:
libcxx/include/random
Index: libcxx/include/random
===================================================================
--- libcxx/include/random
+++ libcxx/include/random
@@ -4048,10 +4048,12 @@
result_type __rd = __ru;
while (true)
{
+ bool __break = true;
if (__rd >= 1)
{
__pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1));
__u -= __pd;
+ __break = false;
if (__u < 0)
return __rd - 1;
}
@@ -4062,9 +4064,12 @@
{
__pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru;
__u -= __pu;
+ __break = false;
if (__u < 0)
return __ru;
}
+ if (__break)
+ return 0;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74997.246030.patch
Type: text/x-patch
Size: 782 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200222/19abcd18/attachment.bin>
More information about the libcxx-commits
mailing list