From: Patrick Palka <ppalka@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
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
Date: Fri, 19 Nov 2021 16:49:58 -0500 (EST) [thread overview]
Message-ID: <69f4a10b-d67d-276a-d2a5-fdc33e195279@idea> (raw)
In-Reply-To: <20211116002505.2324582-3-ppalka@redhat.com>
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<binary_format<T>>(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<T>(pns, am); }
+
+ if((pns.mantissa != 0 && am.mantissa == 0 && am.power2 == 0) || am.power2 == binary_format<T>::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
next prev parent reply other threads:[~2021-11-19 21:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-16 0:25 [PATCH 1/5] libstdc++: Import the fast_float library Patrick Palka
2021-11-16 0:25 ` [PATCH 2/5] libstdc++: Apply modifications to our local copy of fast_float Patrick Palka
2021-11-19 21:47 ` Patrick Palka
2021-11-16 0:25 ` [PATCH 3/5] libstdc++: Adjust fast_float's over/underflow behavior for conformnace Patrick Palka
2021-11-19 21:49 ` Patrick Palka [this message]
2021-11-16 0:25 ` [PATCH 4/5] libstdc++: Use fast_float in std::from_chars for binary32/64 Patrick Palka
2021-11-16 0:25 ` [PATCH 5/5] libstdc++: Import MSVC floating-point std::from_chars testcases Patrick Palka
2021-11-16 7:59 ` [PATCH 1/5] libstdc++: Import the fast_float library Florian Weimer
2021-11-16 9:32 ` Jonathan Wakely
2021-11-16 9:46 ` Florian Weimer
2021-11-16 11:34 ` Jonathan Wakely
2021-11-16 15:30 ` Patrick Palka
2021-11-16 16:18 ` Daniel Krügler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=69f4a10b-d67d-276a-d2a5-fdc33e195279@idea \
--to=ppalka@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).