From patchwork Wed Jun 7 17:17:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 104634 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp357684vqr; Wed, 7 Jun 2023 10:18:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ71hInW7gSR7oZz6DtoOQiqeq+d/BOO915q5CaSKNSScXjbKVR1RBdaaEd941RY3gRWJWSc X-Received: by 2002:a17:906:9b96:b0:953:8249:1834 with SMTP id dd22-20020a1709069b9600b0095382491834mr7455523ejc.16.1686158293752; Wed, 07 Jun 2023 10:18:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686158293; cv=none; d=google.com; s=arc-20160816; b=kvr+sQo9Af9yqcigQikQIvIKOEZRFcxUG/McntWDtyiPACbWxdBU1ITT+AAjJIg51i SUboS0vdBG6njviK527ot2xctgokte6x9Cj6bZO5Oj72/lbkw1D1eWOQ7jz5oIxjrZq1 Om0LNYyuXT5M0CX6dNRTOninAWaG68v42WcEUOsd8cf1BTxzsUAnKL1vGlzLWgeFIZ7o OAFcd57sV4+QoXSiAP89f5K16zPY5TL1LtWjJN9OwM+raLiCXfV/D3XdBc2H9xF2MQk9 8ShMjtL3MQsTTciLFCWj7/1qIJawNLC52G1w/78ZJWm26Xcs9oi6lYNImGtFQGWmC3oK h57Q== 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-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=oRaSDPSPcPTXqjTSGq1EyQ+HPnya/UkSfcMjf9Uy1HI=; b=Euz3uRT/6fzo4XfPe9JcE/zI7BjJFnGCuD9gvxxgDZO7WPVU9456rYLbEuHD5uOVyr I79WdnXYUmNupsjuTOLiZiiQvTnUNXb+9gJ7qJ9Qpaw3b+1uxXtX6MbMPpQ28TiymHzc jz/Lxiq9Y9l4dAwSisDj3Zwtk+SmJAbWnKHj3q5R1sD4kYUMex76TxtMD3l/d7yOAnYz SFU9WkV3L1RQ1YrYTNipxMld/Dx31+KQRVHwW92ywU6QxaTNkXckG+TEm/thYKjGeAzT VWoTl4UUVkOVMnYv+5clt41Ftvjbx1me3EOSowEfwEltDSGVfSit9O2lNBl7YlEaCnwr 5iJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EyDohDZF; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g13-20020a1709067c4d00b0094f34d90a75si8448668ejp.437.2023.06.07.10.18.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 10:18:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EyDohDZF; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 E8B48385842C for ; Wed, 7 Jun 2023 17:17:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8B48385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686158274; bh=oRaSDPSPcPTXqjTSGq1EyQ+HPnya/UkSfcMjf9Uy1HI=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=EyDohDZFVMExFy7E8mC1kU/JFprplo/3xc27D4LbgbW21qV7/H/5fwO6ZMpoJmh1X rO9Gho1qEOXJoSj8Uq5T9wJ0BLvprwjE1zBFIc4bnNqGXo1mGtPzluqBKhAFtEGHf/ 6aYxM5WOw0HdcGAEHuQzy8h791uOO6eqO3MXk76c= 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 7CE0B3857702 for ; Wed, 7 Jun 2023 17:17:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CE0B3857702 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-83-kq68RZiXMhe7MuSRI3smNA-1; Wed, 07 Jun 2023 13:17:08 -0400 X-MC-Unique: kq68RZiXMhe7MuSRI3smNA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 376AB85A5A8; Wed, 7 Jun 2023 17:17:07 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EDFD0140E954; Wed, 7 Jun 2023 17:17:06 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 357HH4jg3600457 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 7 Jun 2023 19:17:05 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 357HH4ox3600456; Wed, 7 Jun 2023 19:17:04 +0200 Date: Wed, 7 Jun 2023 19:17:04 +0200 To: Jonathan Wakely Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Fix up 20_util/to_chars/double.cc test for excess precision [PR110145] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_LOTSOFHASH, 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek 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?1768065118898334781?= X-GMAIL-MSGID: =?utf-8?q?1768065118898334781?= Hi! This test apparently contains 3 problematic floating point constants, 1e126, 4.91e-6 and 5.547e-6. These constants suffer from double rounding when -fexcess-precision=standard evaluates double constants in the precision of Intel extended 80-bit long double. As written in the PR, e.g. the first one is 0x1.7a2ecc414a03f7ff6ca1cb527787b130a97d51e51202365p+418 in the precision of GCC's internal format, 80-bit long double has 63-bit precision, so the above constant rounded to long double is 0x1.7a2ecc414a03f800p+418L (the least significant bit in the 0 before p isn't there already). 0x1.7a2ecc414a03f800p+418L rounded to IEEE double is 0x1.7a2ecc414a040p+418. Now, if excess precision doesn't happen and we round the GCC's internal format number directly to double, it is 0x1.7a2ecc414a03fp+418 and that is the number the test expects. One can see it on x86-64 (where excess precision to long double doesn't happen) where double(1e126L) != 1e126. The other two constants suffer from the same problem. The following patch tweaks the testcase, such that those problematic constants are used only if FLT_EVAL_METHOD is 0 or 1 (i.e. when we have guarantee the constants will be evaluated in double precision), plus adds corresponding tests with hexadecimal constants which don't suffer from this excess precision problem, they are exact in double and long double can hold all double values. Bootstrapped/regtested on x86_64-linux and i686-linux, additionally tested on the latter with make check RUNTESTFLAGS='--target_board=unix/-fexcess-precision=standard conformance.exp=to_chars/double.cc' Ok for trunk? 2023-06-07 Jakub Jelinek PR libstdc++/110145 * testsuite/20_util/to_chars/double.cc: Include . (double_to_chars_test_cases, double_scientific_precision_to_chars_test_cases_2, double_fixed_precision_to_chars_test_cases_2): #if out 1e126, 4.91e-6 and 5.547e-6 tests if FLT_EVAL_METHOD is negative or larger than 1. Add unconditional tests with corresponding double constants 0x1.7a2ecc414a03fp+418, 0x1.4981285e98e79p-18 and 0x1.7440bbff418b9p-18. Jakub --- libstdc++-v3/testsuite/20_util/to_chars/double.cc.jj 2022-11-03 22:16:08.542329555 +0100 +++ libstdc++-v3/testsuite/20_util/to_chars/double.cc 2023-06-07 15:41:44.275604870 +0200 @@ -40,6 +40,7 @@ #include #include #include +#include #include @@ -1968,9 +1969,19 @@ inline constexpr double_to_chars_testcas {1e125, chars_format::fixed, "9999999999999999248677616189928820425446708698348384614392259722252941999757930266031634937628176537515300" "5841365553228283904"}, +#if FLT_EVAL_METHOD >= 0 && FLT_EVAL_METHOD <= 1 + // When long double is Intel extended and double constants are evaluated in precision of + // long double, this value is initialized to double(1e126L), which is 0x1.7a2ecc414a040p+418 due to + // double rounding of 0x1.7a2ecc414a03f7ff6p+418L first to 0x1.7a2ecc414a03f800p+418L and + // then to 0x1.7a2ecc414a040p+418, while when double constants are evaluated in precision of + // IEEE double, this is 0x1.7a2ecc414a03fp+418 which the test expects. See PR110145. {1e126, chars_format::fixed, "9999999999999999248677616189928820425446708698348384614392259722252941999757930266031634937628176537515300" "58413655532282839040"}, +#endif + {0x1.7a2ecc414a03fp+418, chars_format::fixed, + "9999999999999999248677616189928820425446708698348384614392259722252941999757930266031634937628176537515300" + "58413655532282839040"}, {1e127, chars_format::fixed, "9999999999999999549291066784979473595300225087383524118479625982517885450291174622154390152298057300868772" "377386949310916067328"}, @@ -2816,8 +2827,12 @@ inline constexpr double_to_chars_testcas {0x1.a6c767640cd71p+879, chars_format::scientific, "6.6564021122018745e+264"}, // Incorrectly handled by dtoa_milo() (Grisu2), which doesn't achieve shortest round-trip. +#if FLT_EVAL_METHOD >= 0 && FLT_EVAL_METHOD <= 1 {4.91e-6, chars_format::scientific, "4.91e-06"}, {5.547e-6, chars_format::scientific, "5.547e-06"}, +#endif + {0x1.4981285e98e79p-18, chars_format::scientific, "4.91e-06"}, + {0x1.7440bbff418b9p-18, chars_format::scientific, "5.547e-06"}, // Test hexfloat corner cases. {0x1.728p+0, chars_format::hex, "1.728p+0"}, // instead of "2.e5p-1" @@ -5537,10 +5552,16 @@ inline constexpr double_to_chars_testcas "9." "9999999999999992486776161899288204254467086983483846143922597222529419997579302660316349376281765375153005" "841365553228283904e+124"}, +#if FLT_EVAL_METHOD >= 0 && FLT_EVAL_METHOD <= 1 {1e+126, chars_format::scientific, 124, "9." "9999999999999992486776161899288204254467086983483846143922597222529419997579302660316349376281765375153005" "841365553228283904e+125"}, +#endif + {0x1.7a2ecc414a03fp+418, chars_format::scientific, 124, + "9." + "9999999999999992486776161899288204254467086983483846143922597222529419997579302660316349376281765375153005" + "841365553228283904e+125"}, {1e+127, chars_format::scientific, 126, "9." "9999999999999995492910667849794735953002250873835241184796259825178854502911746221543901522980573008687723" @@ -29579,9 +29600,14 @@ inline constexpr double_to_chars_testcas {1e+125, chars_format::fixed, 0, "9999999999999999248677616189928820425446708698348384614392259722252941999757930266031634937628176537515300" "5841365553228283904"}, +#if FLT_EVAL_METHOD >= 0 && FLT_EVAL_METHOD <= 1 {1e+126, chars_format::fixed, 0, "9999999999999999248677616189928820425446708698348384614392259722252941999757930266031634937628176537515300" "58413655532282839040"}, +#endif + {0x1.7a2ecc414a03fp+418, chars_format::fixed, 0, + "9999999999999999248677616189928820425446708698348384614392259722252941999757930266031634937628176537515300" + "58413655532282839040"}, {1e+127, chars_format::fixed, 0, "9999999999999999549291066784979473595300225087383524118479625982517885450291174622154390152298057300868772" "377386949310916067328"},