C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
dot.hpp
00001 /*
00002 **  CXSC is a C++ library for eXtended Scientific Computing (V 2.5.4)
00003 **
00004 **  Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
00005 **                          Universitaet Karlsruhe, Germany
00006 **            (C) 2000-2014 Wiss. Rechnen/Softwaretechnologie
00007 **                          Universitaet Wuppertal, Germany   
00008 **
00009 **  This library is free software; you can redistribute it and/or
00010 **  modify it under the terms of the GNU Library General Public
00011 **  License as published by the Free Software Foundation; either
00012 **  version 2 of the License, or (at your option) any later version.
00013 **
00014 **  This library is distributed in the hope that it will be useful,
00015 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 **  Library General Public License for more details.
00018 **
00019 **  You should have received a copy of the GNU Library General Public
00020 **  License along with this library; if not, write to the Free
00021 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 /* CVS $Id: dot.hpp,v 1.35 2014/01/30 17:23:44 cxsc Exp $ */
00025 
00026 #ifndef _CXSC_DOT_HPP_INCLUDED
00027 #define _CXSC_DOT_HPP_INCLUDED
00028 
00029 #include <iostream>
00030 #include <string> 
00031 
00032 #include "compiler.h"
00033 #include "RtsTyp.h"
00034 
00035 namespace cxsc {
00036 
00037 
00038 // ---- RTS - Definitionen ----
00039     
00040 
00041   // Form des dotprec. Akkus:
00042   //      Pointer auf a_btyp
00043   //  ist Pointer auf long
00044 typedef  d_otpr   Dotprecision;
00045 
00046 // ----------------------------
00047 } // namespace cxsc 
00048 
00049 #include "real.hpp"
00050 #include "ioflags.hpp"
00051 
00052 namespace cxsc {
00053 
00054 class dotprecision;
00055 class idotprecision;
00056     
00057 template<typename S, typename T>
00058 static inline void addDot( dotprecision&, const S&, const T&);
00059 template<typename S, typename T>
00060 static inline void addDot( cdotprecision&, const S&, const T&);
00061 template<typename S, typename T>
00062 static inline void addDot( cidotprecision&, const S&, const T&);
00063 template<typename S, typename T>
00064 static inline void addDot_op( dotprecision&, const S&, const T&);
00065 template<typename S, typename T>
00066 static inline void addDot_op( cdotprecision&, const S&, const T&);
00067 template<typename S>
00068 static inline void addSum( dotprecision&, const S&);
00069 
00070 
00071 //----------------------------------------------------------------------
00072 // global verfgbare Dotprecision Variablen
00073 //
00074 //  dotakku[0..3] stehen fuer Matrix, Langzahl u.a. Pakete zur
00075 //                Verfuegung
00076 //  dotakku[4]    wird in den skalaren Paketen intern verwendet
00077 
00078 //#define MAXDOTAKKU      5
00079 //extern dotprecision dotakku[MAXDOTAKKU];
00080 
00081 //Global precision for operators
00082 #ifdef CXSC_USE_TLS_PREC
00083 
00084 #ifdef _WIN32
00085 extern __declspec(thread) unsigned int opdotprec;
00086 #else
00087 extern __thread unsigned int opdotprec;
00088 #endif
00089 
00090 #else
00091 
00092 extern unsigned int opdotprec;
00093 
00094 #endif
00095 
00096 
00097 
00099 
00111 class dotprecision
00112 {
00113    private:
00114       // ---- Dataelements  -----------------------------------------
00115       Dotprecision akku;
00117       real err;
00119       int k;
00120 
00121    public:
00122       // ---- Constructors  -----------------------------------------
00124       dotprecision(void)                 throw();
00126       dotprecision(const dotprecision &) throw();
00127       
00129       inline int get_k() const { return k; }
00131       inline void set_k(unsigned int i) { k=i; }
00133       inline int get_dotprec() const { return k; }
00135       inline void set_dotprec(unsigned int i) { k=i; }
00137       inline real get_err() const { return err; }
00139       inline void set_err(real e) { err = e; }
00140 
00142       dotprecision & operator =(const dotprecision &) throw();
00144       dotprecision & operator =(const real &)         throw();
00146       dotprecision & operator =(const l_real &)       throw(); // in l_real.cpp
00147 
00148       // ---- Typecasts     -----------------------------------------
00150       explicit dotprecision(const real &)         throw();
00152       explicit dotprecision(const l_real &) throw();
00154 
00159       friend inline dotprecision _dotprecision(const real &d) throw();
00160 
00161       // ---- Destruktor    -----------------------------------------
00162       ~dotprecision(void) ;
00163 
00164       // ---- Input/Output  -----------------------------------------
00166       friend std::string  & operator <<(std::string &,const dotprecision &) throw();
00168       friend std::string  & operator >>(std::string &,dotprecision &)       throw();
00170       friend void           operator >>(const std::string &,dotprecision &) throw();
00172       friend void           operator >>(const char *,dotprecision &)        throw();
00174       friend std::ostream & operator <<(std::ostream &,const dotprecision &) throw();
00176       friend std::istream & operator >>(std::istream &,dotprecision &)      throw();
00177 
00178       // ---- Std.Operators -----------------------------------------
00180       friend  dotprecision operator -(const dotprecision &) throw();
00182       friend  dotprecision operator +(const dotprecision &) throw();
00183 
00185       friend  dotprecision operator +(const dotprecision &,const dotprecision &) throw();
00187       friend  dotprecision operator -(const dotprecision &,const dotprecision &) throw();
00189       friend inline idotprecision operator |(const dotprecision &,const dotprecision &) throw();
00190 
00192       friend  dotprecision operator +(const dotprecision &,const real &) throw();
00194       friend  dotprecision operator +(const real &,const dotprecision &) throw();
00196       friend  dotprecision operator -(const dotprecision &,const real &) throw();
00198       friend  dotprecision operator -(const real &,const dotprecision &) throw();
00200       friend inline idotprecision operator |(const real &,const dotprecision &) throw();
00202       friend inline idotprecision operator |(const dotprecision &,const real &) throw();
00203 
00205       friend dotprecision & operator +=(dotprecision &,const dotprecision &) throw();
00207       friend dotprecision & operator -=(dotprecision &,const dotprecision &) throw();
00208 
00210       friend dotprecision & operator +=(dotprecision &,const real &) throw();
00212       friend dotprecision & operator -=(dotprecision &,const real &) throw();
00213 
00214       // ---- Comp.Operat. ------------------------------------------
00216       friend bool operator  !(const dotprecision &) throw();
00217 //      operator void *() const throw() { if(sign(*this)) return (void *)1; else return 0;}
00218 
00220       friend bool operator ==(const dotprecision &,const dotprecision &) throw();
00222       friend bool operator !=(const dotprecision &,const dotprecision &) throw();
00224       friend bool operator  <(const dotprecision &,const dotprecision &) throw();
00226       friend bool operator  >(const dotprecision &,const dotprecision &) throw();
00228       friend bool operator <=(const dotprecision &,const dotprecision &) throw();
00230       friend bool operator >=(const dotprecision &,const dotprecision &) throw();
00231 
00233       friend bool operator ==(const real &,const dotprecision &) throw();
00235       friend bool operator !=(const real &,const dotprecision &) throw();
00237       friend bool operator  <(const real &,const dotprecision &) throw();
00239       friend bool operator  >(const real &,const dotprecision &) throw();
00241       friend bool operator <=(const real &,const dotprecision &) throw();
00243       friend bool operator >=(const real &,const dotprecision &) throw();
00244 
00246       friend bool operator ==(const dotprecision &,const real &) throw();
00248       friend bool operator !=(const dotprecision &,const real &) throw();
00250       friend bool operator  <(const dotprecision &,const real &) throw();
00252       friend bool operator  >(const dotprecision &,const real &) throw();
00254       friend bool operator <=(const dotprecision &,const real &) throw();
00256       friend bool operator >=(const dotprecision &,const real &) throw();
00257 
00258       // ---- Others ------------------------------------------------
00260       friend void rnd (const dotprecision&, real&, rndtype) throw();
00262       friend void rnd (const dotprecision&, real&, real&)              throw();
00264       friend void rnd (const dotprecision&, interval&) throw(); // Blomquist
00266       friend real rnd (const dotprecision&, rndtype)        throw();
00267 
00269       friend dotprecision abs(const dotprecision &) throw();
00271       friend int         sign(const dotprecision &) throw();
00273       friend dotprecision & accumulate (dotprecision&, const real&, const real&) throw();
00274 
00276       friend dotprecision & accumulate_approx (dotprecision&, const real&, const real&) throw();
00277 
00278       template<typename S, typename T>
00279       friend INLINE void addDot( dotprecision&, const S&, const T&);
00280       template<typename S, typename T>
00281       friend INLINE void addDot( cdotprecision&, const S&, const T&);
00282       template<typename S, typename T>
00283       friend INLINE void addDot( cidotprecision&, const S&, const T&);
00284 
00285       template<typename S, typename T>
00286       friend INLINE void addDot_op( dotprecision&, const S&, const T&);
00287       template<typename S, typename T>
00288       friend INLINE void addDot_op( cdotprecision&, const S&, const T&);
00289 
00290       template<typename S>
00291       friend INLINE void addSum( dotprecision&, const S&);
00292 
00293 
00294       // ---- internal functions ------------------------------------
00295       inline Dotprecision* ptr() { return &akku; }
00296 
00297 
00298    private:
00299       dotprecision & negdot(void) throw(); // Negates current dotprecision
00300 };
00301 
00302 
00303 
00304       inline dotprecision _dotprecision(const real &d) throw() { return dotprecision(d); }
00305       std::string  & operator <<(std::string &,const dotprecision &) throw();
00306       std::string  & operator >>(std::string &,dotprecision &)       throw();
00307       void           operator >>(const std::string &,dotprecision &) throw();
00308       void           operator >>(const char *,dotprecision &)        throw();
00309       std::ostream & operator <<(std::ostream &,const dotprecision &) throw();
00310       std::istream & operator >>(std::istream &,dotprecision &)      throw();
00311       dotprecision operator -(const dotprecision &) throw();
00312       dotprecision operator +(const dotprecision &) throw();
00313       dotprecision operator +(const dotprecision &,const dotprecision &) throw();
00314       dotprecision operator -(const dotprecision &,const dotprecision &) throw();
00315       inline idotprecision operator |(const dotprecision &,const dotprecision &) throw();
00316       dotprecision operator +(const dotprecision &,const real &) throw();
00317       dotprecision operator +(const real &,const dotprecision &) throw();
00318       dotprecision operator -(const dotprecision &,const real &) throw();
00319       dotprecision operator -(const real &,const dotprecision &) throw();
00320       inline idotprecision operator |(const real &,const dotprecision &) throw();
00321       inline idotprecision operator |(const dotprecision &,const real &) throw();
00322       dotprecision & operator +=(dotprecision &,const dotprecision &) throw();
00323       dotprecision & operator -=(dotprecision &,const dotprecision &) throw();
00324       dotprecision & operator +=(dotprecision &,const real &) throw();
00325       dotprecision & operator -=(dotprecision &,const real &) throw();
00326       bool operator  !(const dotprecision &) throw();
00327       bool operator ==(const dotprecision &,const dotprecision &) throw();
00328       bool operator !=(const dotprecision &,const dotprecision &) throw();
00329       bool operator  <(const dotprecision &,const dotprecision &) throw();
00330       bool operator  >(const dotprecision &,const dotprecision &) throw();
00331       bool operator <=(const dotprecision &,const dotprecision &) throw();
00332       bool operator >=(const dotprecision &,const dotprecision &) throw();
00333       bool operator ==(const real &,const dotprecision &) throw();
00334       bool operator !=(const real &,const dotprecision &) throw();
00335       bool operator  <(const real &,const dotprecision &) throw();
00336       bool operator  >(const real &,const dotprecision &) throw();
00337       bool operator <=(const real &,const dotprecision &) throw();
00338       bool operator >=(const real &,const dotprecision &) throw();
00339       bool operator ==(const dotprecision &,const real &) throw();
00340       bool operator !=(const dotprecision &,const real &) throw();
00341       bool operator  <(const dotprecision &,const real &) throw();
00342       bool operator  >(const dotprecision &,const real &) throw();
00343       bool operator <=(const dotprecision &,const real &) throw();
00344       bool operator >=(const dotprecision &,const real &) throw();
00345       void rnd (const dotprecision&, real&, rndtype = RND_NEXT) throw();
00346       void rnd (const dotprecision&, real&, real&)              throw();
00347       void rnd (const dotprecision&, interval&) throw();
00348       real rnd (const dotprecision&, rndtype = RND_NEXT)        throw();
00349       dotprecision abs(const dotprecision &) throw();
00350       int         sign(const dotprecision &) throw();
00351       dotprecision & accumulate (dotprecision&, const real&, const real&) throw();
00352 
00353 
00354 } // namespace cxsc 
00355 
00356 
00357 #endif // _CXSC_DOT_HPP_INCLUDED