public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r11-6258] libstdc++: Check FE_TONEAREST is defined before using it
Date: Fri, 18 Dec 2020 16:55:16 +0000 (GMT)	[thread overview]
Message-ID: <20201218165516.0C9DC38618B2@sourceware.org> (raw)

https://gcc.gnu.org/g:266d74647567e610cc6fd6fccb7db31081f538e2

commit r11-6258-g266d74647567e610cc6fd6fccb7db31081f538e2
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Dec 18 11:52:14 2020 -0500

    libstdc++: Check FE_TONEAREST is defined before using it
    
    We need to test that FE_TONEAREST is defined before we may use it along
    with fegetround/fesetround to adjust the floating-point rounding mode.
    This fixes a build failure with older versions of newlib.
    
    libstdc++-v3/ChangeLog:
    
            * src/c++17/floating_from_chars.cc (from_chars_impl)
            [!defined(FE_TONEAREST)]: Don't adjust the rounding mode.
            * src/c++17/floating_to_chars.cc (__floating_to_chars_precision):
            Likewise.

Diff:
---
 libstdc++-v3/src/c++17/floating_from_chars.cc | 4 ++--
 libstdc++-v3/src/c++17/floating_to_chars.cc   | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc b/libstdc++-v3/src/c++17/floating_from_chars.cc
index a1943351493..86d6d0645a9 100644
--- a/libstdc++-v3/src/c++17/floating_from_chars.cc
+++ b/libstdc++-v3/src/c++17/floating_from_chars.cc
@@ -307,7 +307,7 @@ namespace
       {
 	locale_t orig = ::uselocale(loc);
 
-#if _GLIBCXX_USE_C99_FENV_TR1
+#if _GLIBCXX_USE_C99_FENV_TR1 && defined(FE_TONEAREST)
 	const int rounding = std::fegetround();
 	if (rounding != FE_TONEAREST)
 	  std::fesetround(FE_TONEAREST);
@@ -333,7 +333,7 @@ namespace
 #endif
 	const int conv_errno = std::__exchange(errno, save_errno);
 
-#if _GLIBCXX_USE_C99_FENV_TR1
+#if _GLIBCXX_USE_C99_FENV_TR1 && defined(FE_TONEAREST)
 	if (rounding != FE_TONEAREST)
 	  std::fesetround(rounding);
 #endif
diff --git a/libstdc++-v3/src/c++17/floating_to_chars.cc b/libstdc++-v3/src/c++17/floating_to_chars.cc
index dd83f5eea93..474e791e717 100644
--- a/libstdc++-v3/src/c++17/floating_to_chars.cc
+++ b/libstdc++-v3/src/c++17/floating_to_chars.cc
@@ -946,13 +946,13 @@ template<typename T>
 	    // digit, and carefully compute and write the last digit
 	    // ourselves.
 	    char buffer[expected_output_length+1];
-#if _GLIBCXX_USE_C99_FENV_TR1
+#if _GLIBCXX_USE_C99_FENV_TR1 && defined(FE_TONEAREST)
 	    const int saved_rounding_mode = fegetround();
 	    if (saved_rounding_mode != FE_TONEAREST)
 	      fesetround(FE_TONEAREST); // We want round-to-nearest behavior.
 #endif
 	    const int output_length = sprintf(buffer, "%.0Lf", value);
-#if _GLIBCXX_USE_C99_FENV_TR1
+#if _GLIBCXX_USE_C99_FENV_TR1 && defined(FE_TONEAREST)
 	    if (saved_rounding_mode != FE_TONEAREST)
 	      fesetround(saved_rounding_mode);
 #endif
@@ -1139,14 +1139,14 @@ template<typename T>
 
 	// Do the sprintf into the local buffer.
 	char buffer[output_length_upper_bound+1];
-#if _GLIBCXX_USE_C99_FENV_TR1
+#if _GLIBCXX_USE_C99_FENV_TR1 && defined(FE_TONEAREST)
 	const int saved_rounding_mode = fegetround();
 	if (saved_rounding_mode != FE_TONEAREST)
 	  fesetround(FE_TONEAREST); // We want round-to-nearest behavior.
 #endif
 	int output_length
 	  = sprintf(buffer, output_specifier, effective_precision, value);
-#if _GLIBCXX_USE_C99_FENV_TR1
+#if _GLIBCXX_USE_C99_FENV_TR1 && defined(FE_TONEAREST)
 	if (saved_rounding_mode != FE_TONEAREST)
 	  fesetround(saved_rounding_mode);
 #endif


                 reply	other threads:[~2020-12-18 16:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20201218165516.0C9DC38618B2@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@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).