00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00058 real inf;
00059 real sup;
00060
00061 public:
00062
00064 interval() {}
00066 inline interval(const real&, const real&) throw(ERROR_INTERVAL_EMPTY_INTERVAL);
00068 inline interval& operator= (const real& a);
00069
00070
00071
00073 explicit inline interval(const real &r) throw() :inf(r),sup(r) { }
00074
00075
00076
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();
00118 interval(const l_real &,const l_real &) throw(ERROR_INTERVAL_EMPTY_INTERVAL);
00120 explicit interval(const l_interval &) throw();
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();
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();
00134
00135
00136
00137
00138
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
00151
00152
00153
00154
00155
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
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
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
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
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
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
00395 friend real Mid (const interval &) throw();
00397 friend inline real diam (const interval &) throw();
00399 friend inline void times2pown(interval &, const int&) throw();
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
00435 extern int in ( const real&, const interval& );
00437 extern int in ( const interval&, const interval& );
00438
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
00453 real mid (const interval& a) throw();
00454
00455
00457 extern const interval Pi_interval;
00459 extern const interval Pi2_interval;
00461 extern const interval Pi3_interval;
00463 extern const interval Pid2_interval;
00465 extern const interval Pid3_interval;
00467 extern const interval Pid4_interval;
00469 extern const interval Pir_interval;
00471 extern const interval Pi2r_interval;
00473 extern const interval Pip2_interval;
00475 extern const interval SqrtPi_interval;
00477 extern const interval Sqrt2Pi_interval;
00479 extern const interval SqrtPir_interval;
00481 extern const interval Sqrt2Pir_interval;
00483 extern const interval Sqrt2_interval;
00485 extern const interval Sqrt5_interval;
00487 extern const interval Sqrt7_interval;
00489 extern const interval Sqrt2r_interval;
00491 extern const interval Sqrt3_interval;
00493 extern const interval Sqrt3d2_interval;
00495 extern const interval Sqrt3r_interval;
00497 extern const interval Ln2_interval;
00499 extern const interval Ln2r_interval;
00501 extern const interval Ln10_interval;
00503 extern const interval Ln10r_interval;
00505 extern const interval LnPi_interval;
00507 extern const interval Ln2Pi_interval;
00509 extern const interval E_interval;
00511 extern const interval Er_interval;
00513 extern const interval Ep2_interval;
00515 extern const interval Ep2r_interval;
00517 extern const interval EpPi_interval;
00519 extern const interval Ep2Pi_interval;
00521 extern const interval EpPid2_interval;
00523 extern const interval EpPid4_interval;
00524
00525
00526 }
00527
00528 #include "interval.inl"
00529 #include "imath.hpp"
00530
00531 #endif // _CXSC_INTERVAL_H_INCLUDED