lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master e04cad4 3/6: Explicitly qualify standard func


From: Greg Chicares
Subject: [lmi-commits] [lmi] master e04cad4 3/6: Explicitly qualify standard functions
Date: Thu, 5 Jan 2017 21:52:29 +0000 (UTC)

branch: master
commit e04cad4c54d31821d5cf9807dd07617ebc520a48
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Explicitly qualify standard functions
    
    It seemed curious that the code even compiled before this change, but
    apparently that's permitted now:
      http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#456
    
    <cfenv> is now explicitly included in all files that use any function
    it declares, even though for the time being it's implicitly included
    via 'fenv_lmi.hpp'.
---
 fenv_lmi.cpp      |   21 +++++++++++----------
 fenv_lmi_test.cpp |    7 ++++---
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/fenv_lmi.cpp b/fenv_lmi.cpp
index 31e9a57..ccabf8e 100644
--- a/fenv_lmi.cpp
+++ b/fenv_lmi.cpp
@@ -27,6 +27,7 @@
 #include "assert_lmi.hpp"
 #include "miscellany.hpp"               // stifle_warning_for_unused_variable()
 
+#include <cfenv>
 #include <iomanip>
 #include <ios>
 #include <sstream>
@@ -52,7 +53,7 @@
 /// they are sufficient, in order to maintain consistency with cases
 /// for which they are not. Another reason for this design decision
 /// is type safety: for instance,
-///   fesetround(int);
+///   std::fesetround(int);
 /// accepts any integer, whereas
 ///   void fenv_rounding(e_ieee754_rounding rounding_mode)
 /// accepts only the arguments we allow.
@@ -64,13 +65,13 @@ void fenv_initialize()
 #if defined LMI_X87
     x87_control_word(default_x87_control_word());
 #else  // !defined LMI_X87
-    fenv_t save_env;
-    feholdexcept(&save_env);
-    fesetround(FE_TONEAREST);
+    std::fenv_t save_env;
+    std::feholdexcept(&save_env);
+    std::fesetround(FE_TONEAREST);
     // Standard C++ provides no way to set hardware precision.
     // Here is an example of a C99 7.6/9 extension that controls
     // hardware precision for MinGW32:
-    //   fesetenv(FE_PC64_ENV);
+    //   std::fesetenv(FE_PC64_ENV);
 #endif // !defined LMI_X87
 }
 
@@ -120,7 +121,7 @@ e_ieee754_rounding fenv_rounding()
         : throw std::runtime_error("Failed to determine rounding mode.")
         ;
 #else  // !defined LMI_X87
-    int z = fegetround();
+    int z = std::fegetround();
     return
           (FE_TONEAREST  == z) ? fe_tonearest
         : (FE_DOWNWARD   == z) ? fe_downward
@@ -152,7 +153,7 @@ void fenv_rounding(e_ieee754_rounding rounding_mode)
         : (fe_towardzero == rounding_mode) ? FE_TOWARDZERO
         : throw std::runtime_error("Failed to set rounding mode.")
         ;
-    fesetround(z);
+    std::fesetround(z);
 #endif // !defined LMI_X87
 }
 
@@ -161,7 +162,7 @@ bool fenv_is_valid()
 #if defined LMI_X87
     return default_x87_control_word() == x87_control_word();
 #else  // !defined LMI_X87
-    return FE_TONEAREST == fegetround() && 0 == fetestexcept(FE_ALL_EXCEPT);
+    return FE_TONEAREST == std::fegetround() && 0 == 
std::fetestexcept(FE_ALL_EXCEPT);
 #endif // !defined LMI_X87
 }
 
@@ -180,8 +181,8 @@ std::string fenv_explain_invalid_control_word()
 #else  // !defined LMI_X87
     oss
         << "The floating-point environment unexpectedly changed."
-        << "\nThe rounding mode is " << fegetround()
-        << " and the exception bitmask is " << fetestexcept(FE_ALL_EXCEPT)
+        << "\nThe rounding mode is " << std::fegetround()
+        << " and the exception bitmask is " << std::fetestexcept(FE_ALL_EXCEPT)
         << ".\n"
         ;
 #endif // !defined LMI_X87
diff --git a/fenv_lmi_test.cpp b/fenv_lmi_test.cpp
index 494c79b..5973664 100644
--- a/fenv_lmi_test.cpp
+++ b/fenv_lmi_test.cpp
@@ -40,6 +40,7 @@
 #include "test_tools.hpp"
 
 #include <bitset>
+#include <cfenv>
 #include <climits>                      // CHAR_BIT
 #include <math.h>                       // C99 rint()
 #include <stdexcept>
@@ -134,13 +135,13 @@ int test_main(int, char*[])
 
 #   if defined __MINGW32__
     // Test the C99 method, as extended by MinGW.
-    fesetenv(FE_PC53_ENV);
+    std::fesetenv(FE_PC53_ENV);
     BOOST_TEST_EQUAL_BITS(0x027f, x87_control_word());
 
-    fesetenv(FE_PC64_ENV);
+    std::fesetenv(FE_PC64_ENV);
     BOOST_TEST_EQUAL_BITS(0x037f, x87_control_word());
 
-    fesetenv(FE_DFL_ENV);
+    std::fesetenv(FE_DFL_ENV);
     BOOST_TEST_EQUAL_BITS(0x037f, x87_control_word());
 #   endif // defined __MINGW32__
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]