Chris@16: /* Boost interval/detail/c99sub_rounding_control.hpp file Chris@16: * Chris@16: * Copyright 2000 Jens Maurer Chris@16: * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion Chris@16: * Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or Chris@16: * copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP Chris@16: #define BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP Chris@16: Chris@16: #include // ISO C 99 rounding mode control Chris@16: Chris@16: namespace boost { Chris@16: namespace numeric { Chris@16: namespace interval_lib { Chris@16: namespace detail { Chris@16: Chris@16: extern "C" { double rint(double); } Chris@16: Chris@16: struct c99_rounding_control Chris@16: { Chris@16: typedef int rounding_mode; Chris@16: Chris@16: static void set_rounding_mode(rounding_mode mode) { fesetround(mode); } Chris@16: static void get_rounding_mode(rounding_mode &mode) { mode = fegetround(); } Chris@16: static void downward() { set_rounding_mode(FE_DOWNWARD); } Chris@16: static void upward() { set_rounding_mode(FE_UPWARD); } Chris@16: static void to_nearest() { set_rounding_mode(FE_TONEAREST); } Chris@16: static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); } Chris@16: Chris@16: template Chris@16: static T to_int(const T& r) { return rint(r); } Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace interval_lib Chris@16: } // namespace numeric Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUBDING_CONTROL_HPP