From patchwork Wed May 31 12:22:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 101408 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2839445vqr; Wed, 31 May 2023 05:27:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ABl+eRzv1vcZCLGpw2RHm768gkxEZd2r/Mn7s1MvsBvOtQLYZqAAda7czQwbkiYerA4s4 X-Received: by 2002:a17:907:d18:b0:96f:afe9:25c7 with SMTP id gn24-20020a1709070d1800b0096fafe925c7mr5006633ejc.10.1685536046825; Wed, 31 May 2023 05:27:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685536046; cv=none; d=google.com; s=arc-20160816; b=zM8I05dXsgFiV/4dEwv0dghbgEKRU8Uzr08pFyNdjlsf7FATal+QXIo57iwaPJAIBp 6r6Gj1FHQakRzIS1Hg9oBQHulpcIAN4eJjgkjv9WXOwr7vzO1Dr/rekLIJFo/qdC64So qaE0Z0N81WgWk2MKCwEitnOtK8Gq3kbTZP6IeMK7qeJSnii/XL+HVmC+go9jweTwZHoB kiKR/n/z06B0GUNtPHF4+EUlaNAXwg0kTkEuHio4ImeoC/8T7ej33TiOeKjHuMaT6+pv wgYxqQuGoMweL8mKuXWqQVAXYrbFF593Pu8hROUaDKaRLfDuXvuHH2GTYhcX9L5ONNKy XGWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=eQNq3/5q6/mJs86AWi5L6JqU6i23mfCu6M33XPjvUSQ=; b=vbXKJOC8U2ndHbAcR7UPYdQbSj+YhKuoi2YOmvN3Orvyv1DsxBrqkqGEyDf0HsJ//G 7MkqriXmzj1e2sYyXRrA/NDRMrTqa7SkBKqufmKNFhnN92mgidebaCVjr7COfBYDCdam RmGoObwEHzrNhQUS+dm4Y7xvLoEryjtidpe5nT4Fed7+dXYAaUmCFJYnOBx45KgUkpex yM4juZletStlL92LW3YPp3Uua4FbLLlUEBwDvPkKqzB/RtyvWQN/y1UoaDNGhZW3tcZB wjZ6ncRWLcE5hrad/c85g76S+K6BbQGmOOZMWi/T387c2vTigyEtRrKwxCQ0cG6aVDV2 XBTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yvhdp+gZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c18-20020a17090603d200b00965cb784a27si614830eja.699.2023.05.31.05.27.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 05:27:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yvhdp+gZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 88C1E383E8D0 for ; Wed, 31 May 2023 12:24:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88C1E383E8D0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685535869; bh=eQNq3/5q6/mJs86AWi5L6JqU6i23mfCu6M33XPjvUSQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=yvhdp+gZ+DPTvLjI4jZqsio6qhSpUG5ln/QiD/9fsf4aiYSYlS2uZWNju0u8toeq/ iBTP5aRg9sjCee1OPkYAG1GCENMMccIjgyt6WvbQDnZoL8DxaI/+hrsV8/fGzx3VeE WKxa5WeCmw1XsjswMjlIECAB8ATZs1RBDbCR1VAs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 6B7B63855896 for ; Wed, 31 May 2023 12:22:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B7B63855896 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-607-92yvOv5yMgWr7jUOeOPvCQ-1; Wed, 31 May 2023 08:22:42 -0400 X-MC-Unique: 92yvOv5yMgWr7jUOeOPvCQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AA97A1C06ED5; Wed, 31 May 2023 12:22:41 +0000 (UTC) Received: from localhost (unknown [10.42.28.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id 53EC9112132C; Wed, 31 May 2023 12:22:41 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add std::numeric_limits<__float128> specialization [PR104772] Date: Wed, 31 May 2023 13:22:39 +0100 Message-Id: <20230531122239.4116906-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767412645592242123?= X-GMAIL-MSGID: =?utf-8?q?1767412645592242123?= Tested powerpc64le-linux. Pushed to trunk. -- >8 -- As suggested by Jakub in the PR, this just hardcodes the constants with a Q suffix, since the properties of __float128 are not going to change. We can only define it for non-strict modes because the suffix gives an error otherwise, even in system headers: limits:2085: error: unable to find numeric literal operator 'operator""Q' libstdc++-v3/ChangeLog: PR libstdc++/104772 * include/std/limits (numeric_limits<__float128>): Define. * testsuite/18_support/numeric_limits/128bit.cc: New test. --- libstdc++-v3/include/std/limits | 75 +++++++++++++++++++ .../18_support/numeric_limits/128bit.cc | 12 +++ 2 files changed, 87 insertions(+) create mode 100644 libstdc++-v3/testsuite/18_support/numeric_limits/128bit.cc diff --git a/libstdc++-v3/include/std/limits b/libstdc++-v3/include/std/limits index 8bafd6fb972..5f341e63b93 100644 --- a/libstdc++-v3/include/std/limits +++ b/libstdc++-v3/include/std/limits @@ -2073,6 +2073,81 @@ __glibcxx_float_n(128) #endif +#if defined(_GLIBCXX_USE_FLOAT128) && !defined(__STRICT_ANSI__) + __extension__ + template<> + struct numeric_limits<__float128> + { + static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; + + static _GLIBCXX_CONSTEXPR __float128 + min() _GLIBCXX_USE_NOEXCEPT + { return __extension__ 3.36210314311209350626267781732175260e-4932Q; } + + static _GLIBCXX_CONSTEXPR __float128 + max() _GLIBCXX_USE_NOEXCEPT + { return __extension__ 1.18973149535723176508575932662800702e+4932Q; } + + static _GLIBCXX_CONSTEXPR __float128 + lowest() _GLIBCXX_USE_NOEXCEPT + { return -max(); } + + static _GLIBCXX_USE_CONSTEXPR int digits = 113; + static _GLIBCXX_USE_CONSTEXPR int digits10 = 33; + static _GLIBCXX_USE_CONSTEXPR int max_digits10 + = __glibcxx_max_digits10 (112); + static _GLIBCXX_USE_CONSTEXPR bool is_signed = true; + static _GLIBCXX_USE_CONSTEXPR bool is_integer = false; + static _GLIBCXX_USE_CONSTEXPR bool is_exact = false; + static _GLIBCXX_USE_CONSTEXPR int radix = __FLT_RADIX__; + + static _GLIBCXX_CONSTEXPR __float128 + epsilon() _GLIBCXX_USE_NOEXCEPT + { return __extension__ 1.92592994438723585305597794258492732e-34Q; } + + static _GLIBCXX_CONSTEXPR __float128 + round_error() _GLIBCXX_USE_NOEXCEPT { return __extension__ 0.5Q; } + + static _GLIBCXX_USE_CONSTEXPR int min_exponent = -16381; + static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = -4931; + static _GLIBCXX_USE_CONSTEXPR int max_exponent = 16384; + static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 4932; + + static _GLIBCXX_USE_CONSTEXPR bool has_infinity = 1; + static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = 1; + static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = has_quiet_NaN; + static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm + = denorm_present; + static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; + + static _GLIBCXX_CONSTEXPR __float128 + infinity() _GLIBCXX_USE_NOEXCEPT + { return __builtin_huge_valq(); } + + static _GLIBCXX_CONSTEXPR __float128 + quiet_NaN() _GLIBCXX_USE_NOEXCEPT + { return __builtin_nanq(""); } + + static _GLIBCXX_CONSTEXPR __float128 + signaling_NaN() _GLIBCXX_USE_NOEXCEPT + { return __builtin_nansq(""); } + + static _GLIBCXX_CONSTEXPR __float128 + denorm_min() _GLIBCXX_USE_NOEXCEPT + { return __extension__ 6.47517511943802511092443895822764655e-4966Q; } + + static _GLIBCXX_USE_CONSTEXPR bool is_iec559 + = has_infinity && has_quiet_NaN && has_denorm == denorm_present; + static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; + static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false; + + static _GLIBCXX_USE_CONSTEXPR bool traps = false; + static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; + static _GLIBCXX_USE_CONSTEXPR float_round_style round_style + = round_to_nearest; + }; +#endif // _GLIBCXX_USE_FLOAT128 && ! __STRICT_ANSI__ + _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/testsuite/18_support/numeric_limits/128bit.cc b/libstdc++-v3/testsuite/18_support/numeric_limits/128bit.cc new file mode 100644 index 00000000000..e8ea568df94 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/numeric_limits/128bit.cc @@ -0,0 +1,12 @@ +// { dg-do compile } + +#include + +#if __SIZEOF_FLOAT128__ && !defined __STRICT_ANSI__ +__extension__ template class std::numeric_limits<__float128>; +#endif + +#if __SIZEOF_INT128__ +__extension__ template class std::numeric_limits<__int128>; +__extension__ template class std::numeric_limits; +#endif