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: interval.hpp,v 1.48 2014/01/30 18:13:52 cxsc Exp $ */ 00025 00026 #ifndef _CXSC_INTERVAL_H_INCLUDED 00027 #define _CXSC_INTERVAL_H_INCLUDED 00028 00029 #include <iostream> 00030 #include <string> 00031 #include "real.hpp" 00032 #include "except.hpp" 00033 00034 namespace cxsc { 00035 00036 class ivector; 00037 class ivector_slice; 00038 class imatrix; 00039 class imatrix_slice; 00040 00041 00043 00054 class interval 00055 { 00056 private: 00057 // ---- Datenelemente --------------------------------------- 00058 real inf; 00059 real sup; 00060 00061 public: 00062 // ---- Konstruktoren --------------------------------------- 00064 interval() {} 00066 inline interval(const real&, const real&) throw(ERROR_INTERVAL_EMPTY_INTERVAL); 00068 inline interval& operator= (const real& a); 00069 00070 // ---- Typecasts --------------------------------------- 00071 00073 explicit inline interval(const real &r) throw() :inf(r),sup(r) { } 00074 00076 friend inline interval _unchecked_interval(const real&, const real&); 00077 00078 #if(CXSC_INDEX_CHECK) 00079 00080 explicit INLINE interval(const ivector &) throw(ERROR_IVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_IVECTOR_USE_OF_UNINITIALIZED_OBJ); 00082 explicit INLINE interval(const ivector_slice &) throw(ERROR_IVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_IVECTOR_USE_OF_UNINITIALIZED_OBJ); 00084 explicit INLINE interval(const imatrix &m) throw(ERROR_IMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_IMATRIX_USE_OF_UNINITIALIZED_OBJ); 00086 explicit INLINE interval(const imatrix_slice &m) throw(ERROR_IMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_IMATRIX_USE_OF_UNINITIALIZED_OBJ); 00088 friend INLINE interval _interval(const ivector &) throw(ERROR_IVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_IVECTOR_USE_OF_UNINITIALIZED_OBJ); 00090 friend INLINE interval _interval(const ivector_slice &) throw(ERROR_IVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_IVECTOR_USE_OF_UNINITIALIZED_OBJ); 00092 friend INLINE interval _interval(const imatrix &m) throw(ERROR_IMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_IMATRIX_USE_OF_UNINITIALIZED_OBJ); 00094 friend INLINE interval _interval(const imatrix_slice &m) throw(ERROR_IMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_IMATRIX_USE_OF_UNINITIALIZED_OBJ); 00095 #else 00096 00097 explicit INLINE interval(const ivector &) throw(); 00099 explicit INLINE interval(const ivector_slice &) throw(); 00101 explicit INLINE interval(const imatrix &m) throw(); 00103 explicit INLINE interval(const imatrix_slice &m) throw(); 00105 friend INLINE interval _interval(const ivector &) throw(); 00107 friend INLINE interval _interval(const ivector_slice &) throw(); 00109 friend INLINE interval _interval(const imatrix &m) throw(); 00111 friend INLINE interval _interval(const imatrix_slice &m) throw(); 00112 #endif 00113 00114 explicit interval(const l_real &) throw(); // in l_real.cpp 00116 interval(const l_real &,const l_real &) throw(ERROR_INTERVAL_EMPTY_INTERVAL); 00118 explicit interval(const l_interval &) throw(); // in l_interval.cpp 00120 explicit interval(const dotprecision &) throw(); 00122 interval(const dotprecision &,const dotprecision &) throw(ERROR_INTERVAL_EMPTY_INTERVAL); 00124 explicit interval(const idotprecision &) throw(); 00125 00127 friend inline interval _interval(const l_real &a) throw(); // in l_interval.inl 00129 friend inline interval _interval(const l_real &a,const l_real &b) throw(ERROR_INTERVAL_EMPTY_INTERVAL) { return interval(a,b); } 00131 friend interval _interval(const l_interval &a) throw(); // in l_interv.inl 00132 // friend inline interval _interval(const dotprecision &a) throw() { return interval(a); } 00133 // friend inline interval _interval(const dotprecision &a,const dotprecision &b) throw(ERROR_INTERVAL_EMPTY_INTERVAL) { return interval(a,b); } 00134 // friend inline interval _interval(const idotprecision &a) throw() { return interval(a); } 00135 00136 // interval & operator= (const interval& a); Default passt 00138 interval & operator =(const l_real &) throw(); 00140 interval & operator =(const l_interval &) throw(); 00142 interval & operator = (const lx_interval &) throw(); 00144 interval & operator =(const dotprecision &) throw(); 00146 interval & operator =(const idotprecision &) throw(); 00147 00148 // ---- Destruktor ---- 00149 // ~interval() {} unnoetig 00150 00151 // ---- Typwandlungen ---- 00152 00153 // ---- Ausgabefunkt. --------------------------------------- 00155 friend std::istream& operator >> (std::istream &, interval &) throw(); 00157 friend std::ostream& operator << (std::ostream &, const interval &) throw(); 00159 friend std::string & operator >> (std::string &, interval &) throw(); 00161 friend std::string & operator << (std::string &, const interval &) throw(); 00163 friend void operator >> (const std::string&,interval &) throw(); 00165 friend void operator >> (const char *,interval &) throw(); 00166 00167 // ---- Standardfunkt ---- (arithmetische Operatoren) 00169 friend inline interval operator -(const interval &) throw(); 00171 friend inline interval operator +(const interval &) throw(); 00172 00174 friend inline interval operator +(const interval &,const interval &) throw(); 00176 friend inline interval operator -(const interval &,const interval &) throw(); 00178 friend inline interval operator *(const interval &,const interval &) throw(); 00180 friend inline interval operator /(const interval &,const interval &) throw(DIV_BY_ZERO); 00182 friend inline interval operator |(const interval &,const interval &) throw(); 00184 friend inline interval operator &(const interval &,const interval &) throw(ERROR_INTERVAL_EMPTY_INTERVAL); 00185 00187 friend inline interval operator +(const interval &,const real &) throw(); 00189 friend inline interval operator +(const real &,const interval &) throw(); 00191 friend inline interval operator -(const interval &,const real &) throw(); 00193 friend inline interval operator -(const real &,const interval &) throw(); 00195 friend inline interval operator *(const interval &,const real &) throw(); 00197 friend inline interval operator *(const real &,const interval &) throw(); 00199 friend inline interval operator /(const interval &,const real &) throw(); 00201 friend inline interval operator /(const real &,const interval &) throw(); 00203 friend inline interval operator |(const real &,const interval &) throw(); 00205 friend inline interval operator |(const interval &,const real &) throw(); 00207 friend inline interval operator |(const real &,const real &) throw(); 00209 friend inline interval operator &(const real &,const interval &) throw(ERROR_INTERVAL_EMPTY_INTERVAL); 00211 friend inline interval operator &(const interval &,const real &) throw(ERROR_INTERVAL_EMPTY_INTERVAL); 00212 00213 00215 friend inline idotprecision operator +(const idotprecision &,const interval &) throw(); 00217 friend inline idotprecision operator +(const interval &,const idotprecision &) throw(); 00219 friend inline idotprecision operator -(const idotprecision &,const interval &) throw(); 00221 friend inline idotprecision operator -(const interval &,const idotprecision &) throw(); 00223 friend inline idotprecision operator |(const interval &,const idotprecision &) throw(); 00225 friend inline idotprecision operator |(const idotprecision &,const interval &) throw(); 00227 friend inline idotprecision operator &(const interval &,const idotprecision &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00229 friend inline idotprecision operator &(const idotprecision &,const interval &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL); 00230 00232 friend inline interval & operator +=(interval &,const interval &) throw(); 00234 friend inline interval & operator -=(interval &,const interval &) throw(); 00236 friend inline interval & operator *=(interval &,const interval &) throw(); 00238 friend inline interval & operator /=(interval &,const interval &) throw(); 00240 friend inline interval & operator |=(interval &,const interval &) throw(); 00242 friend inline interval & operator &=(interval &,const interval &) throw(ERROR_INTERVAL_EMPTY_INTERVAL); 00243 00245 friend inline interval & operator +=(interval &,const real &) throw(); 00247 friend inline interval & operator -=(interval &,const real &) throw(); 00249 friend inline interval & operator *=(interval &,const real &) throw(); 00251 friend inline interval & operator /=(interval &,const real &) throw(); 00253 friend inline interval & operator |=(interval &,const real &) throw(); 00255 friend inline interval & operator &=(interval &,const real &) throw(ERROR_INTERVAL_EMPTY_INTERVAL); 00256 00257 // ---- Vergleichsop. ---- 00258 00260 friend inline bool operator ==(const interval &,const interval &) throw(); 00262 friend inline bool operator !=(const interval &,const interval &) throw(); 00263 00265 friend inline bool operator !(const interval &) throw(); 00266 // inline operator void*(void) const throw() { return (void*)(!(!*this)); } 00267 00269 friend inline bool operator ==(const real &,const interval &) throw(); 00271 friend inline bool operator !=(const real &,const interval &) throw(); 00272 00274 friend inline bool operator ==(const interval &,const real &) throw(); 00276 friend inline bool operator !=(const interval &,const real &) throw(); 00277 00279 friend bool operator ==(const dotprecision &,const interval &) throw(); 00281 friend bool operator !=(const dotprecision &,const interval &) throw(); 00282 00284 friend bool operator ==(const interval &,const dotprecision &) throw(); 00286 friend bool operator !=(const interval &,const dotprecision &) throw(); 00287 00289 friend inline bool operator ==(const int &,const interval &) throw(); 00291 friend inline bool operator !=(const int &,const interval &) throw(); 00292 00294 friend inline bool operator ==(const interval &,const int &) throw(); 00296 friend inline bool operator !=(const interval &,const int &) throw(); 00297 00299 friend inline bool operator ==(const long &,const interval &) throw(); 00301 friend inline bool operator !=(const long &,const interval &) throw(); 00302 00304 friend inline bool operator ==(const interval &,const long &) throw(); 00306 friend inline bool operator !=(const interval &,const long &) throw(); 00307 00309 friend inline bool operator ==(const double &,const interval &) throw(); 00311 friend inline bool operator !=(const double &,const interval &) throw(); 00312 00314 friend inline bool operator ==(const interval &,const double &) throw(); 00316 friend inline bool operator !=(const interval &,const double &) throw(); 00317 00318 // ---- Mengenvergle. ---- 00319 00321 friend inline bool operator <(const interval &,const interval &) throw(); 00323 friend inline bool operator >(const interval &,const interval &) throw(); 00325 friend inline bool operator <=(const interval &,const interval &) throw(); 00327 friend inline bool operator >=(const interval &,const interval &) throw(); 00328 00330 friend inline bool operator <(const real &,const interval &) throw(); 00332 friend inline bool operator >(const real &,const interval &) throw() { return false; } 00334 friend inline bool operator <=(const real &,const interval &) throw(); 00336 friend inline bool operator >=(const real &,const interval &) throw(); 00337 00339 friend inline bool operator <(const interval &,const real &) throw() { return false; } 00341 friend inline bool operator >(const interval &,const real &) throw(); 00343 friend inline bool operator <=(const interval &,const real &) throw(); 00345 friend inline bool operator >=(const interval &,const real &) throw(); 00346 00348 friend bool operator <(const dotprecision &,const interval &) throw(); 00350 friend bool operator >(const dotprecision &,const interval &) throw() { return false; } 00352 friend bool operator <=(const dotprecision &,const interval &) throw(); 00354 friend bool operator >=(const dotprecision &,const interval &) throw(); 00355 00357 friend bool operator <(const interval &,const dotprecision &) throw() { return false; } 00359 friend bool operator >(const interval &,const dotprecision &) throw(); 00361 friend bool operator <=(const interval &,const dotprecision &) throw(); 00363 friend bool operator >=(const interval &,const dotprecision &) throw(); 00364 00365 // ---- Funktionen ---- 00366 00368 friend inline real & Inf (interval &) throw(); 00370 friend inline const real & Inf (const interval &) throw(); 00372 friend inline real & Sup (interval &) throw(); 00374 friend inline const real & Sup (const interval &) throw(); 00375 00377 friend inline interval& SetInf (interval &, const real &) throw(); 00379 friend inline interval& SetSup (interval &, const real &) throw(); 00381 friend inline interval& UncheckedSetInf (interval &, const real &) throw(); 00383 friend inline interval& UncheckedSetSup (interval &, const real &) throw(); 00384 00386 friend inline bool IsEmpty (const interval &) throw(); 00387 00389 friend inline interval abs (const interval &) throw(); 00391 friend real mid (const interval &) throw(); 00392 // Returns the rounded middle of the interval (faster version for tests) 00393 friend real Mid (const interval &) throw(); 00395 friend inline real diam (const interval &) throw(); 00397 friend inline void times2pown(interval &, const int&) throw(); // Blomquist, 28.11.02 00398 }; 00399 00405 inline interval _interval(const real & r) throw() { return interval(r); } 00411 inline interval _interval(const real & a, const real & b) throw(ERROR_INTERVAL_EMPTY_INTERVAL) { return interval(a,b); } 00417 inline interval _interval(const dotprecision &a) throw() { return interval(a); } 00423 inline interval _interval(const dotprecision &a,const dotprecision &b) throw(ERROR_INTERVAL_EMPTY_INTERVAL) { return interval(a,b); } 00429 inline interval _interval(const idotprecision &a) throw() { return interval(a); } 00430 00431 // for compatibility with CToolbox library - from former i_util.hpp 00433 extern int in ( const real&, const interval& ); 00435 extern int in ( const interval&, const interval& ); 00436 //extern void rnd ( const dotprecision&, interval& ); 00438 extern interval Blow ( const interval&, const real& ); 00440 extern int Disjoint ( const interval&, const interval& ); 00442 extern real AbsMin ( const interval& ); 00444 extern real AbsMax ( const interval& ); 00446 extern real RelDiam ( const interval& ); 00448 extern int UlpAcc ( const interval&, int ); 00449 00450 // Additional declaration of friend functions outside class interval 00451 real mid (const interval& a) throw(); 00452 00453 // Interval constants, optimal inclusions: 00455 extern const interval Pi_interval; // Pi 00457 extern const interval Pi2_interval; // 2*Pi 00459 extern const interval Pi3_interval; // 3*Pi 00461 extern const interval Pid2_interval; // Pi/2 00463 extern const interval Pid3_interval; // Pi/3 00465 extern const interval Pid4_interval; // Pi/4 00467 extern const interval Pir_interval; // 1/Pi 00469 extern const interval Pi2r_interval; // 1/(2*Pi) 00471 extern const interval Pip2_interval; // Pi^2 00473 extern const interval SqrtPi_interval; // sqrt(Pi) 00475 extern const interval Sqrt2Pi_interval; // sqrt(2Pi) 00477 extern const interval SqrtPir_interval; // 1/sqrt(Pi) 00479 extern const interval Sqrt2Pir_interval; // 1/sqrt(2Pi) 00481 extern const interval Sqrt2_interval; // sqrt(2) 00483 extern const interval Sqrt5_interval; // sqrt(5) 00485 extern const interval Sqrt7_interval; // sqrt(7) 00487 extern const interval Sqrt2r_interval; // 1/sqrt(2) 00489 extern const interval Sqrt3_interval; // sqrt(3) 00491 extern const interval Sqrt3d2_interval; // sqrt(3)/2 00493 extern const interval Sqrt3r_interval; // 1/sqrt(3) 00495 extern const interval Ln2_interval; // ln(2) 00497 extern const interval Ln2r_interval; // 1/ln(2) 00499 extern const interval Ln10_interval; // ln(10) 00501 extern const interval Ln10r_interval; // 1/ln(10) 00503 extern const interval LnPi_interval; // ln(Pi) 00505 extern const interval Ln2Pi_interval; // ln(2Pi) 00507 extern const interval E_interval; // e 00509 extern const interval Er_interval; // 1/e 00511 extern const interval Ep2_interval; // e^2 00513 extern const interval Ep2r_interval; // 1/e^2 00515 extern const interval EpPi_interval; // e^(Pi) 00517 extern const interval Ep2Pi_interval; // e^(2Pi) 00519 extern const interval EpPid2_interval; // e^(Pi/2) 00521 extern const interval EpPid4_interval; // e^(Pi/4) 00522 00523 00524 } // namespace cxsc 00525 00526 #include "interval.inl" 00527 #include "imath.hpp" 00528 00529 #endif // _CXSC_INTERVAL_H_INCLUDED