From patchwork Mon Mar 14 18:27:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 86793 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 86ADDB6F7C for ; Tue, 15 Mar 2011 05:27:18 +1100 (EST) Received: (qmail 28458 invoked by alias); 14 Mar 2011 18:27:16 -0000 Received: (qmail 28441 invoked by uid 22791); 14 Mar 2011 18:27:15 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from smtp204.alice.it (HELO smtp204.alice.it) (82.57.200.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 Mar 2011 18:27:07 +0000 Received: from [192.168.1.4] (79.43.213.253) by smtp204.alice.it (8.5.124.08) id 4D7E0F640008EC64; Mon, 14 Mar 2011 19:27:03 +0100 Message-ID: <4D7E5DF6.4090901@oracle.com> Date: Mon, 14 Mar 2011 19:27:02 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110221 SUSE/3.1.8 Thunderbird/3.1.8 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] libstdc++/48114 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, a couple of issues with the C++0x , very easy to fix but very serious from the user point of view: due to a stupid thinko of mine we have been computing the binomial distribution incorrectly for p > 0.5 + we had the TR1 != C++0x definition for the geometric_distribution. Both fixes applied to mainline and 4_6-branch, only the first one to 4_5-branch. Paolo. /////////////// 2011-03-14 Andrey Zholos PR libstdc++/48114 * include/bits/random.h (geometric_distribution): Correct formula in comment, per C++0x. (geometric_distribution<>::param_type::param_type(double)): Fix check. (geometric_distribution<>::param_type::_M_initialize): Store log(1 - p). * include/bits/random.tcc (geometric_distribution<>::operator()): Fix computation. (binomial_distribution<>::operator()): Likewise. Index: include/bits/random.tcc =================================================================== --- include/bits/random.tcc (revision 170943) +++ include/bits/random.tcc (working copy) @@ -1025,7 +1025,7 @@ double __cand; 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); return result_type(__cand + __naf); @@ -1434,7 +1434,7 @@ { result_type __ret; const _IntType __t = __param.t(); - const _IntType __p = __param.p(); + const double __p = __param.p(); const double __p12 = __p <= 0.5 ? __p : 1.0 - __p; __detail::_Adaptor<_UniformRandomNumberGenerator, double> __aurng(__urng); Index: include/bits/random.h =================================================================== --- include/bits/random.h (revision 170943) +++ include/bits/random.h (working copy) @@ -1,6 +1,6 @@ // random number generation -*- C++ -*- -// Copyright (C) 2009, 2010 Free Software Foundation, Inc. +// Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -3589,7 +3589,7 @@ * @brief A discrete geometric random number distribution. * * The formula for the geometric probability density function is - * @f$p(i|p) = (1 - p)p^{i-1}@f$ where @f$p@f$ is the parameter of the + * @f$p(i|p) = p(1 - p)^{i}@f$ where @f$p@f$ is the parameter of the * distribution. */ template @@ -3611,8 +3611,8 @@ param_type(double __p = 0.5) : _M_p(__p) { - _GLIBCXX_DEBUG_ASSERT((_M_p >= 0.0) - && (_M_p <= 1.0)); + _GLIBCXX_DEBUG_ASSERT((_M_p > 0.0) + && (_M_p < 1.0)); _M_initialize(); } @@ -3627,11 +3627,11 @@ private: void _M_initialize() - { _M_log_p = std::log(_M_p); } + { _M_log_1_p = std::log(1.0 - _M_p); } double _M_p; - double _M_log_p; + double _M_log_1_p; }; // constructors and member function