interval.hpp

00001 /*
00002 **  CXSC is a C++ library for eXtended Scientific Computing (V 2.5.1)
00003 **
00004 **  Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
00005 **                          Universitaet Karlsruhe, Germany
00006 **            (C) 2000-2011 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.43 2011/06/07 15:17:39 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       
00075 //      friend inline interval _interval(const real & r) throw()                            { return interval(r); }
00076 //      friend inline interval _interval(const real & a, const real & b) throw(ERROR_INTERVAL_EMPTY_INTERVAL) { return interval(a,b); }
00078       friend inline interval _unchecked_interval(const real&, const real&);
00079 
00080 #if(CXSC_INDEX_CHECK)
00081 
00082       explicit INLINE interval(const ivector &) throw(ERROR_IVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_IVECTOR_USE_OF_UNINITIALIZED_OBJ);
00084       explicit INLINE interval(const ivector_slice &) throw(ERROR_IVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_IVECTOR_USE_OF_UNINITIALIZED_OBJ);
00086       explicit INLINE interval(const imatrix &m) throw(ERROR_IMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_IMATRIX_USE_OF_UNINITIALIZED_OBJ);
00088       explicit INLINE interval(const imatrix_slice &m) throw(ERROR_IMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_IMATRIX_USE_OF_UNINITIALIZED_OBJ);
00090       friend INLINE interval _interval(const ivector &) throw(ERROR_IVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_IVECTOR_USE_OF_UNINITIALIZED_OBJ);
00092       friend INLINE interval _interval(const ivector_slice &) throw(ERROR_IVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_IVECTOR_USE_OF_UNINITIALIZED_OBJ);
00094       friend INLINE interval _interval(const imatrix &m) throw(ERROR_IMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_IMATRIX_USE_OF_UNINITIALIZED_OBJ);
00096       friend INLINE interval _interval(const imatrix_slice &m) throw(ERROR_IMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_IMATRIX_USE_OF_UNINITIALIZED_OBJ);
00097 #else
00098 
00099       explicit INLINE interval(const ivector &) throw();
00101       explicit INLINE interval(const ivector_slice &) throw();
00103       explicit INLINE interval(const imatrix &m) throw();
00105       explicit INLINE interval(const imatrix_slice &m) throw();
00107       friend INLINE interval _interval(const ivector &) throw();
00109       friend INLINE interval _interval(const ivector_slice &) throw();
00111       friend INLINE interval _interval(const imatrix &m) throw();
00113       friend INLINE interval _interval(const imatrix_slice &m) throw();
00114 #endif
00115 
00116       explicit        interval(const l_real &) throw();     // in l_real.cpp
00118                       interval(const l_real &,const l_real &) throw(ERROR_INTERVAL_EMPTY_INTERVAL);
00120       explicit        interval(const l_interval &) throw(); // in l_interval.cpp
00122       explicit        interval(const dotprecision &) throw();
00124                       interval(const dotprecision &,const dotprecision &) throw(ERROR_INTERVAL_EMPTY_INTERVAL);
00126       explicit        interval(const idotprecision &) throw();
00127       
00129       friend inline interval _interval(const l_real &a) throw(); // in l_interval.inl
00131       friend inline interval _interval(const l_real &a,const l_real &b) throw(ERROR_INTERVAL_EMPTY_INTERVAL) { return interval(a,b); }
00133       friend        interval _interval(const l_interval &a) throw(); // in l_interv.inl
00134 //      friend inline interval _interval(const dotprecision &a) throw() { return interval(a); } 
00135 //      friend inline interval _interval(const dotprecision &a,const dotprecision &b) throw(ERROR_INTERVAL_EMPTY_INTERVAL) { return interval(a,b); }
00136 //      friend inline interval _interval(const idotprecision &a) throw() { return interval(a); }
00137       
00138       // interval & operator= (const interval& a); Default passt
00140       interval & operator =(const l_real &) throw();
00142       interval & operator =(const l_interval &) throw();
00144       interval & operator = (const lx_interval &) throw();
00146       interval & operator =(const dotprecision &) throw();
00148       interval & operator =(const idotprecision &) throw();
00149 
00150       // ---- Destruktor    ----
00151       // ~interval() {} unnoetig
00152 
00153       // ---- Typwandlungen ----
00154       
00155       // ---- Ausgabefunkt. ---------------------------------------
00157       friend std::istream& operator >> (std::istream &, interval &)       throw();
00159       friend std::ostream& operator << (std::ostream &, const interval &) throw();
00161       friend std::string & operator >> (std::string &, interval &)       throw();
00163       friend std::string & operator << (std::string &, const interval &) throw();         
00165       friend void          operator >> (const std::string&,interval &)   throw();
00167       friend void          operator >> (const char *,interval &)   throw();      
00168 
00169       // ---- Standardfunkt ---- (arithmetische Operatoren)
00171       friend     inline interval operator -(const interval &) throw();
00173       friend     inline interval operator +(const interval &) throw();
00174 
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();
00182       friend     inline interval operator /(const interval &,const interval &) throw(DIV_BY_ZERO);
00184       friend     inline interval operator |(const interval &,const interval &) throw();
00186       friend     inline interval operator &(const interval &,const interval &) throw(ERROR_INTERVAL_EMPTY_INTERVAL);
00187 
00189       friend     inline interval operator +(const interval &,const real &) throw();
00191       friend     inline interval operator +(const real &,const interval &) throw();
00193       friend     inline interval operator -(const interval &,const real &) throw();
00195       friend     inline interval operator -(const real &,const interval &) throw();
00197       friend     inline interval operator *(const interval &,const real &) throw();
00199       friend     inline interval operator *(const real &,const interval &) throw();
00201       friend     inline interval operator /(const interval &,const real &) throw();
00203       friend     inline interval operator /(const real &,const interval &) throw();
00205       friend     inline interval operator |(const real &,const interval &) throw();
00207       friend     inline interval operator |(const interval &,const real &) throw();
00209       friend     inline interval operator |(const real &,const real &)     throw();
00211       friend     inline interval operator &(const real &,const interval &) throw(ERROR_INTERVAL_EMPTY_INTERVAL);
00213       friend     inline interval operator &(const interval &,const real &) throw(ERROR_INTERVAL_EMPTY_INTERVAL);
00214 
00215 
00217       friend     inline idotprecision operator +(const idotprecision &,const interval &) throw();
00219       friend     inline idotprecision operator +(const interval &,const idotprecision &) throw();
00221       friend     inline idotprecision operator -(const idotprecision &,const interval &) throw();
00223       friend     inline idotprecision operator -(const interval &,const idotprecision &) throw();
00225       friend     inline idotprecision operator |(const interval &,const idotprecision &) throw();
00227       friend     inline idotprecision operator |(const idotprecision &,const interval &) throw();
00229       friend     inline idotprecision operator &(const interval &,const idotprecision &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL);
00231       friend     inline idotprecision operator &(const idotprecision &,const interval &) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL);
00232  
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();
00244       friend     inline interval & operator &=(interval &,const interval &) throw(ERROR_INTERVAL_EMPTY_INTERVAL);
00245 
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();
00257       friend     inline interval & operator &=(interval &,const real &) throw(ERROR_INTERVAL_EMPTY_INTERVAL);
00258  
00259       // ---- Vergleichsop. ----
00260 
00262       friend inline bool operator ==(const interval &,const interval &) throw();
00264       friend inline bool operator !=(const interval &,const interval &) throw();
00265 
00267       friend inline bool operator !(const interval &) throw();
00268 //             inline      operator void*(void) const throw() { return (void*)(!(!*this)); } 
00269 
00271       friend inline bool operator ==(const real &,const interval &) throw();
00273       friend inline bool operator !=(const real &,const interval &) throw();
00274 
00276       friend inline bool operator ==(const interval &,const real &) throw();
00278       friend inline bool operator !=(const interval &,const real &) throw();
00279 
00281       friend        bool operator ==(const dotprecision &,const interval &) throw();
00283       friend        bool operator !=(const dotprecision &,const interval &) throw();
00284 
00286       friend        bool operator ==(const interval &,const dotprecision &) throw();
00288       friend        bool operator !=(const interval &,const dotprecision &) throw();
00289 
00291       friend inline bool operator ==(const int &,const interval &) throw();
00293       friend inline bool operator !=(const int &,const interval &) throw();
00294 
00296       friend inline bool operator ==(const interval &,const int &) throw();
00298       friend inline bool operator !=(const interval &,const int &) throw();
00299  
00301       friend inline bool operator ==(const long &,const interval &) throw();
00303       friend inline bool operator !=(const long &,const interval &) throw();
00304 
00306       friend inline bool operator ==(const interval &,const long &) throw();
00308       friend inline bool operator !=(const interval &,const long &) throw();
00309 
00311       friend inline bool operator ==(const double &,const interval &) throw();
00313       friend inline bool operator !=(const double &,const interval &) throw();
00314 
00316       friend inline bool operator ==(const interval &,const double &) throw();
00318       friend inline bool operator !=(const interval &,const double &) throw();
00319 
00320       // ---- Mengenvergle. ----
00321 
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();
00329       friend inline bool operator >=(const interval &,const interval &) throw();
00330 
00332       friend inline bool operator  <(const real &,const interval &) throw();
00334       friend inline bool operator  >(const real &,const interval &) throw() { return false; }
00336       friend inline bool operator <=(const real &,const interval &) throw();
00338       friend inline bool operator >=(const real &,const interval &) throw();
00339 
00341       friend inline bool operator  <(const interval &,const real &) throw() { return false; }
00343       friend inline bool operator  >(const interval &,const real &) throw();
00345       friend inline bool operator <=(const interval &,const real &) throw();
00347       friend inline bool operator >=(const interval &,const real &) throw();
00348 
00350       friend        bool operator  <(const dotprecision &,const interval &) throw();
00352       friend        bool operator  >(const dotprecision &,const interval &) throw() { return false; }
00354       friend        bool operator <=(const dotprecision &,const interval &) throw();
00356       friend        bool operator >=(const dotprecision &,const interval &) throw();
00357 
00359       friend        bool operator  <(const interval &,const dotprecision &) throw() { return false; }
00361       friend        bool operator  >(const interval &,const dotprecision &) throw();
00363       friend        bool operator <=(const interval &,const dotprecision &) throw();
00365       friend        bool operator >=(const interval &,const dotprecision &) throw();
00366 
00367       // ---- Funktionen    ----
00368       
00370       friend inline       real & Inf (interval &)       throw();
00372       friend inline const real & Inf (const interval &) throw();
00374       friend inline       real & Sup (interval &)       throw();
00376       friend inline const real & Sup (const interval &) throw();
00377       
00379       friend inline interval& SetInf (interval &, const real &) throw();
00381       friend inline interval& SetSup (interval &, const real &) throw();
00383       friend inline interval& UncheckedSetInf (interval &, const real &) throw();
00385       friend inline interval& UncheckedSetSup (interval &, const real &) throw();
00386 
00388       friend inline bool IsEmpty (const interval &) throw();
00389 
00391       friend inline interval abs  (const interval &) throw();
00393       friend        real     mid  (const interval &) throw();     
00394       // Returns the rounded middle of the interval (faster version for tests)
00395       friend        real     Mid  (const interval &) throw();     
00397       friend inline real     diam (const interval &) throw();     
00399       friend inline void times2pown(interval &, const int&) throw(); // Blomquist, 28.11.02
00400 };
00401 
00407 inline interval _interval(const real & r) throw() { return interval(r); }
00413 inline interval _interval(const real & a, const real & b) throw(ERROR_INTERVAL_EMPTY_INTERVAL) { return interval(a,b); }
00419 inline interval _interval(const dotprecision &a) throw() { return interval(a); }
00425 inline interval _interval(const dotprecision &a,const dotprecision &b) throw(ERROR_INTERVAL_EMPTY_INTERVAL) { return interval(a,b); }
00431 inline interval _interval(const idotprecision &a) throw() { return interval(a); }
00432 
00433 // for compatibility with CToolbox library - from former i_util.hpp
00435 extern int      in         ( const real&, const interval& );
00437 extern int      in         ( const interval&, const interval& );
00438 //extern void     rnd        ( const dotprecision&, interval& );
00440 extern interval Blow       ( const interval&, const real& );
00442 extern int      Disjoint   ( const interval&, const interval& );
00444 extern real     AbsMin     ( const interval& );
00446 extern real     AbsMax     ( const interval& );
00448 extern real     RelDiam    ( const interval& );
00450 extern int      UlpAcc     ( const interval&, int );
00451 
00452 // Additional declaration of friend functions outside class interval
00453 real     mid  (const interval& a) throw();        
00454 
00455 // Interval constants, optimal inclusions:
00457 extern const interval Pi_interval;        // Pi
00459 extern const interval Pi2_interval;       // 2*Pi
00461 extern const interval Pi3_interval;       // 3*Pi
00463 extern const interval Pid2_interval;      // Pi/2
00465 extern const interval Pid3_interval;      // Pi/3
00467 extern const interval Pid4_interval;      // Pi/4
00469 extern const interval Pir_interval;       // 1/Pi
00471 extern const interval Pi2r_interval;      // 1/(2*Pi)
00473 extern const interval Pip2_interval;      // Pi^2
00475 extern const interval SqrtPi_interval;    // sqrt(Pi)
00477 extern const interval Sqrt2Pi_interval;   // sqrt(2Pi)
00479 extern const interval SqrtPir_interval;   // 1/sqrt(Pi)
00481 extern const interval Sqrt2Pir_interval;  // 1/sqrt(2Pi)
00483 extern const interval Sqrt2_interval;     // sqrt(2)
00485 extern const interval Sqrt5_interval;     // sqrt(5)
00487 extern const interval Sqrt7_interval;     // sqrt(7)
00489 extern const interval Sqrt2r_interval;    // 1/sqrt(2)
00491 extern const interval Sqrt3_interval;     // sqrt(3)
00493 extern const interval Sqrt3d2_interval;   // sqrt(3)/2
00495 extern const interval Sqrt3r_interval;    // 1/sqrt(3)
00497 extern const interval Ln2_interval;       // ln(2)
00499 extern const interval Ln2r_interval;      // 1/ln(2)
00501 extern const interval Ln10_interval;      // ln(10)
00503 extern const interval Ln10r_interval;     // 1/ln(10)
00505 extern const interval LnPi_interval;      // ln(Pi)
00507 extern const interval Ln2Pi_interval;     // ln(2Pi)
00509 extern const interval E_interval;         // e
00511 extern const interval Er_interval;        // 1/e
00513 extern const interval Ep2_interval;       // e^2
00515 extern const interval Ep2r_interval;      // 1/e^2
00517 extern const interval EpPi_interval;      // e^(Pi)
00519 extern const interval Ep2Pi_interval;     // e^(2Pi)
00521 extern const interval EpPid2_interval;    // e^(Pi/2)
00523 extern const interval EpPid4_interval;    // e^(Pi/4)
00524 
00525 
00526 } // namespace cxsc 
00527 
00528 #include "interval.inl"
00529 #include "imath.hpp"
00530 
00531 #endif // _CXSC_INTERVAL_H_INCLUDED

Generated on Thu Jun 9 11:20:46 2011 for C-XSC - A C++ Class Library for Extended Scientific Computing by  doxygen 1.4.6