From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17327 invoked by alias); 14 Mar 2011 15:23:37 -0000 Received: (qmail 17315 invoked by uid 22791); 14 Mar 2011 15:23:36 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 Mar 2011 15:23:32 +0000 From: "aaz at althenia dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/48114] binomial_distribution incorrect for p > .5 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: aaz at althenia dot net X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: paolo.carlini at oracle dot com X-Bugzilla-Target-Milestone: 4.5.3 X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Mon, 14 Mar 2011 15:23:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-03/txt/msg01413.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48114 --- Comment #3 from Andrey Zholos 2011-03-14 15:23:25 UTC --- I'll add this here since it's in the same place and the test will be similar. For geometric_distribution(.25) the first 10 probabilities are: sample correct p_0 0.000 0.250 p_1 0.750 0.188 p_2 0.187 0.141 p_3 0.046 0.105 p_4 0.012 0.079 p_5 0.003 0.059 p_6 0.001 0.044 p_7 0.000 0.033 p_8 0.000 0.025 p_9 0.000 0.019 The smallest value returned is 1, but should be 0 (and d.min() is correctly 0); and p is used as 1-p. Fix: --- include/c++/bits/random.h +++ include/c++/bits/random.h @@ -3628,8 +3628,8 @@ void _M_initialize() - { _M_log_p = std::log(_M_p); } + { _M_log_1_p = std::log(1 - _M_p); } double _M_p; - double _M_log_p; + double _M_log_1_p; }; --- include/c++/bits/random.tcc +++ include/c++/bits/random.tcc @@ -1027,3 +1027,3 @@ do - __cand = std::ceil(std::log(__aurng()) / __param._M_log_p); + __cand = std::floor(std::log(__aurng()) / __param._M_log_1_p); while (__cand >= __thr); Also, there's a line in random.h _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) && (_M_p <= 1.0)); but the standard only requires 0 < p < 1.