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.129.124]) by sourceware.org (Postfix) with ESMTPS id EC9A7385840D for ; Fri, 19 Nov 2021 21:50:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EC9A7385840D Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-35-zmTJ7XvoMiKeih3AJxHe8Q-1; Fri, 19 Nov 2021 16:50:01 -0500 X-MC-Unique: zmTJ7XvoMiKeih3AJxHe8Q-1 Received: by mail-qv1-f69.google.com with SMTP id q2-20020a05621419e200b003aeeeff5417so10101429qvc.9 for ; Fri, 19 Nov 2021 13:50:00 -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=6t7Vq4CC/JFSk5RQgFT65XqqQGR28YvE/8dbqZ0ZliqzGJTar4NvCRYu0mOR3ewbF+ HdUqAn1RU7d1GwCAS4/rBHztkSVUz77TqcD5l8L9VN2mY9Tzy0PUrdf4m4LliDH46yWy YHTIUVlZplvVP62xBM6wo2ewU6MKrtnPafOSv69TiP+MSIYoDpKznvkBuCd3RbedxMPU 7aDMUpqsidcMeCZ0M9R2dO1kNMUSdbyJtCARgR8ZHLH2TJZidUaKC5p7BxoGk+Y2+D1H 9ZDlTsbzGWI2GWigT2F1HOumzBqX1DpQdcWCvracjSt6ep6a6HngyG+22uUiE5QU9lzb IsSw== X-Gm-Message-State: AOAM530GEd4k8mN55D2Nm36g4V5/KWU3d4L7t6bzimGUd1weQRXMQbt0 yjORWyWcjnIzJRU5qQs25H30SFWPctBsZxtQ2mW5EC7UWqpdaokD0SjFpVlHFwQAM+tbI7ZXPLM xXrBkU13gS1RkH58ibw== X-Received: by 2002:a05:6214:21a6:: with SMTP id t6mr77046475qvc.5.1637358600464; 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=-16.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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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: 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-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