Chris@16: /* Boost interval/rounding.hpp template implementation file Chris@16: * Chris@16: * Copyright 2002-2003 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_ROUNDING_HPP Chris@16: #define BOOST_NUMERIC_INTERVAL_ROUNDING_HPP Chris@16: Chris@16: namespace boost { Chris@16: namespace numeric { Chris@16: namespace interval_lib { Chris@16: Chris@16: /* Chris@16: * Default rounding_control class (does nothing) Chris@16: */ Chris@16: Chris@16: template Chris@16: struct rounding_control Chris@16: { Chris@16: typedef int rounding_mode; Chris@16: static void get_rounding_mode(rounding_mode&) {} Chris@16: static void set_rounding_mode(rounding_mode) {} Chris@16: static void upward() {} Chris@16: static void downward() {} Chris@16: static void to_nearest() {} Chris@16: static const T& to_int(const T& x) { return x; } Chris@16: static const T& force_rounding(const T& x) { return x; } Chris@16: }; Chris@16: Chris@16: /* Chris@16: * A few rounding control classes (exact/std/opp: see documentation) Chris@16: * rounded_arith_* control the rounding of the arithmetic operators Chris@16: * rounded_transc_* control the rounding of the transcendental functions Chris@16: */ Chris@16: Chris@16: template > Chris@16: struct rounded_arith_exact; Chris@16: Chris@16: template > Chris@16: struct rounded_arith_std; Chris@16: Chris@16: template > Chris@16: struct rounded_arith_opp; Chris@16: Chris@16: template Chris@16: struct rounded_transc_dummy; Chris@16: Chris@16: template > Chris@16: struct rounded_transc_exact; Chris@16: Chris@16: template > Chris@16: struct rounded_transc_std; Chris@16: Chris@16: template > Chris@16: struct rounded_transc_opp; Chris@16: Chris@16: /* Chris@16: * State-saving classes: allow to set and reset rounding control Chris@16: */ Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: struct save_state_unprotected: Rounding Chris@16: { Chris@16: typedef save_state_unprotected unprotected_rounding; Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: template Chris@16: struct save_state: Rounding Chris@16: { Chris@16: typename Rounding::rounding_mode mode; Chris@16: save_state() { Chris@16: this->get_rounding_mode(mode); Chris@16: this->init(); Chris@16: } Chris@16: ~save_state() { this->set_rounding_mode(mode); } Chris@16: typedef detail::save_state_unprotected unprotected_rounding; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct save_state_nothing: Rounding Chris@16: { Chris@16: typedef save_state_nothing unprotected_rounding; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct rounded_math: save_state_nothing > Chris@16: {}; Chris@16: Chris@16: } // namespace interval_lib Chris@16: } // namespace numeric Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_NUMERIC_INTERVAL_ROUNDING_HPP