C-XSC - A C++ Class Library for Extended Scientific Computing
2.5.4
|
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: idot.hpp,v 1.31 2014/01/30 17:23:45 cxsc Exp $ */ 00025 00026 #ifndef _CXSC_IDOT_HPP_INCLUDED 00027 #define _CXSC_IDOT_HPP_INCLUDED 00028 00029 #include <iostream> 00030 #include <string> 00031 #include "dot.hpp" 00032 #include "interval.hpp" 00033 00034 namespace cxsc { 00035 00037 00047 class idotprecision 00048 { 00049 private: 00050 // ---- Datenelemente --------------------------------------- 00051 dotprecision inf,sup; 00052 int k; //precision 00053 00054 public: 00055 // ---- Constructors --------------------------------------- 00057 idotprecision() : k(0) {} 00059 inline idotprecision(const dotprecision&, const dotprecision&) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00061 inline idotprecision(const idotprecision&); 00062 00063 // explicit inline idotprecision(int n) : inf(n), sup(n) { } 00064 // explicit inline idotprecision(int a,int b) : inf(a), sup(b) { } 00065 // explicit inline idotprecision(const float &d) : inf(double(d)), sup(double(d)) { } 00066 // explicit inline idotprecision(const float &a, const float &b) : inf(double(a)), 00067 // sup(double(b)) { } 00068 // explicit inline idotprecision(const double &d) : inf(d), sup(d) { } 00069 // explicit inline idotprecision(const double &a, const double &b) : inf(a), sup(b) { } 00071 explicit inline idotprecision(const real & a) : inf(a), sup(a), k(0) { } 00073 explicit inline idotprecision(const real & a,const real & b) : inf(a), sup(b), k(0) { } 00075 explicit inline idotprecision(const interval & a) : inf(Inf(a)), sup(Sup(a)), k(0) { } 00077 explicit inline idotprecision(const dotprecision &r) : inf(r), sup(r), k(0) { inf.set_k(0); sup.set_k(0); } 00079 explicit idotprecision(const l_real &) throw(); // In l_real.cpp 00081 explicit idotprecision(const l_real &,const l_real &); // in l_real.cpp 00083 explicit idotprecision(const l_interval &) throw(); // In l_interval.cpp 00084 00086 inline int get_k() const { return k; } 00088 inline void set_k(unsigned int i) { k=i; inf.set_k(i); sup.set_k(i); } 00090 inline int get_dotprec() const { return k; } 00092 inline void set_dotprec(unsigned int i) { k=i; inf.set_k(i); sup.set_k(i); } 00093 00094 // inline idotprecision& operator= (const double& a) { inf=sup=a; return *this; } 00096 inline idotprecision& operator= (const real& a) { inf=sup=a; return *this; } 00098 inline idotprecision& operator= (const interval& a) { inf=Inf(a); sup=Sup(a); return *this; } 00099 // inline idotprecision& operator= (const int& a) { inf=sup=a; return *this; } 00101 inline idotprecision& operator= (const dotprecision& a) { inf=sup=a; return *this; } 00103 inline idotprecision& operator= (const idotprecision& a){ inf=a.inf; sup=a.sup; return *this; } 00105 inline idotprecision& operator= (const l_real & a) { inf=sup=a; return *this; } 00107 idotprecision& operator= (const l_interval &) throw(); // in l_interv.cpp 00108 00109 // ---- Destruktor ---- 00110 // ~idotprecision() {} unnoetig 00111 00112 // ---- Typwandlungen ---- 00114 friend inline idotprecision _idotprecision(const real &); 00116 friend inline idotprecision _idotprecision(const real &,const real &); 00118 friend inline idotprecision _unchecked_idotprecision(const real &,const real &); 00120 friend inline idotprecision _idotprecision(const dotprecision&); 00122 friend inline idotprecision _idotprecision(const dotprecision&, const dotprecision&); 00124 friend inline idotprecision _unchecked_idotprecision(const dotprecision&, const dotprecision&); 00125 00127 friend inline idotprecision _idotprecision(const l_real &a) throw() { return idotprecision(a); } 00129 friend inline idotprecision _idotprecision(const l_real &a,const l_real &b) { return idotprecision(a,b); } 00130 00131 00132 // ---- Ausgabefunkt. --------------------------------------- 00134 friend std::istream& operator >> (std::istream& s, idotprecision& a) throw(); 00136 friend std::ostream& operator << (std::ostream& s, const idotprecision& a) throw(); 00138 friend std::string& operator >> (std::string& s, idotprecision& a) throw(); 00140 friend std::string& operator << (std::string& s, const idotprecision& a) throw(); 00142 friend void operator >> (const std::string &s,idotprecision& a) throw(); 00144 friend void operator >> (const char *s ,idotprecision& a) throw(); 00145 00146 // ---- Standardfunkt ---- (arithmetische Operatoren) 00148 friend inline idotprecision operator -(const idotprecision &) throw(); 00150 friend inline idotprecision operator +(const idotprecision &) throw(); 00151 00153 friend inline idotprecision operator +(const idotprecision &,const idotprecision &) throw(); 00155 friend inline idotprecision operator -(const idotprecision &,const idotprecision &) throw(); 00157 friend inline idotprecision operator |(const idotprecision &,const idotprecision &) throw(); 00159 friend inline idotprecision operator &(const idotprecision &,const idotprecision &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00160 00162 friend inline idotprecision operator +(const idotprecision &,const dotprecision &) throw(); 00164 friend inline idotprecision operator +(const dotprecision &,const idotprecision &) throw(); 00166 friend inline idotprecision operator -(const idotprecision &,const dotprecision &) throw(); 00168 friend inline idotprecision operator -(const dotprecision &,const idotprecision &) throw(); 00170 friend inline idotprecision operator |(const dotprecision &,const idotprecision &) throw(); 00172 friend inline idotprecision operator |(const idotprecision &,const dotprecision &) throw(); 00174 friend inline idotprecision operator |(const dotprecision &,const dotprecision &) throw(); 00176 friend inline idotprecision operator &(const dotprecision &,const idotprecision &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00178 friend inline idotprecision operator &(const idotprecision &,const dotprecision &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00179 00181 friend inline idotprecision operator +(const idotprecision &,const long &) throw(); 00183 friend inline idotprecision operator +(const long &,const idotprecision &) throw(); 00185 friend inline idotprecision operator -(const idotprecision &,const long &) throw(); 00187 friend inline idotprecision operator -(const long &,const idotprecision &) throw(); 00189 friend inline idotprecision operator |(const long &,const idotprecision &) throw(); 00191 friend inline idotprecision operator |(const idotprecision &,const long &) throw(); 00193 friend inline idotprecision operator &(const long &,const idotprecision &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00195 friend inline idotprecision operator &(const idotprecision &,const long &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00196 00198 friend inline idotprecision operator +(const idotprecision &,const real &) throw(); 00200 friend inline idotprecision operator +(const real &,const idotprecision &) throw(); 00202 friend inline idotprecision operator -(const idotprecision &,const real &) throw(); 00204 friend inline idotprecision operator -(const real &,const idotprecision &) throw(); 00206 friend inline idotprecision operator |(const real &,const idotprecision &) throw(); 00208 friend inline idotprecision operator |(const idotprecision &,const real &) throw(); 00210 friend inline idotprecision operator &(const real &,const idotprecision &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00212 friend inline idotprecision operator &(const idotprecision &,const real &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00213 00215 friend idotprecision operator +(const idotprecision &,const l_real &) throw(); 00217 friend idotprecision operator +(const l_real &,const idotprecision &) throw(); 00219 friend idotprecision operator -(const idotprecision &,const l_real &) throw(); 00221 friend idotprecision operator -(const l_real &,const idotprecision &) throw(); 00223 friend idotprecision operator |(const l_real &,const idotprecision &) throw(); 00225 friend idotprecision operator |(const idotprecision &,const l_real &) throw(); 00227 friend idotprecision operator &(const l_real &,const idotprecision &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00229 friend idotprecision operator &(const idotprecision &,const l_real &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00230 00232 friend inline idotprecision operator +(const idotprecision &,const interval &) throw(); 00234 friend inline idotprecision operator +(const interval &,const idotprecision &) throw(); 00236 friend inline idotprecision operator -(const idotprecision &,const interval &) throw(); 00238 friend inline idotprecision operator -(const interval &,const idotprecision &) throw(); 00240 friend inline idotprecision operator |(const interval &,const idotprecision &) throw(); 00242 friend inline idotprecision operator |(const idotprecision &,const interval &) throw(); 00244 friend inline idotprecision operator &(const interval &,const idotprecision &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00246 friend inline idotprecision operator &(const idotprecision &,const interval &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00247 00249 friend inline idotprecision & operator +=(idotprecision &,const idotprecision &) throw(); 00251 friend inline idotprecision & operator -=(idotprecision &,const idotprecision &) throw(); 00253 friend inline idotprecision & operator +=(idotprecision &,const interval &) throw(); 00255 friend inline idotprecision & operator -=(idotprecision &,const interval &) throw(); 00257 friend inline idotprecision & operator +=(idotprecision &,const real &) throw(); 00259 friend inline idotprecision & operator -=(idotprecision &,const real &) throw(); 00261 friend idotprecision & operator +=(idotprecision &,const l_real &) throw(); 00263 friend idotprecision & operator -=(idotprecision &,const l_real &) throw(); 00265 friend inline idotprecision & operator +=(idotprecision &,const l_interval &) throw(); 00267 friend inline idotprecision & operator -=(idotprecision &,const l_interval &) throw(); 00268 00270 friend inline idotprecision & operator |=(idotprecision &,const idotprecision &) throw(); 00272 friend inline idotprecision & operator &=(idotprecision &,const idotprecision &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00273 00275 friend inline idotprecision & operator +=(idotprecision &,const dotprecision &) throw(); 00277 friend inline idotprecision & operator -=(idotprecision &,const dotprecision &) throw(); 00278 00280 friend inline idotprecision & operator |=(idotprecision &,const dotprecision &) throw(); 00282 friend inline idotprecision & operator &=(idotprecision &,const dotprecision &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00283 00284 // friend inline idotprecision & operator |=(idotprecision & i,const long & l) throw() { return i|=_dotprecision(l); } 00285 // friend inline idotprecision & operator &=(idotprecision & i,const long & l) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL) { return i&=_dotprecision(l); } 00287 friend inline idotprecision & operator |=(idotprecision & i,const real & l) throw() { return i|=dotprecision(l); } 00289 friend inline idotprecision & operator &=(idotprecision & i,const real & l) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL) { return i&=dotprecision(l); } 00290 00292 friend idotprecision & operator |=(idotprecision & i,const l_real & l) throw(); // in l_real.cpp 00294 friend idotprecision & operator &=(idotprecision & i,const l_real & l) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); // in l_real.cpp 00295 00297 friend inline idotprecision & operator |=(idotprecision & i,const l_interval & l) throw(); // in l_interv.inl 00299 friend inline idotprecision & operator &=(idotprecision & i,const l_interval & l) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); // in l_interv.inl 00300 00301 // ---- Vergleichsop. ---- 00302 00304 friend inline bool operator ==(const idotprecision &,const idotprecision &) throw(); 00306 friend inline bool operator !=(const idotprecision &,const idotprecision &) throw(); 00307 00309 friend inline bool operator ==(const dotprecision &,const idotprecision &) throw(); 00311 friend inline bool operator !=(const dotprecision &,const idotprecision &) throw(); 00312 00314 friend inline bool operator ==(const idotprecision &,const dotprecision &) throw(); 00316 friend inline bool operator !=(const idotprecision &,const dotprecision &) throw(); 00317 00319 friend inline bool operator ==(const real &,const idotprecision &) throw(); 00321 friend inline bool operator !=(const real &,const idotprecision &) throw(); 00322 00324 friend inline bool operator ==(const idotprecision &,const real &) throw(); 00326 friend inline bool operator !=(const idotprecision &,const real &) throw(); 00327 00329 friend inline bool operator ==(const interval &,const idotprecision &) throw(); 00331 friend inline bool operator !=(const interval &,const idotprecision &) throw(); 00332 00334 friend inline bool operator ==(const idotprecision &,const interval &) throw(); 00336 friend inline bool operator !=(const idotprecision &,const interval &) throw(); 00337 00338 // ---- Mengenvergle. ---- 00339 00341 friend inline bool operator <(const idotprecision &,const idotprecision &) throw(); 00343 friend inline bool operator >(const idotprecision &,const idotprecision &) throw(); 00345 friend inline bool operator <=(const idotprecision &,const idotprecision &) throw(); 00347 friend inline bool operator >=(const idotprecision &,const idotprecision &) throw(); 00348 00350 friend inline bool operator <(const dotprecision &,const idotprecision &) throw(); 00352 friend inline bool operator >(const dotprecision &,const idotprecision &) throw() { return false; } 00354 friend inline bool operator <=(const dotprecision &,const idotprecision &) throw(); 00356 friend inline bool operator >=(const dotprecision &,const idotprecision &) throw(); 00357 00359 friend inline bool operator <(const idotprecision &,const dotprecision &) throw() { return false; } 00361 friend inline bool operator >(const idotprecision &,const dotprecision &) throw(); 00363 friend inline bool operator <=(const idotprecision &,const dotprecision &) throw(); 00365 friend inline bool operator >=(const idotprecision &,const dotprecision &) throw(); 00366 00368 friend inline bool operator <(const real &,const idotprecision &) throw(); 00370 friend inline bool operator >(const real &,const idotprecision &) throw() { return false; } 00372 friend inline bool operator <=(const real &,const idotprecision &) throw(); 00374 friend inline bool operator >=(const real &,const idotprecision &) throw(); 00375 00377 friend inline bool operator <(const idotprecision &,const real &) throw() { return false; } 00379 friend inline bool operator >(const idotprecision &,const real &) throw(); 00381 friend inline bool operator <=(const idotprecision &,const real &) throw(); 00383 friend inline bool operator >=(const idotprecision &,const real &) throw(); 00384 00386 friend inline bool operator <(const interval &,const idotprecision &) throw(); 00388 friend inline bool operator >(const interval &,const idotprecision &) throw(); 00390 friend inline bool operator <=(const interval &,const idotprecision &) throw(); 00392 friend inline bool operator >=(const interval &,const idotprecision &) throw(); 00393 00395 friend inline bool operator <(const idotprecision &,const interval &) throw(); 00397 friend inline bool operator >(const idotprecision &,const interval &) throw(); 00399 friend inline bool operator <=(const idotprecision &,const interval &) throw(); 00401 friend inline bool operator >=(const idotprecision &,const interval &) throw(); 00402 00404 friend inline bool operator !(const idotprecision&) throw(); 00405 // operator void *(void) throw() { return (void *)(!*this); } 00406 00407 // ---- Funktionen ---- 00408 00410 friend dotprecision & Inf(idotprecision& a) throw() { return a.inf; } 00412 friend dotprecision & Sup(idotprecision& a) throw() { return a.sup; } 00414 friend const dotprecision & Inf(const idotprecision& a) throw() { return a.inf; } 00416 friend const dotprecision & Sup(const idotprecision& a) throw() { return a.sup; } 00417 00419 friend inline idotprecision& SetInf (idotprecision &, const dotprecision &) throw(); 00421 friend inline idotprecision& SetSup (idotprecision &, const dotprecision &) throw(); 00423 friend inline idotprecision& SetInf (idotprecision &, const real &) throw(); 00425 friend inline idotprecision& SetSup (idotprecision &, const real &) throw(); 00427 friend inline idotprecision& UncheckedSetInf (idotprecision &, const dotprecision &) throw(); 00429 friend inline idotprecision& UncheckedSetSup (idotprecision &, const dotprecision &) throw(); 00431 friend inline idotprecision& UncheckedSetInf (idotprecision &, const real &) throw(); 00433 friend inline idotprecision& UncheckedSetSup (idotprecision &, const real &) throw(); 00434 00436 friend inline bool IsEmpty (const idotprecision& a) throw(); 00437 00439 friend inline idotprecision abs (const idotprecision& a) throw(); 00441 friend inline dotprecision mid (const idotprecision& a) throw(); 00443 friend inline dotprecision diam (const idotprecision& a) throw(); 00444 00445 friend void rnd(const idotprecision &,interval &) throw(); 00446 friend interval rnd(const idotprecision &) throw(); 00447 00449 friend void accumulate (idotprecision&, const interval&, const interval&) throw(); 00451 friend inline void accumulate (idotprecision&, const interval&, const real&) throw(); 00453 friend inline void accumulate (idotprecision&, const real&, const interval&) throw(); 00455 friend inline void accumulate (idotprecision&, const real&, const real&) throw(); 00456 }; 00457 00458 //---------------------------------------------------------------------- 00459 // global verfuegbare IDotprecision Akku's 00460 00461 //#define MAXIDOTAKKU 3 00462 //extern idotprecision idotakku[MAXIDOTAKKU]; 00463 00464 //---------------------------------------------------------------------- 00465 00466 } // namespace cxsc 00467 00468 #include "idot.inl" 00469 00470 #endif 00471