sl@0: /* Boost interval/rounding.hpp template implementation file sl@0: * sl@0: * Copyright 2002-2003 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion sl@0: * sl@0: * Distributed under the Boost Software License, Version 1.0. sl@0: * (See accompanying file LICENSE_1_0.txt or sl@0: * copy at http://www.boost.org/LICENSE_1_0.txt) sl@0: */ sl@0: sl@0: #ifndef BOOST_NUMERIC_INTERVAL_ROUNDING_HPP sl@0: #define BOOST_NUMERIC_INTERVAL_ROUNDING_HPP sl@0: sl@0: namespace boost { sl@0: namespace numeric { sl@0: namespace interval_lib { sl@0: sl@0: /* sl@0: * Default rounding_control class (does nothing) sl@0: */ sl@0: sl@0: template sl@0: struct rounding_control sl@0: { sl@0: typedef int rounding_mode; sl@0: static void get_rounding_mode(rounding_mode&) {} sl@0: static void set_rounding_mode(rounding_mode) {} sl@0: static void upward() {} sl@0: static void downward() {} sl@0: static void to_nearest() {} sl@0: static const T& to_int(const T& x) { return x; } sl@0: static const T& force_rounding(const T& x) { return x; } sl@0: }; sl@0: sl@0: /* sl@0: * A few rounding control classes (exact/std/opp: see documentation) sl@0: * rounded_arith_* control the rounding of the arithmetic operators sl@0: * rounded_transc_* control the rounding of the transcendental functions sl@0: */ sl@0: sl@0: template > sl@0: struct rounded_arith_exact; sl@0: sl@0: template > sl@0: struct rounded_arith_std; sl@0: sl@0: template > sl@0: struct rounded_arith_opp; sl@0: sl@0: template sl@0: struct rounded_transc_dummy; sl@0: sl@0: template > sl@0: struct rounded_transc_exact; sl@0: sl@0: template > sl@0: struct rounded_transc_std; sl@0: sl@0: template > sl@0: struct rounded_transc_opp; sl@0: sl@0: /* sl@0: * State-saving classes: allow to set and reset rounding control sl@0: */ sl@0: sl@0: namespace detail { sl@0: sl@0: template sl@0: struct save_state_unprotected: Rounding sl@0: { sl@0: typedef save_state_unprotected unprotected_rounding; sl@0: }; sl@0: sl@0: } // namespace detail sl@0: sl@0: template sl@0: struct save_state: Rounding sl@0: { sl@0: typename Rounding::rounding_mode mode; sl@0: save_state() { sl@0: this->get_rounding_mode(mode); sl@0: this->init(); sl@0: } sl@0: ~save_state() { this->set_rounding_mode(mode); } sl@0: typedef detail::save_state_unprotected unprotected_rounding; sl@0: }; sl@0: sl@0: template sl@0: struct save_state_nothing: Rounding sl@0: { sl@0: typedef save_state_nothing unprotected_rounding; sl@0: }; sl@0: sl@0: template sl@0: struct rounded_math: save_state_nothing > sl@0: {}; sl@0: sl@0: } // namespace interval_lib sl@0: } // namespace numeric sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_NUMERIC_INTERVAL_ROUNDING_HPP