1 /* Boost interval/detail/c99sub_rounding_control.hpp file
3 * Copyright 2000 Jens Maurer
4 * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
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)
11 #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP
12 #define BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP
14 #include <boost/detail/fenv.hpp> // ISO C 99 rounding mode control
18 namespace interval_lib {
21 extern "C" { double rint(double); }
23 struct c99_rounding_control
25 typedef int rounding_mode;
27 static void set_rounding_mode(rounding_mode mode) { fesetround(mode); }
28 static void get_rounding_mode(rounding_mode &mode) { mode = fegetround(); }
29 static void downward() { set_rounding_mode(FE_DOWNWARD); }
30 static void upward() { set_rounding_mode(FE_UPWARD); }
31 static void to_nearest() { set_rounding_mode(FE_TONEAREST); }
32 static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); }
35 static T to_int(const T& r) { return rint(r); }
39 } // namespace interval_lib
40 } // namespace numeric
43 #endif // BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUBDING_CONTROL_HPP