From patchwork Wed Oct 24 12:23:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 193758 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 2C6972C0156 for ; Wed, 24 Oct 2012 23:24:16 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1351686257; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Message-ID:Date:From:User-Agent:MIME-Version: To:CC:Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=vbN63IbfNURrbFHpOr7Cb5DDSjc=; b=U5tV5qISMcII66p MUscXmS4SHf+BKqgTg7s+1YB3I6DwK56vw1GcdUMK6MGG5ECOLl5k5dEiA6W5Zng WFxA8fv4ZUWJ0EjIvBJlFqgLJfdUnJASeBz10gmD+Y6qgogAEGangW3r9AAwNS4e Tk0ju6kdXzcFCIL7WA3n6XKR+RC0= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=tY2GG33XPpZPq3VeIeEZ75vzJaMP8pB+GjWkBitD1aYnggzsuMNnOtaVpn3oup SRLx2t7JhWDFLX5Sn5u9teWZ2jVqc6AgF7Qfg+1U7G2BiwwLAPVckhG20jbouAqM 18S7Du1rcdEMIfiXUsJD89MZMfLf6GvHiTX2E5Xm9O4es=; Received: (qmail 11180 invoked by alias); 24 Oct 2012 12:24:06 -0000 Received: (qmail 11161 invoked by uid 22791); 24 Oct 2012 12:24:04 -0000 X-SWARE-Spam-Status: No, hits=-7.2 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rcsinet15.oracle.com (HELO rcsinet15.oracle.com) (148.87.113.117) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 24 Oct 2012 12:23:58 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by rcsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q9OCNulM004992 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 24 Oct 2012 12:23:57 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q9OCNt3r027876 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 24 Oct 2012 12:23:56 GMT Received: from abhmt116.oracle.com (abhmt116.oracle.com [141.146.116.68]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q9OCNteh013885; Wed, 24 Oct 2012 07:23:55 -0500 Received: from [192.168.1.4] (/79.52.211.59) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 24 Oct 2012 05:23:55 -0700 Message-ID: <5087DDD8.2020109@oracle.com> Date: Wed, 24 Oct 2012 14:23:52 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] libstdc++/55047 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 tested x86_64-linux multilib, committed to mainline. A similar fix will go in 4_7-branch too. Thanks, Paolo. //////////////////////// 2012-10-24 Haakan Younes Paolo Carlini PR libstdc++/55047 * include/bits/random.h (exponential_distribution<>::operator): Fix formula to std::log(result_type(1) - __aurng()). * include/bits/random.tcc: Likewise, everywhere. Index: include/bits/random.tcc =================================================================== --- include/bits/random.tcc (revision 192718) +++ include/bits/random.tcc (working copy) @@ -1,6 +1,6 @@ // random number generation (out of line) -*- C++ -*- -// Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc. +// Copyright (C) 2009-2012 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 @@ -1187,7 +1187,7 @@ double __cand; do - __cand = std::floor(std::log(__aurng()) / __param._M_log_1_p); + __cand = std::floor(std::log(1.0 - __aurng()) / __param._M_log_1_p); while (__cand >= __thr); return result_type(__cand + __naf); @@ -1217,7 +1217,8 @@ { double __cand; do - __cand = std::floor(std::log(__aurng()) / __param._M_log_1_p); + __cand = std::floor(std::log(1.0 - __aurng()) + / __param._M_log_1_p); while (__cand >= __thr); *__f++ = __cand + __naf; @@ -1464,7 +1465,7 @@ do { const double __u = __c * __aurng(); - const double __e = -std::log(__aurng()); + const double __e = -std::log(1.0 - __aurng()); double __w = 0.0; @@ -1496,7 +1497,7 @@ __x = 1; else { - const double __v = -std::log(__aurng()); + const double __v = -std::log(1.0 - __aurng()); const double __y = __param._M_d + __v * __2cx / __param._M_d; __x = std::ceil(__y); @@ -1655,7 +1656,7 @@ do { - const double __e = -std::log(__aurng()); + const double __e = -std::log(1.0 - __aurng()); __sum += __e / (__t - __x); __x += 1; } @@ -1723,7 +1724,7 @@ __reject = __y >= __param._M_d1; if (!__reject) { - const double __e = -std::log(__aurng()); + const double __e = -std::log(1.0 - __aurng()); __x = std::floor(__y); __v = -__e - __n * __n / 2 + __param._M_c; } @@ -1735,15 +1736,15 @@ __reject = __y >= __param._M_d2; if (!__reject) { - const double __e = -std::log(__aurng()); + const double __e = -std::log(1.0 - __aurng()); __x = std::floor(-__y); __v = -__e - __n * __n / 2; } } else if (__u <= __a123) { - const double __e1 = -std::log(__aurng()); - const double __e2 = -std::log(__aurng()); + const double __e1 = -std::log(1.0 - __aurng()); + const double __e2 = -std::log(1.0 - __aurng()); const double __y = __param._M_d1 + 2 * __s1s * __e1 / __param._M_d1; @@ -1754,8 +1755,8 @@ } else { - const double __e1 = -std::log(__aurng()); - const double __e2 = -std::log(__aurng()); + const double __e1 = -std::log(1.0 - __aurng()); + const double __e2 = -std::log(1.0 - __aurng()); const double __y = __param._M_d2 + 2 * __s2s * __e1 / __param._M_d2; @@ -1869,7 +1870,7 @@ __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> __aurng(__urng); while (__f != __t) - *__f++ = -std::log(__aurng()) / __p.lambda(); + *__f++ = -std::log(result_type(1) - __aurng()) / __p.lambda(); } template @@ -2628,7 +2629,7 @@ { __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> __aurng(__urng); - return __p.b() * std::pow(-std::log(__aurng()), + return __p.b() * std::pow(-std::log(result_type(1) - __aurng()), result_type(1) / __p.a()); } @@ -2644,10 +2645,11 @@ __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> __aurng(__urng); - auto inv_a = result_type(1) / __p.a(); + auto __inv_a = result_type(1) / __p.a(); while (__f != __t) - *__f++ = __p.b() * std::pow(-std::log(__aurng()), inv_a); + *__f++ = __p.b() * std::pow(-std::log(result_type(1) - __aurng()), + __inv_a); } template @@ -2704,7 +2706,8 @@ { __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> __aurng(__urng); - return __p.a() - __p.b() * std::log(-std::log(__aurng())); + return __p.a() - __p.b() * std::log(-std::log(result_type(1) + - __aurng())); } template @@ -2721,7 +2724,8 @@ __aurng(__urng); while (__f != __t) - *__f++ = __p.a() - __p.b() * std::log(-std::log(__aurng())); + *__f++ = __p.a() - __p.b() * std::log(-std::log(result_type(1) + - __aurng())); } template Index: include/bits/random.h =================================================================== --- include/bits/random.h (revision 192718) +++ include/bits/random.h (working copy) @@ -1,6 +1,6 @@ // random number generation -*- C++ -*- -// Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc. +// Copyright (C) 2009-2012 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 @@ -4748,7 +4748,7 @@ { __detail::_Adaptor<_UniformRandomNumberGenerator, result_type> __aurng(__urng); - return -std::log(__aurng()) / __p.lambda(); + return -std::log(result_type(1) - __aurng()) / __p.lambda(); } template