• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

rounding.h

Go to the documentation of this file.
00001 /// @addtogroup unifexp
00002 /// @{
00003 
00004 /////////////////////////////////////////////////////////////////////////////
00005 ///
00006 /// @file rounding.h
00007 ///
00008 /// This file contains the definition of a class for rounding operations
00009 /// which uses the BOOST library.
00010 ///
00011 /// @author Pawel Pilarczyk
00012 ///
00013 /////////////////////////////////////////////////////////////////////////////
00014 
00015 // Copyright (C) 2007 by Pawel Pilarczyk.
00016 //
00017 // This file is part of my research program package.  This is free software;
00018 // you can redistribute it and/or modify it under the terms of the GNU
00019 // General Public License as published by the Free Software Foundation;
00020 // either version 2 of the License, or (at your option) any later version.
00021 //
00022 // This software is distributed in the hope that it will be useful,
00023 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025 // GNU General Public License for more details.
00026 //
00027 // You should have received a copy of the GNU General Public License along
00028 // with this software; see the file "license.txt".  If not, write to the
00029 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00030 // MA 02111-1307, USA.
00031 
00032 // Started on July 10, 2007. Last revision: July 10, 2007.
00033 
00034 #ifndef _rounding_h_
00035 #define _rounding_h_
00036 
00037 // BOOST (this header must be included first)
00038 #include "boost/numeric/interval.hpp"
00039 
00040 #include <utility>
00041 #include <iostream>
00042 
00043 
00044 namespace unifexp {
00045 
00046 // --------------------------------------------------
00047 // -------------- rounding operations ---------------
00048 // --------------------------------------------------
00049 
00050 /// A class for rounding operations which uses the BOOST library.
00051 template <class numType>
00052 class tRounding
00053 {
00054 public:
00055 /// This is an internal macro of the class template "tRounding"
00056 /// which defines arithmetic operations using the operations
00057 /// available in the BOOST library.
00058 #define DEFOP(WHAT) \
00059         static inline numType WHAT (const numType &x, const numType &y) \
00060         { \
00061                 numType result = Rounding. WHAT (x, y); \
00062                 Rounding. to_nearest (); \
00063                 return result; \
00064         }
00065 
00066         DEFOP(add_down)
00067         DEFOP(add_up)
00068         DEFOP(sub_down)
00069         DEFOP(sub_up)
00070         DEFOP(mul_down)
00071         DEFOP(mul_up)
00072         DEFOP(div_down)
00073         DEFOP(div_up)
00074 
00075 #undef DEFOP
00076 
00077 /*      numType add_down (const numType &x, const numType &y) const
00078         {
00079                 numType result = Rounding. add_down (x, y);
00080                 Rounding. to_nearest ();
00081                 return result;
00082         }
00083 */
00084 
00085 private:
00086         /// This is an object from the BOOST library which contains
00087         /// the definitions of arithmetic operations with correct rounding.
00088         static boost::numeric::interval_lib::rounded_arith_std<numType>
00089                 Rounding;
00090 }; /* class tRounding */
00091 
00092 // --------------------------------------------------
00093 
00094 template <class numType>
00095 boost::numeric::interval_lib::rounded_arith_std<numType>
00096         tRounding<numType>::Rounding;
00097 
00098 // --------------------------------------------------
00099 
00100 
00101 } // namespace unifexp
00102 
00103 #endif // _rounding_h_
00104 
00105 /// @}
00106 

Generated on Sun Feb 3 2013 12:40:32 for The Uniform Expansion Software by  doxygen 1.7.2