]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* Boost interval/rounding.hpp template implementation file |
2 | * | |
b32b8144 | 3 | * Copyright 2002-2003 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion |
7c673cae FG |
4 | * |
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 | */ | |
9 | ||
10 | #ifndef BOOST_NUMERIC_INTERVAL_ROUNDING_HPP | |
11 | #define BOOST_NUMERIC_INTERVAL_ROUNDING_HPP | |
12 | ||
13 | namespace boost { | |
14 | namespace numeric { | |
15 | namespace interval_lib { | |
16 | ||
17 | /* | |
18 | * Default rounding_control class (does nothing) | |
19 | */ | |
20 | ||
21 | template<class T> | |
22 | struct rounding_control | |
23 | { | |
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; } | |
32 | }; | |
33 | ||
34 | /* | |
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 | |
38 | */ | |
39 | ||
40 | template<class T, class Rounding = rounding_control<T> > | |
41 | struct rounded_arith_exact; | |
42 | ||
43 | template<class T, class Rounding = rounding_control<T> > | |
44 | struct rounded_arith_std; | |
45 | ||
46 | template<class T, class Rounding = rounding_control<T> > | |
47 | struct rounded_arith_opp; | |
48 | ||
49 | template<class T, class Rounding> | |
50 | struct rounded_transc_dummy; | |
51 | ||
52 | template<class T, class Rounding = rounded_arith_exact<T> > | |
53 | struct rounded_transc_exact; | |
54 | ||
55 | template<class T, class Rounding = rounded_arith_std<T> > | |
56 | struct rounded_transc_std; | |
57 | ||
58 | template<class T, class Rounding = rounded_arith_opp<T> > | |
59 | struct rounded_transc_opp; | |
60 | ||
61 | /* | |
62 | * State-saving classes: allow to set and reset rounding control | |
63 | */ | |
64 | ||
65 | namespace detail { | |
66 | ||
67 | template<class Rounding> | |
68 | struct save_state_unprotected: Rounding | |
69 | { | |
70 | typedef save_state_unprotected<Rounding> unprotected_rounding; | |
71 | }; | |
72 | ||
73 | } // namespace detail | |
74 | ||
75 | template<class Rounding> | |
76 | struct save_state: Rounding | |
77 | { | |
78 | typename Rounding::rounding_mode mode; | |
79 | save_state() { | |
80 | this->get_rounding_mode(mode); | |
81 | this->init(); | |
82 | } | |
83 | ~save_state() { this->set_rounding_mode(mode); } | |
84 | typedef detail::save_state_unprotected<Rounding> unprotected_rounding; | |
85 | }; | |
86 | ||
87 | template<class Rounding> | |
88 | struct save_state_nothing: Rounding | |
89 | { | |
90 | typedef save_state_nothing<Rounding> unprotected_rounding; | |
91 | }; | |
92 | ||
93 | template<class T> | |
94 | struct rounded_math: save_state_nothing<rounded_arith_exact<T> > | |
95 | {}; | |
96 | ||
97 | } // namespace interval_lib | |
98 | } // namespace numeric | |
99 | } // namespace boost | |
100 | ||
101 | #endif // BOOST_NUMERIC_INTERVAL_ROUNDING_HPP |