fix doc example typo
[boost.git] / boost / numeric / interval / rounding.hpp
blobf69e2e4b538dc1e523960fe8c5e24367f69d2d63
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)
8 */
10 #ifndef BOOST_NUMERIC_INTERVAL_ROUNDING_HPP
11 #define BOOST_NUMERIC_INTERVAL_ROUNDING_HPP
13 namespace boost {
14 namespace numeric {
15 namespace interval_lib {
18 * Default rounding_control class (does nothing)
21 template<class T>
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
65 namespace detail {
67 template<class Rounding>
68 struct save_state_unprotected: Rounding
70 typedef save_state_unprotected<Rounding> unprotected_rounding;
73 } // namespace detail
75 template<class Rounding>
76 struct save_state: Rounding
78 typename Rounding::rounding_mode mode;
79 save_state() {
80 this->get_rounding_mode(mode);
81 this->init();
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;
93 template<class T>
94 struct rounded_math: save_state_nothing<rounded_arith_exact<T> >
95 {};
97 } // namespace interval_lib
98 } // namespace numeric
99 } // namespace boost
101 #endif // BOOST_NUMERIC_INTERVAL_ROUNDING_HPP