{
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);
#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
// 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
// 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