The CyMeAlg Software (Release 0.01)
boostrnd.h
Go to the documentation of this file.
1 /// @addtogroup cymealg
2 /// @{
3 
4 /////////////////////////////////////////////////////////////////////////////
5 ///
6 /// @file
7 ///
8 /// This file contains the definition of a class for rounding operations
9 /// for graph algorithms, based on the BOOST library.
10 ///
11 /// @author Pawel Pilarczyk
12 ///
13 /////////////////////////////////////////////////////////////////////////////
14 
15 // Copyright (C) 1997-2020 by Pawel Pilarczyk.
16 //
17 // This file is part of my research software. This is free software:
18 // you can redistribute it and/or modify it under the terms of the GNU
19 // General Public License as published by the Free Software Foundation,
20 // either version 3 of the License, or (at your option) any later version.
21 //
22 // This software is distributed in the hope that it will be useful,
23 // but WITHOUT ANY WARRANTY; without even the implied warranty of
24 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 // GNU General Public License for more details.
26 //
27 // You should have received a copy of the GNU General Public License
28 // along with this software; see the file "license.txt". If not,
29 // please, see <http://www.gnu.org/licenses/>.
30 
31 // Started in January 2006. Last revision: August 23, 2019.
32 
33 
34 #ifndef _CYMEALG_BOOSTRND_H_
35 #define _CYMEALG_BOOSTRND_H_
36 
37 // BOOST (this header must be included first)
38 #include "boost/numeric/interval.hpp"
39 
40 namespace cymealg {
41 
42 // --------------------------------------------------
43 // -------------------- rounding --------------------
44 // --------------------------------------------------
45 
46 /// A class for rounding operations which uses the BOOST library.
47 template <class numType>
49 {
50 public:
51 /// This is an internal macro of the class template "tBoostRounding"
52 /// which defines arithmetic operations using the operations
53 /// available in the BOOST library.
54 #define DEFOP(WHAT) \
55  static inline numType WHAT (const numType &x, const numType &y) \
56  { \
57  numType result = Rounding. WHAT (x, y); \
58  Rounding. to_nearest (); \
59  return result; \
60  }
61 
62  DEFOP(add_down)
63  DEFOP(add_up)
64  DEFOP(sub_down)
65  DEFOP(sub_up)
66  DEFOP(mul_down)
67  DEFOP(mul_up)
68  DEFOP(div_down)
69  DEFOP(div_up)
70 
71 #undef DEFOP
72 
73 /* numType add_down (const numType &x, const numType &y) const
74  {
75  numType result = Rounding. add_down (x, y);
76  Rounding. to_nearest ();
77  return result;
78  }
79 */
80 
81 private:
82  /// This is an object from the BOOST library which contains
83  /// the definitions of arithmetic operations with correct rounding.
84  static boost::numeric::interval_lib::rounded_arith_std<numType>
86 }; /* class tBoostRounding */
87 
88 // --------------------------------------------------
89 
90 template <class numType>
91 boost::numeric::interval_lib::rounded_arith_std<numType>
93 
94 
95 } // namespace cymealg
96 
97 #endif // _CYMEALG_BOOSTRND_H_
98 
99 /// @}
100 
#define DEFOP(WHAT)
This is an internal macro of the class template "tBoostRounding" which defines arithmetic operations ...
Definition: boostrnd.h:54
static boost::numeric::interval_lib::rounded_arith_std< numType > Rounding
This is an object from the BOOST library which contains the definitions of arithmetic operations with...
Definition: boostrnd.h:85
A class for rounding operations which uses the BOOST library.
Definition: boostrnd.h:48