c99sub_rounding_control.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* Boost interval/detail/c99sub_rounding_control.hpp file
  2. *
  3. * Copyright 2000 Jens Maurer
  4. * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
  5. *
  6. * Distributed under the Boost Software License, Version 1.0.
  7. * (See accompanying file LICENSE_1_0.txt or
  8. * copy at http://www.boost.org/LICENSE_1_0.txt)
  9. */
  10. #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP
  11. #define BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP
  12. #include <boost/detail/fenv.hpp> // ISO C 99 rounding mode control
  13. namespace boost {
  14. namespace numeric {
  15. namespace interval_lib {
  16. namespace detail {
  17. extern "C" { double rint(double); }
  18. struct c99_rounding_control
  19. {
  20. typedef int rounding_mode;
  21. static void set_rounding_mode(rounding_mode mode) { fesetround(mode); }
  22. static void get_rounding_mode(rounding_mode &mode) { mode = fegetround(); }
  23. static void downward() { set_rounding_mode(FE_DOWNWARD); }
  24. static void upward() { set_rounding_mode(FE_UPWARD); }
  25. static void to_nearest() { set_rounding_mode(FE_TONEAREST); }
  26. static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); }
  27. template<class T>
  28. static T to_int(const T& r) { return rint(r); }
  29. };
  30. } // namespace detail
  31. } // namespace interval_lib
  32. } // namespace numeric
  33. } // namespace boost
  34. #endif // BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUBDING_CONTROL_HPP