From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 62DBA385842E for ; Tue, 16 Nov 2021 00:25:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 62DBA385842E Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-326-heHwH2JgOZaeTGK3QcUisw-1; Mon, 15 Nov 2021 19:25:19 -0500 X-MC-Unique: heHwH2JgOZaeTGK3QcUisw-1 Received: by mail-qt1-f198.google.com with SMTP id y25-20020ac87059000000b002a71d24c242so14631735qtm.0 for ; Mon, 15 Nov 2021 16:25:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E318mzVmnKdBe78N3Tnsl73pfiG8c7f0KoyeIOlyKiI=; b=6fbjzTkY/RgXoBILiktjNVOBvqYQ6X+Rj/fOVI4MKqJsNNxFkYPcvCwf92WcPJN60A Niv1ioZlrhcnmnb+tb9GVUIeg7MYUV79C6WWLqZsI2fRTB1PwbE/Ju1B2TCvwwoy6OkE Tl1j3e/iaxay897VROf6qPu3CTLWTgYMsxegBNfANAk5KB/CIoB6ab/wMkCWd8sFvH1p S2IuQdpQHbXyKuBay6oYlm7HcExw3AY05MOwyUXNRdCpRTmZJvBGwEzaZtPBpEBVWLqE ++lyaFZvSMdrPXjl31zhKib+V+PIXKzEZUtdSvw/S3TkAU55AZIh4e502pNcrY6GgHU3 Q7xg== X-Gm-Message-State: AOAM530h2b/s4oh+ceajfiiuq8CPfLr6+EuZcjgG1uwv1nouJokRhzAE ooNxcgI35gpgu1MbDh6RZ6gUDyBrSlqrgaubwC+xo3qaeDQbhOWl2zY+OVKAbwmbgzo3jgMHlEk mt1N1FRCy5R1IfYo= X-Received: by 2002:ac8:5881:: with SMTP id t1mr3338409qta.414.1637022318202; Mon, 15 Nov 2021 16:25:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9u/CiZv3eAlilayG54ULx9DBWSt/GvqivL5YcM1FN0vwjfSk1Pt3JzlyIf24AKBwCVKCjjg== X-Received: by 2002:ac8:5881:: with SMTP id t1mr3338386qta.414.1637022318000; Mon, 15 Nov 2021 16:25:18 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id j19sm7836545qkp.28.2021.11.15.16.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Nov 2021 16:25:17 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 3/5] libstdc++: Adjust fast_float's over/underflow behavior for conformnace Date: Mon, 15 Nov 2021 19:25:03 -0500 Message-Id: <20211116002505.2324582-3-ppalka@redhat.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211116002505.2324582-1-ppalka@redhat.com> References: <20211116002505.2324582-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-16.0 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_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Nov 2021 00:25:22 -0000 This makes fast_float handle the situation where std::from_chars is specified to return result_out_of_range, i.e. when the parsed value is outside the representable range of the floating-point type. libstdc++-v3/ChangeLog: * src/c++17/fast_float/LOCAL_PATCHES: Update. * src/c++17/fast_float/parse_number.h (from_chars_advanced): In case of over/underflow, return errc::result_out_of_range and don't modify 'value'. --- libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES | 1 + libstdc++-v3/src/c++17/fast_float/parse_number.h | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES b/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES index e9d7bba6195..1f90f9d1d85 100644 --- a/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES +++ b/libstdc++-v3/src/c++17/fast_float/LOCAL_PATCHES @@ -1 +1,2 @@ r12-???? +r12-???? diff --git a/libstdc++-v3/src/c++17/fast_float/parse_number.h b/libstdc++-v3/src/c++17/fast_float/parse_number.h index 86dea2287b4..57b3585c2fe 100644 --- a/libstdc++-v3/src/c++17/fast_float/parse_number.h +++ b/libstdc++-v3/src/c++17/fast_float/parse_number.h @@ -99,6 +99,16 @@ from_chars_result from_chars_advanced(const char *first, const char *last, // If we called compute_float>(pns.exponent, pns.mantissa) and we have an invalid power (am.power2 < 0), // then we need to go the long way around again. This is very uncommon. if(am.power2 < 0) { am = digit_comp(pns, am); } + + if((pns.mantissa != 0 && am.mantissa == 0 && am.power2 == 0) || am.power2 == binary_format::infinite_power()) { + // In case of over/underflow, return result_out_of_range and don't modify value, + // as per [charconv.from.chars]/1. + // + // If LWG 3081 gets adopted, then we'll need to call to_float in this case too. + answer.ec = std::errc::result_out_of_range; + return answer; + } + to_float(pns.negative, am, value); return answer; } -- 2.34.0