Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:49:07

0001 /* Boost interval/rounding.hpp template implementation file
0002  *
0003  * Copyright 2002-2003 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
0004  *
0005  * Distributed under the Boost Software License, Version 1.0.
0006  * (See accompanying file LICENSE_1_0.txt or
0007  * copy at http://www.boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_NUMERIC_INTERVAL_ROUNDING_HPP
0011 #define BOOST_NUMERIC_INTERVAL_ROUNDING_HPP
0012 
0013 namespace boost {
0014 namespace numeric {
0015 namespace interval_lib {
0016 
0017 /*
0018  * Default rounding_control class (does nothing)
0019  */
0020 
0021 template<class T>
0022 struct rounding_control
0023 {
0024   typedef int rounding_mode;
0025   static void get_rounding_mode(rounding_mode&) {}
0026   static void set_rounding_mode(rounding_mode)  {}
0027   static void upward()     {}
0028   static void downward()   {}
0029   static void to_nearest() {}
0030   static const T& to_int(const T& x)         { return x; }
0031   static const T& force_rounding(const T& x) { return x; }
0032 };
0033 
0034 /*
0035  * A few rounding control classes (exact/std/opp: see documentation)
0036  *   rounded_arith_* control the rounding of the arithmetic operators
0037  *   rounded_transc_* control the rounding of the transcendental functions
0038  */
0039 
0040 template<class T, class Rounding = rounding_control<T> >
0041 struct rounded_arith_exact;
0042 
0043 template<class T, class Rounding = rounding_control<T> >
0044 struct rounded_arith_std;
0045 
0046 template<class T, class Rounding = rounding_control<T> >
0047 struct rounded_arith_opp;
0048 
0049 template<class T, class Rounding>
0050 struct rounded_transc_dummy;
0051 
0052 template<class T, class Rounding = rounded_arith_exact<T> > 
0053 struct rounded_transc_exact;
0054 
0055 template<class T, class Rounding = rounded_arith_std<T> > 
0056 struct rounded_transc_std;
0057 
0058 template<class T, class Rounding = rounded_arith_opp<T> > 
0059 struct rounded_transc_opp;
0060 
0061 /*
0062  * State-saving classes: allow to set and reset rounding control
0063  */
0064 
0065 namespace detail {
0066 
0067 template<class Rounding>
0068 struct save_state_unprotected: Rounding
0069 {
0070   typedef save_state_unprotected<Rounding> unprotected_rounding;
0071 };
0072 
0073 } // namespace detail
0074 
0075 template<class Rounding>
0076 struct save_state: Rounding
0077 {
0078   typename Rounding::rounding_mode mode;
0079   save_state() {
0080     this->get_rounding_mode(mode);
0081     this->init();
0082   }
0083   ~save_state() { this->set_rounding_mode(mode); }
0084   typedef detail::save_state_unprotected<Rounding> unprotected_rounding;
0085 };
0086   
0087 template<class Rounding>
0088 struct save_state_nothing: Rounding
0089 {
0090   typedef save_state_nothing<Rounding> unprotected_rounding;
0091 };
0092   
0093 template<class T>
0094 struct rounded_math: save_state_nothing<rounded_arith_exact<T> >
0095 {};
0096 
0097 } // namespace interval_lib
0098 } // namespace numeric
0099 } // namespace boost
0100 
0101 #endif // BOOST_NUMERIC_INTERVAL_ROUNDING_HPP