From patchwork Fri Aug 6 08:59:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 61094 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 74085B6F0D for ; Fri, 6 Aug 2010 20:18:34 +1000 (EST) Received: (qmail 21110 invoked by alias); 6 Aug 2010 10:18:32 -0000 Received: (qmail 21099 invoked by uid 22791); 6 Aug 2010 10:18:31 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY X-Spam-Check-By: sourceware.org Received: from rcsinet10.oracle.com (HELO rcsinet10.oracle.com) (148.87.113.121) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 06 Aug 2010 10:18:26 +0000 Received: from rcsinet15.oracle.com (rcsinet15.oracle.com [148.87.113.117]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id o76AINKP028414 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 6 Aug 2010 10:18:24 GMT Received: from acsmt355.oracle.com (acsmt355.oracle.com [141.146.40.155]) by rcsinet15.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id o76AIKMC002843 for ; Fri, 6 Aug 2010 10:18:21 GMT Received: from abhmt004.oracle.com by acsmt354.oracle.com with ESMTP id 490571311281085190; Fri, 06 Aug 2010 01:59:50 -0700 Received: from macbook-pro-di-paolo-carlini.local (/152.96.0.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 06 Aug 2010 01:59:50 -0700 Message-ID: <4C5BCF04.3010601@oracle.com> Date: Fri, 06 Aug 2010 10:59:48 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; it; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2 MIME-Version: 1.0 To: Gcc Patch List CC: libstdc++ Subject: [v3] Improve ratio_less 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, committed to mainline. Paolo. //////////// 2010-08-06 Paolo Carlini * include/std/ratio (ratio_less): Improve, use ratio_divide to avoid more overflows. * testsuite/20_util/ratio/comparisons/comp1.cc: Extend. * testsuite/20_util/ratio/comparisons/comp2.cc: Likewise. Index: testsuite/20_util/ratio/comparisons/comp1.cc =================================================================== --- testsuite/20_util/ratio/comparisons/comp1.cc (revision 162897) +++ testsuite/20_util/ratio/comparisons/comp1.cc (working copy) @@ -1,7 +1,7 @@ // { dg-options "-std=gnu++0x" } // { dg-require-cstdint "" } -// Copyright (C) 2008, 2009 Free Software Foundation +// Copyright (C) 2008, 2009, 2010 Free Software Foundation // // 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 @@ -45,7 +45,12 @@ VERIFY( (std::ratio_less, std::ratio<1,4>>::value == 0) ); VERIFY( (std::ratio_less, std::ratio<-1,3>>::value == 0) ); - + + VERIFY( (std::ratio_less, std::ratio<-1,4>>::value == 1) ); + VERIFY( (std::ratio_less, std::ratio<0,3>>::value == 0) ); + VERIFY( (std::ratio_less, std::ratio<0,3>>::value == 0) ); + VERIFY( (std::ratio_less, std::ratio<-1,4>>::value == 0) ); + VERIFY( (std::ratio_less_equal, std::ratio<-1,3>>::value == 1) ); VERIFY( ( std::ratio_less_equal, Index: testsuite/20_util/ratio/comparisons/comp2.cc =================================================================== --- testsuite/20_util/ratio/comparisons/comp2.cc (revision 162897) +++ testsuite/20_util/ratio/comparisons/comp2.cc (working copy) @@ -1,7 +1,7 @@ // { dg-options "-std=gnu++0x" } // { dg-require-cstdint "" } -// Copyright (C) 2008, 2009 Free Software Foundation +// Copyright (C) 2008, 2009, 2010 Free Software Foundation // // 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 @@ -41,6 +41,13 @@ VERIFY( (std::ratio_less, std::ratio<-M, M - 1>>::value == 0) ); + + // No overflow + VERIFY( (std::ratio_less, + std::ratio>::value == 1) ); + + VERIFY( (std::ratio_less, + std::ratio<-M, M - 2>>::value == 0) ); } int main() Index: include/std/ratio =================================================================== --- include/std/ratio (revision 162897) +++ include/std/ratio (working copy) @@ -233,23 +233,30 @@ struct ratio_not_equal : integral_constant::value> { }; - + + template + struct __ratio_less_impl_1 + : integral_constant + { }; + + template::value + != __static_sign<_R2::num>::value)), + bool = (__static_sign<_R1::num>::value == -1 + && __static_sign<_R2::num>::value == -1)> + struct __ratio_less_impl + : __ratio_less_impl_1::type>::type + { }; + template - struct __ratio_less_simple_impl - : integral_constant::value - < __safe_multiply<_R2::num, _R1::den>::value)> + struct __ratio_less_impl<_R1, _R2, true, false> + : integral_constant { }; - // If the denominators are equal or the signs differ, we can just compare - // numerators, otherwise fallback to the simple cross-multiply method. template - struct __ratio_less_impl - : conditional<(_R1::den == _R2::den - || (__static_sign<_R1::num>::value - != __static_sign<_R2::num>::value)), - integral_constant, - __ratio_less_simple_impl<_R1, _R2>>::type + struct __ratio_less_impl<_R1, _R2, false, true> + : __ratio_less_impl_1::type>::type { }; /// ratio_less