1 /* Boost interval/rounding.hpp template implementation file
3 * Copyright 2002-2003 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE_1_0.txt or
7 * copy at http://www.boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_NUMERIC_INTERVAL_ROUNDING_HPP
11 #define BOOST_NUMERIC_INTERVAL_ROUNDING_HPP
15 namespace interval_lib
{
18 * Default rounding_control class (does nothing)
22 struct rounding_control
24 typedef int rounding_mode
;
25 static void get_rounding_mode(rounding_mode
&) {}
26 static void set_rounding_mode(rounding_mode
) {}
27 static void upward() {}
28 static void downward() {}
29 static void to_nearest() {}
30 static const T
& to_int(const T
& x
) { return x
; }
31 static const T
& force_rounding(const T
& x
) { return x
; }
35 * A few rounding control classes (exact/std/opp: see documentation)
36 * rounded_arith_* control the rounding of the arithmetic operators
37 * rounded_transc_* control the rounding of the transcendental functions
40 template<class T
, class Rounding
= rounding_control
<T
> >
41 struct rounded_arith_exact
;
43 template<class T
, class Rounding
= rounding_control
<T
> >
44 struct rounded_arith_std
;
46 template<class T
, class Rounding
= rounding_control
<T
> >
47 struct rounded_arith_opp
;
49 template<class T
, class Rounding
>
50 struct rounded_transc_dummy
;
52 template<class T
, class Rounding
= rounded_arith_exact
<T
> >
53 struct rounded_transc_exact
;
55 template<class T
, class Rounding
= rounded_arith_std
<T
> >
56 struct rounded_transc_std
;
58 template<class T
, class Rounding
= rounded_arith_opp
<T
> >
59 struct rounded_transc_opp
;
62 * State-saving classes: allow to set and reset rounding control
67 template<class Rounding
>
68 struct save_state_unprotected
: Rounding
70 typedef save_state_unprotected
<Rounding
> unprotected_rounding
;
75 template<class Rounding
>
76 struct save_state
: Rounding
78 typename
Rounding::rounding_mode mode
;
80 this->get_rounding_mode(mode
);
83 ~save_state() { this->set_rounding_mode(mode
); }
84 typedef detail::save_state_unprotected
<Rounding
> unprotected_rounding
;
87 template<class Rounding
>
88 struct save_state_nothing
: Rounding
90 typedef save_state_nothing
<Rounding
> unprotected_rounding
;
94 struct rounded_math
: save_state_nothing
<rounded_arith_exact
<T
> >
97 } // namespace interval_lib
98 } // namespace numeric
101 #endif // BOOST_NUMERIC_INTERVAL_ROUNDING_HPP