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 11 #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP 12 #define BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP 13 14 #include <boost/detail/fenv.hpp> // ISO C 99 rounding mode control 15 16 namespace boost { 17 namespace numeric { 18 namespace interval_lib { 19 namespace detail { 20 21 extern "C" { double rint(double); } 22 23 struct c99_rounding_control 24 { 25 typedef int rounding_mode; 26 set_rounding_modeboost::numeric::interval_lib::detail::c99_rounding_control27 static void set_rounding_mode(rounding_mode mode) { fesetround(mode); } get_rounding_modeboost::numeric::interval_lib::detail::c99_rounding_control28 static void get_rounding_mode(rounding_mode &mode) { mode = fegetround(); } downwardboost::numeric::interval_lib::detail::c99_rounding_control29 static void downward() { set_rounding_mode(FE_DOWNWARD); } upwardboost::numeric::interval_lib::detail::c99_rounding_control30 static void upward() { set_rounding_mode(FE_UPWARD); } to_nearestboost::numeric::interval_lib::detail::c99_rounding_control31 static void to_nearest() { set_rounding_mode(FE_TONEAREST); } toward_zeroboost::numeric::interval_lib::detail::c99_rounding_control32 static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); } 33 34 template<class T> to_intboost::numeric::interval_lib::detail::c99_rounding_control35 static T to_int(const T& r) { return rint(r); } 36 }; 37 38 } // namespace detail 39 } // namespace interval_lib 40 } // namespace numeric 41 } // namespace boost 42 43 #endif // BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUBDING_CONTROL_HPP 44