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 DA7853858406 for ; Fri, 19 Nov 2021 21:50:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DA7853858406 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-518-q5aBasvPOh68s11QDBmxSw-1; Fri, 19 Nov 2021 16:50:01 -0500 X-MC-Unique: q5aBasvPOh68s11QDBmxSw-1 Received: by mail-qt1-f198.google.com with SMTP id y25-20020ac87059000000b002a71d24c242so8034993qtm.0 for ; Fri, 19 Nov 2021 13:50:01 -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:date:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=+URFH/BdDh7zXwaZmxJ9fzSyIZKcqDDzJ7a/yJqkg3c=; b=EtcI8DkXnRySrFeBGMXSRTZiFO0r6+wFDDQcOSZ6SFJRfg/D8cz/q59QwYk+EReEjg lq4RhzCyoA2aqCsWH80a1f1eNRoimXLvQtTmns+IFqD8xsimiCRWcR48bk8QPbf8INPf gcyyQsZCTuurXhsTUBWgzooPdEOg8FdLdRQgVdbOFBiIDQ5RV2e/YanD+MS/7tE4M4zC Zh2pSc6geZTzRZQhsDIbYG249nVsZGdDgyUbF77GsWcu1L9TvVTeAO+gh6VMxkIcCGMM mhxwIHfMFnbW6HerB0j7OtRtcijL2xxTeAAK+bs0HG153Dl1ekPiHC5cZYsu5UXrq8w7 CZaQ== X-Gm-Message-State: AOAM533nIFKIbW9RalUmNMoA3O8Spm/fUYa9GnvsFPwNnAyzlgkMufY3 hM6b7aWxx686+nnnX9V2nd1ub1/auNmEGcUdUzyVGiscbtiBzeZAAJje/kmnXUYlIHzp5iA3DUG Hs2L27O5WRZdIxwI= X-Received: by 2002:a05:6214:21a6:: with SMTP id t6mr77046476qvc.5.1637358600463; Fri, 19 Nov 2021 13:50:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJzkDP6DgTgDu5Ry2GflF038pVYN1XfQeawxLSgJm5izogWFImGknHgaUuND5tzkJJKocVXqvQ== X-Received: by 2002:a05:6214:21a6:: with SMTP id t6mr77046450qvc.5.1637358600232; Fri, 19 Nov 2021 13:50:00 -0800 (PST) Received: from [192.168.1.130] (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id q12sm546606qtx.16.2021.11.19.13.49.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 13:49:59 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Fri, 19 Nov 2021 16:49:58 -0500 (EST) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: Re: [PATCH 3/5] libstdc++: Adjust fast_float's over/underflow behavior for conformnace In-Reply-To: <20211116002505.2324582-3-ppalka@redhat.com> Message-ID: <69f4a10b-d67d-276a-d2a5-fdc33e195279@idea> References: <20211116002505.2324582-1-ppalka@redhat.com> <20211116002505.2324582-3-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-15.7 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=unavailable 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: Fri, 19 Nov 2021 21:50:05 -0000 On Mon, 15 Nov 2021, Patrick Palka wrote: > 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'. v2: Now in terms of the amalgamated version of the library. -- >8 -- Subject: [PATCH 3/5] libstdc++: Adjust fast_float's over/underflow behavior for conformance This adjusts fast_float's behavior in case of over/underflow: rather than setting value to +-0 or +-infinity, return result_out_of_range and don't modify value, as per [charconv.from.chars]/1. libstdc++-v3/ChangeLog: * src/c++17/fast_float/LOCAL_PATCHES: Update. * src/c++17/fast_float/fast_float.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/fast_float.h | 9 +++++++++ 2 files changed, 10 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/fast_float.h b/libstdc++-v3/src/c++17/fast_float/fast_float.h index c908719ec3a..97d28940944 100644 --- a/libstdc++-v3/src/c++17/fast_float/fast_float.h +++ b/libstdc++-v3/src/c++17/fast_float/fast_float.h @@ -2884,6 +2884,15 @@ 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. Note that LWG 3081 wants to modify value 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