C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
lx_interval.inl
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: lx_interval.inl,v 1.8 2014/01/30 17:23:47 cxsc Exp $ */
00025 
00026 /*
00027 **  F. Blomquist, University of Wuppertal, 19.09.2007;
00028 */
00029 
00030 namespace cxsc {
00031         
00032 
00033 // --------------------------------------------------------------------------
00034 // ------ Inline functions and operators related to type lx_interval --------
00035 // --------------------------------------------------------------------------
00036 
00037 inline int StagPrec(const lx_interval &a) throw() 
00038 { return StagPrec(a.li); }
00039 
00040 inline real expo(const lx_interval &a) throw()
00041 { return (a.ex); }
00042 
00043 inline l_interval li_part(const lx_interval &a) throw()
00044 { return (a.li); }
00045 
00046 inline int Disjoint(const lx_interval& a, const lx_interval& b)
00047 { return (Inf(a)>Sup(b) || Inf(b)>Sup(a)); }
00048 
00049 inline int in(const lx_interval& x, const lx_interval& y) 
00050 { return ( (Inf(y) < Inf(x)) && (Sup(x) < Sup(y)) ); }
00051 
00052 inline int in(const l_interval& x, const lx_interval& y) 
00053 { return ( (Inf(y) < Inf(x)) && (Sup(x) < Sup(y)) ); }
00054 
00055 inline int in(const interval& x, const lx_interval& y) 
00056 { return ( (Inf(y) < Inf(x)) && (Sup(x) < Sup(y)) ); }
00057 
00058 inline int in(const lx_real& x, const lx_interval& y ) 
00059 { return ( (Inf(y) <= x) && (x <= Sup(y)) ); }
00060 
00061 inline int in(const l_real& x, const lx_interval& y ) 
00062 { return ( (Inf(y) <= x) && (x <= Sup(y)) ); }
00063 
00064 inline int in(const real& x, const lx_interval& y ) 
00065 { return ( (Inf(y) <= x) && (x <= Sup(y)) ); }
00066 
00067 inline lx_interval Blow(const lx_interval& a) throw()
00068 // This function returns an inflated interval res,
00069 // if the following condition is complied:
00070 //      expo(a) < -Max_Int_R + 2100 = Max_Int_N;
00071 // After the inflation it holds: 
00072 //      expo(a) = -Max_Int_R + 2100;
00073 // a = [0,0] is not modified.
00074 // Blomquist, 31.01.2008;
00075 {
00076     lx_interval res(a);
00077     l_interval al(a.li);
00078 
00079     if (a.ex<Max_Int_N)
00080     {
00081         if (Inf(al)>0)
00082             SetInf(al,0.0);
00083         else
00084             if (Sup(al)<0)
00085                 SetSup(al,0.0);
00086         res = lx_interval(Max_Int_N,al);
00087     }
00088 
00089     return res;
00090 }
00091 
00092 inline lx_interval Blow( const lx_interval& x, const real& eps )
00093 {
00094     l_interval y(li_part(x));
00095     return lx_interval( expo(x), Blow(y,eps) );
00096 }
00097 
00098 inline lx_real AbsMin (const lx_interval &x)
00099 {
00100    if ( in(0.0,x) ) return lx_real(0.0);
00101    else 
00102    { 
00103        lx_real y(Inf(x));
00104        if (y > 0.0) return y;
00105        else return -Sup(x);
00106    }
00107 }
00108   
00109 inline lx_real AbsMax (const lx_interval &x)
00110 { 
00111     lx_real a, b;
00112 
00113     a = abs(Inf(x));
00114     b = abs(Sup(x));
00115 
00116     if (a > b)
00117         return a;
00118     else
00119         return b;
00120 }
00121 
00122 inline lx_interval & lx_interval::operator = (const lx_interval &a) throw()
00123 {
00124     ex = a.ex;
00125     li = a.li;
00126     return *this;
00127 } 
00128 
00129 inline lx_interval & lx_interval::operator = (const lx_real &a) throw()
00130 {
00131     ex = expo(a);
00132     li = lr_part(a);
00133     return *this;
00134 } 
00135 
00136 inline lx_interval & lx_interval::operator = (const l_interval &a) throw()
00137 {
00138     ex = 0;
00139     li = a;
00140     return *this;
00141 }
00142 
00143 inline lx_interval & lx_interval::operator = (const l_real & a) throw()
00144 {
00145     ex = 0;
00146     li = a;
00147     return *this;
00148 }
00149 
00150 inline lx_interval & lx_interval::operator = (const real & a) throw()
00151 {
00152     ex = 0;
00153     li = a;
00154     return *this;
00155 }
00156 
00157 inline lx_interval & lx_interval::operator = (const interval & a) throw()
00158 {
00159     ex = 0;
00160     li = a;
00161     return *this;
00162 } 
00163 
00164 inline lx_interval operator+(const lx_interval & a) throw() { return a; }
00165 inline lx_interval operator-(const lx_interval & a) throw()
00166 {  return lx_interval(a.ex,-a.li);  }
00167 
00168 inline lx_interval operator + (const lx_interval &a, const l_interval &b) throw()
00169 {  return a + lx_interval(b); }
00170 
00171 inline lx_interval operator + (const l_interval &a, const lx_interval &b) throw()
00172 {  return lx_interval(a) + b; }
00173 
00174 inline lx_interval operator + (const lx_interval &a, const l_real &b) throw()
00175 {  return a + lx_interval(b); }
00176 
00177 inline lx_interval operator + (const l_real &a, const lx_interval &b) throw()
00178 {  return lx_interval(a) + b; }
00179 
00180 inline lx_interval operator + (const lx_interval &a, const lx_real &b) throw()
00181 {  return a + lx_interval(b); }
00182 
00183 inline lx_interval operator + (const lx_real &a, const lx_interval &b) throw()
00184 {  return lx_interval(a) + b; }
00185 
00186 inline lx_interval operator + (const lx_interval &a, const real &b) throw()
00187 {  return a + lx_interval(b); }
00188 
00189 inline lx_interval operator + (const real &a, const lx_interval &b) throw()
00190 {  return lx_interval(a) + b; }
00191 
00192 inline lx_interval operator + (const lx_interval &a, const interval &b) throw()
00193 {  return a + lx_interval(b); }
00194 
00195 inline lx_interval operator + (const interval &a, const lx_interval &b) throw()
00196 {  return lx_interval(a) + b; }
00197 
00198 inline lx_interval & operator +=(lx_interval &a, const lx_interval &b) throw()
00199 {  return a = a+b; }
00200 
00201 inline lx_interval & operator +=(lx_interval &a, const l_interval &b) throw()
00202 {  return a = a+b; }
00203 
00204 inline lx_interval & operator +=(lx_interval &a, const l_real &b) throw()
00205 {  return a = a+b; }
00206 
00207 inline lx_interval & operator +=(lx_interval &a, const lx_real &b) throw()
00208 {  return a = a+b; }
00209 
00210 inline lx_interval & operator +=(lx_interval &a, const real &b) throw()
00211 {  return a = a+b; }
00212 
00213 inline lx_interval & operator +=(lx_interval &a, const interval &b) throw()
00214 {  return a = a+b; }
00215 
00216 inline lx_interval operator - (const lx_interval &a, const lx_interval &b) throw()
00217 {  return a + lx_interval(-b); }
00218 
00219 inline lx_interval operator - (const lx_interval &a, const l_interval &b) throw()
00220 {  return a + lx_interval(-b); }
00221 
00222 inline lx_interval operator - (const l_interval &a, const lx_interval &b) throw()
00223 {  return lx_interval(a) + (-b); }
00224  
00225 inline lx_interval operator - (const lx_interval &a, const l_real &b) throw()
00226 {  return a + lx_interval(-b); }
00227 
00228 inline lx_interval operator - (const l_real &a, const lx_interval &b) throw()
00229 {  return lx_interval(a) + (-b); }
00230 
00231 inline lx_interval operator - (const lx_interval &a, const lx_real &b) throw()
00232 {  return a + lx_interval(-b); }
00233 
00234 inline lx_interval operator - (const lx_real &a, const lx_interval &b) throw()
00235 {  return lx_interval(a) + (-b); }
00236  
00237 inline lx_interval operator - (const lx_interval &a, const real &b) throw()
00238 {  return a + lx_interval(-b); }
00239 
00240 inline lx_interval operator - (const real &a, const lx_interval &b) throw()
00241 {  return lx_interval(a) + (-b); }
00242 
00243 inline lx_interval operator - (const lx_interval &a, const interval &b) throw()
00244 {  return a + lx_interval(-b); }
00245 
00246 inline lx_interval operator - (const interval &a, const lx_interval &b) throw()
00247 {  return lx_interval(a) + (-b); }
00248 
00249 inline lx_interval & operator -=(lx_interval &a, const lx_interval &b) throw()
00250 {  return a = a-b; }
00251 inline lx_interval & operator -=(lx_interval &a, const l_interval &b) throw()
00252 {  return a = a-b; }
00253 inline lx_interval & operator -=(lx_interval &a, const l_real &b) throw()
00254 {  return a = a-b; }
00255 inline lx_interval & operator -=(lx_interval &a, const lx_real &b) throw()
00256 {  return a = a-b; }
00257 inline lx_interval & operator -=(lx_interval &a, const real &b) throw()
00258 {  return a = a-b; }
00259 inline lx_interval & operator -=(lx_interval &a, const interval &b) throw()
00260 {  return a = a-b; }
00261 
00262 inline lx_interval operator * (const lx_interval &a, const l_interval &b) 
00263     throw()
00264 { return a * lx_interval(b); }
00265 
00266 inline lx_interval operator * (const l_interval &a, const lx_interval &b) 
00267     throw()
00268 { return lx_interval(a) * b; }
00269 
00270 inline lx_interval operator * (const lx_interval &a, const l_real &b) throw()
00271 { return a * lx_interval(b); }
00272 
00273 inline lx_interval operator * (const l_real &a, const lx_interval &b) throw()
00274 { return lx_interval(a) * b; }
00275 
00276 inline lx_interval operator * (const lx_interval &a, const lx_real &b) throw()
00277 { return a * lx_interval(b); }
00278 
00279 inline lx_interval operator * (const lx_real &a, const lx_interval &b) throw()
00280 { return lx_interval(a) * b; }
00281 
00282 inline lx_interval operator * (const lx_interval &a, const real &b) throw()
00283 { return a * lx_interval(b); }
00284 
00285 inline lx_interval operator * (const real &a, const lx_interval &b) throw()
00286 { return lx_interval(a) * b; }
00287 
00288 inline lx_interval operator * (const lx_interval &a, const interval &b) throw()
00289 { return a * lx_interval(b); }
00290 
00291 inline lx_interval operator * (const interval &a, const lx_interval &b) throw()
00292 { return lx_interval(a) * b; }
00293 
00294 inline lx_interval & operator *=(lx_interval &a, const lx_interval &b) throw()
00295 {  return a = a*b; }
00296 inline lx_interval & operator *=(lx_interval &a, const l_interval &b) throw()
00297 {  return a = a*b; }
00298 inline lx_interval & operator *=(lx_interval &a, const l_real &b) throw()
00299 {  return a = a*b; }
00300 inline lx_interval & operator *=(lx_interval &a, const lx_real &b) throw()
00301 {  return a = a*b; }
00302 inline lx_interval & operator *=(lx_interval &a, const real &b) throw()
00303 {  return a = a*b; }
00304 inline lx_interval & operator *=(lx_interval &a, const interval &b) throw()
00305 {  return a = a*b; } 
00306 
00307 inline lx_interval operator / (const lx_interval &a, const l_interval &b) 
00308                               throw(ERROR_LINTERVAL_DIV_BY_ZERO)
00309 { return a / lx_interval(b); }
00310 
00311 inline lx_interval operator / (const l_interval &a, const lx_interval &b) 
00312                               throw(ERROR_LINTERVAL_DIV_BY_ZERO)
00313 { return lx_interval(a) / b; }
00314 
00315 inline lx_interval operator / (const lx_interval &a, const l_real &b) 
00316                               throw(ERROR_LINTERVAL_DIV_BY_ZERO)
00317 { return a / lx_interval(b); }
00318 
00319 inline lx_interval operator / (const l_real &a, const lx_interval &b) 
00320                               throw(ERROR_LINTERVAL_DIV_BY_ZERO)
00321 { return lx_interval(a) / b; }
00322 
00323 inline lx_interval operator / (const lx_interval &a, const real &b) 
00324                               throw(ERROR_LINTERVAL_DIV_BY_ZERO)
00325 { return a / lx_interval(b); }
00326 
00327 inline lx_interval operator / (const real &a, const lx_interval &b) 
00328                               throw(ERROR_LINTERVAL_DIV_BY_ZERO)
00329 { return lx_interval(a) / b; }
00330 
00331 inline lx_interval operator / (const lx_interval &a, const interval &b) 
00332                               throw(ERROR_LINTERVAL_DIV_BY_ZERO)
00333 { return a / lx_interval(b); }
00334 
00335 inline lx_interval operator / (const interval &a, const lx_interval &b) 
00336                               throw(ERROR_LINTERVAL_DIV_BY_ZERO)
00337 { return lx_interval(a) / b; }
00338 
00339 inline lx_interval operator / (const lx_interval &a, const lx_real &b) 
00340                                       throw(ERROR_LINTERVAL_DIV_BY_ZERO)
00341 {  return a / lx_interval(b); }
00342 
00343 inline lx_interval operator / (const lx_real &a, const lx_interval &b) 
00344                                       throw(ERROR_LINTERVAL_DIV_BY_ZERO)
00345 {  return lx_interval(a) / b; }
00346 
00347 
00348 inline lx_interval & operator /=(lx_interval &a, const lx_interval &b) throw()
00349 {  return a = a/b; }
00350 inline lx_interval & operator /=(lx_interval &a, const l_interval &b) throw()
00351 {  return a = a/b; }
00352 inline lx_interval & operator /=(lx_interval &a, const l_real &b) throw()
00353 {  return a = a/b; }
00354 inline lx_interval & operator /=(lx_interval &a, const real &b) throw()
00355 {  return a = a/b; }
00356 inline lx_interval & operator /=(lx_interval &a, const interval &b) throw()
00357 {  return a = a/b; }
00358 inline lx_interval & operator /=(lx_interval &a, const lx_real &b) throw()
00359 {  return a = a/b; } 
00360 
00361 // ------------------ Vergleichsoperatoren ----------------------------------
00362 
00363 inline bool operator ! (const lx_interval& a) throw()
00364 { return !a.li; }
00365 
00366 inline bool operator == (const lx_interval &a, const lx_interval &b) throw()
00367 {
00368     l_interval al(li_part(a)), bl(li_part(b));
00369     int exa(expo_gr(al)), exb(expo_gr(bl));
00370     real na(expo(a)), nb(expo(b)), d;
00371     bool a_0(exa<-100000), b_0(exb<-100000), res;
00372 
00373     if (a_0 || b_0) res = (a_0 == b_0);
00374     else // a,b <> 0:
00375     {
00376         d = exa-exb;
00377         if (d>0)
00378         {  // bl nach oben skalieren:
00379             Times2pown(bl,d);
00380             d = nb - d;
00381             nb = (abs(d) > Max_Int_R)? MaxReal : d; // b = 2^nb * bl;
00382         } else // d<=0:
00383         {  // al nach oben skalieren:
00384             Times2pown(al,-d);
00385             d = na + d;
00386             na = (abs(d) > Max_Int_R)? MaxReal : d; // a = 2^na * al;
00387         }
00388         res = (na==nb && al==bl);
00389     }
00390     return res;
00391 }
00392 
00393 inline bool operator == (const lx_interval &a, const l_interval &b) throw()
00394 {  return (a == lx_interval(b)); }
00395 
00396 inline bool operator == (const l_interval &a, const lx_interval &b) throw()
00397 {  return ( lx_interval(a) == b); }
00398 
00399 inline bool operator == (const lx_interval &a, const interval &b) throw()
00400 {  return (a == lx_interval(b)); }
00401 
00402 inline bool operator == (const interval &a, const lx_interval &b) throw()
00403 {  return ( lx_interval(a) == b); }
00404 
00405 inline bool operator == (const lx_interval &a, const real &b) throw()
00406 {  return ( a == lx_interval(b)); }
00407 
00408 inline bool operator == (const lx_interval &a, const l_real &b) throw()
00409 {  return ( a == lx_interval(b)); }
00410 
00411 inline bool operator == (const real &a, const lx_interval &b) throw()
00412 {  return ( lx_interval(a) == b); }
00413 
00414 inline bool operator == (const l_real &a, const lx_interval &b) throw()
00415 {  return ( lx_interval(a) == b); }
00416 
00417 inline bool operator == (const lx_interval &a, const lx_real &b) throw()
00418 {  return ( a == lx_interval(b)); }
00419 
00420 inline bool operator == (const lx_real &a, const lx_interval &b) throw()
00421 {  return ( lx_interval(a) == b); }
00422 
00423 inline bool operator != (const lx_interval &a, const lx_interval &b) throw()
00424 { return !(a==b); }
00425 
00426 inline bool operator != (const lx_interval &a, const l_interval &b) throw()
00427 { return !(a==lx_interval(b)); }
00428 
00429 inline bool operator != (const l_interval &a, const lx_interval &b) throw()
00430 { return !(lx_interval(a) == b); }
00431 
00432 inline bool operator != (const lx_interval &a, const interval &b) throw()
00433 { return !(a==lx_interval(b)); }
00434 
00435 inline bool operator != (const interval &a, const lx_interval &b) throw()
00436 { return !(lx_interval(a) == b); }
00437 
00438 inline bool operator != (const lx_interval &a, const real &b) throw()
00439 { return !(a == lx_interval(b)); }
00440 
00441 inline bool operator != (const real &a, const lx_interval &b) throw()
00442 { return !(lx_interval(a) == b); }
00443 
00444 inline bool operator != (const lx_interval &a, const l_real &b) throw()
00445 { return !(a == lx_interval(b)); }
00446 
00447 inline bool operator != (const l_real &a, const lx_interval &b) throw()
00448 { return !(lx_interval(a) == b); }
00449 
00450 inline bool operator != (const lx_interval &a, const lx_real &b) throw()
00451 { return !(a == lx_interval(b)); }
00452 
00453 inline bool operator != (const lx_real &a, const lx_interval &b) throw()
00454 { return !(lx_interval(a) == b); }
00455 
00456 // ------------------------------------------------------------------------
00457 // --------------------------- set comparisons ----------------------------
00458 // ------------------------------------------------------------------------
00459 
00460 // ---- lx_interval--lx_interval
00461 inline bool operator <  (const lx_interval &a, const lx_interval &b) throw()
00462 { return( Inf(a)>Inf(b) && Sup(a)<Sup(b) ); }
00463 inline bool operator <= (const lx_interval &a, const lx_interval &b) throw()
00464 { return( Inf(a)>=Inf(b) && Sup(a)<=Sup(b) ); }
00465 inline bool operator > (const lx_interval& a, const lx_interval& b) throw()
00466 { return(Inf(a)<Inf(b) && Sup(a)>Sup(b)); }
00467 inline bool operator >= (const lx_interval& a, const lx_interval& b) throw()
00468 { return(Inf(a)<=Inf(b) && Sup(a)>=Sup(b)); }
00469 
00470 // ---- lx_interval--l_interval
00471 inline bool operator <  (const lx_interval &a, const l_interval &b) throw()
00472 { return( Inf(a)>Inf(b) && Sup(a)<Sup(b) ); }
00473 inline bool operator <= (const lx_interval &a, const l_interval &b) throw()
00474 { return( Inf(a)>=Inf(b) && Sup(a)<=Sup(b) ); }
00475 inline bool operator <  (const l_interval &a, const lx_interval &b) throw()
00476 { return( Inf(a)>Inf(b) && Sup(a)<Sup(b) ); }
00477 inline bool operator <= (const l_interval &a, const lx_interval &b) throw()
00478 { return( Inf(a)>=Inf(b) && Sup(a)<=Sup(b) ); }
00479 inline bool operator > (const lx_interval& a, const l_interval& b) throw()
00480 { return(Inf(a)<Inf(b) && Sup(a)>Sup(b)); }
00481 inline bool operator >= (const lx_interval& a, const l_interval& b) throw()
00482 { return(Inf(a)<=Inf(b) && Sup(a)>=Sup(b)); }
00483 inline bool operator > (const l_interval& a, const lx_interval& b) throw()
00484 { return(Inf(a)<Inf(b) && Sup(a)>Sup(b)); }
00485 inline bool operator >= (const l_interval& a, const lx_interval& b) throw()
00486 { return(Inf(a)<=Inf(b) && Sup(a)>=Sup(b)); }
00487 
00488 // ---- lx_interval--interval
00489 inline bool operator <  (const lx_interval &a, const interval &b) throw()
00490 { return( Inf(a)>Inf(b) && Sup(a)<Sup(b) ); }
00491 inline bool operator <= (const lx_interval &a, const interval &b) throw()
00492 { return( Inf(a)>=Inf(b) && Sup(a)<=Sup(b) ); }
00493 inline bool operator <  (const interval &a, const lx_interval &b) throw()
00494 { return( Inf(a)>Inf(b) && Sup(a)<Sup(b) ); }
00495 inline bool operator <= (const interval &a, const lx_interval &b) throw()
00496 { return( Inf(a)>=Inf(b) && Sup(a)<=Sup(b) ); }
00497 inline bool operator > (const lx_interval& a, const interval& b) throw()
00498 { return(Inf(a)<Inf(b) && Sup(a)>Sup(b)); }
00499 inline bool operator >= (const lx_interval& a, const interval& b) throw()
00500 { return(Inf(a)<=Inf(b) && Sup(a)>=Sup(b)); }
00501 inline bool operator > (const interval& a, const lx_interval& b) throw()
00502 { return(Inf(a)<Inf(b) && Sup(a)>Sup(b)); }
00503 inline bool operator >= (const interval& a, const lx_interval& b) throw()
00504 { return(Inf(a)<=Inf(b) && Sup(a)>=Sup(b)); }
00505 
00506 // ---- lx_interval--real
00507 inline bool operator <  (const real &a, const lx_interval &b) throw()
00508 { return( a>Inf(b) && a<Sup(b) ); }
00509 inline bool operator <= (const real &a, const lx_interval &b) throw()
00510 { return( a>=Inf(b) && a<=Sup(b) ); }
00511 inline bool operator >  (const lx_interval &a, const real &b) throw()
00512 { return( b>Inf(a) && b<Sup(a) ); }
00513 inline bool operator >=  (const lx_interval &a, const real &b) throw()
00514 { return( b>=Inf(a) && b<=Sup(a) ); }
00515 
00516 // ---- lx_interval--l_real
00517 inline bool operator <  (const l_real &a, const lx_interval &b) throw()
00518 { return( a>Inf(b) && a<Sup(b) ); }
00519 inline bool operator <= (const l_real &a, const lx_interval &b) throw()
00520 { return( a>=Inf(b) && a<=Sup(b) ); }
00521 inline bool operator >  (const lx_interval &a, const l_real &b) throw()
00522 { return( b>Inf(a) && b<Sup(a) ); }
00523 inline bool operator >=  (const lx_interval &a, const l_real &b) throw()
00524 { return( b>=Inf(a) && b<=Sup(a) ); }
00525 
00526 // ---- lx_interval--lx_real
00527 inline bool operator <  (const lx_real &a, const lx_interval &b) throw()
00528 { return( a>Inf(b) && a<Sup(b) ); }
00529 inline bool operator <= (const lx_real &a, const lx_interval &b) throw()
00530 { return( a>=Inf(b) && a<=Sup(b) ); }
00531 inline bool operator >  (const lx_interval &a, const lx_real &b) throw()
00532 { return( b>Inf(a) && b<Sup(a) ); }
00533 inline bool operator >=  (const lx_interval &a, const lx_real &b) throw()
00534 { return( b>=Inf(a) && b<=Sup(a) ); }
00535 
00536 
00537 inline lx_interval adjust(const lx_interval &a) throw()
00538 {  return lx_interval(a.ex,adjust(a.li));  }
00539 
00540 inline lx_interval abs(const lx_interval &a) throw()
00541 {  return lx_interval(a.ex,abs(a.li));  }
00542 
00543 inline bool point_intv(const lx_interval &a)
00544 {  return point_intv(a.li);  }
00545 
00546 inline void times2pown(lx_interval &a, const real& n) throw()
00547 {  a = lx_interval(add_real(n,a.ex),a.li); }
00548 
00549 inline void times2pown_neg(lx_interval& a, const real& n) throw()
00550 // Calculating an inclusion of  a*2^n, n = 0,-1,-2,...,-9007199254740991.0;
00551 // n MUST be an integer and n MUST not be positive! 
00552 // These conditions are not tested in this function!
00553 // Blomquist, 09.06.2008;
00554 {
00555     int exal(expo_gr(a.li));
00556     real exa,d,n_d;
00557     l_interval lia(a.li);
00558     int k;
00559 
00560     if (exal>-100000) // a != [0,0]
00561     {
00562         exa = a.ex;
00563         if (exa < -Max_Int_R - n) // exa+n < -9007199254740991;
00564         {   // It holds: -Max_Int_R - n in {-Max_Int_R, ...,-1,0},
00565             // Thus, -Max_Int_R - n is always in integer value.
00566             // Furthermore it holds: exa in {-Max_Int_R,...,-2,-1}.
00567             d = -Max_Int_R - exa; // d in {-Max_Int_R+1,..., -1,0} 
00568             n_d = n-d;
00569             // With exa+n < -Max_Int_R  and with  exa+d = -Max_Int_R
00570             // it follows:  n-d < 0, and:
00571             // n-d in {-Max_Int_R,-Max_Int_R+1, ... , -1};
00572             // Thus, n-d is a negative and integer value.
00573             if (n_d < -2147483647)
00574             {
00575                if (Inf(lia)>=0)
00576                   lia = l_interval(0,minreal);
00577                else 
00578                   if (Sup(lia)<=0) 
00579                       lia = l_interval(-minreal,0);
00580                   else lia = l_interval(-minreal,minreal);
00581             }
00582             else  // n_d >=-2147483647:
00583             {
00584                 k = (int) _double(n_d);
00585                 Times2pown(lia,k);
00586             }
00587             a = lx_interval(-Max_Int_R,lia);
00588         }
00589         else // n+a.ex >= -9007199254740991, so an integer overflow
00590              // is not possible here!
00591             a = lx_interval(n+a.ex,lia);
00592     }
00593 } // times2pown_neg(...)
00594 
00595 inline lx_real Inf(const lx_interval &a) throw()
00596 {  return lx_real(a.ex,Inf(a.li));  }
00597 
00598 inline lx_real Sup(const lx_interval &a) throw()
00599 {  return lx_real(a.ex,Sup(a.li));  }
00600 
00601 inline lx_real RelDiam( const lx_interval &a )
00602 { 
00603         lx_real x;
00604         if (0<=a.li)
00605                 x = lx_real(a.ex,RelDiam(a.li));
00606         else x = RelDiam(a.li);
00607         return x;
00608 }
00609 
00610 inline lx_real diam(const lx_interval &a) throw()
00611 {  return lx_real(a.ex,diam(a.li)); }
00612 
00613 inline lx_real mid(const lx_interval& a) throw()
00614 {  return lx_real(a.ex,mid(a.li)); }
00615 
00616 inline bool IsEmpty(const lx_interval& a) throw()
00617 { return  Inf(a.li) > Sup(a.li); }
00618 
00619 // ----------------------------- Convex hull -------------------------------
00620 
00621 inline lx_interval operator |(const lx_interval &a, const lx_interval &b) throw() 
00622 {
00623    return lx_interval( (Inf(a)<Inf(b)) ? Inf(a) : Inf(b),
00624                       (Sup(a)>Sup(b)) ? Sup(a) : Sup(b) );
00625 }
00626 
00627 inline lx_interval operator |(const lx_interval &a, const l_interval &b) throw() 
00628 {
00629     lx_interval Lb(0.0,b);
00630     return lx_interval( (Inf(a)<Inf(Lb)) ? Inf(a) : Inf(Lb),
00631                        (Sup(a)>Sup(Lb)) ? Sup(a) : Sup(Lb) );
00632 }
00633 
00634 inline lx_interval operator |(const l_interval &a, const lx_interval &b) throw() 
00635 {
00636     lx_interval La(0.0,a);
00637     return lx_interval( (Inf(La)<Inf(b)) ? Inf(La) : Inf(b),
00638                        (Sup(La)>Sup(b)) ? Sup(La) : Sup(b) );
00639 }
00640 
00641 inline lx_interval operator |(const lx_interval &a, const interval &b) throw() 
00642 {
00643     lx_interval Lb(0.0,l_interval(b));
00644     return lx_interval( (Inf(a)<Inf(Lb)) ? Inf(a) : Inf(Lb),
00645                        (Sup(a)>Sup(Lb)) ? Sup(a) : Sup(Lb) );
00646 }
00647 
00648 inline lx_interval operator |(const interval &a, const lx_interval &b) throw() 
00649 {
00650     lx_interval La(0.0,l_interval(a));
00651     return lx_interval( (Inf(La)<Inf(b)) ? Inf(La) : Inf(b),
00652                        (Sup(La)>Sup(b)) ? Sup(La) : Sup(b) );
00653 }
00654 
00655 inline lx_interval & operator |= (lx_interval &a,const lx_interval &b) throw() 
00656 {
00657    Inf(a)=(Inf(a)<Inf(b))?Inf(a):Inf(b),Sup(a)=(Sup(a)>Sup(b))?Sup(a):Sup(b);
00658    return a;
00659 }
00660 
00661 inline lx_interval & operator |= (lx_interval &a,const l_interval &b) throw() 
00662 {
00663     lx_interval Lb(0,b);
00664     Inf(a) = (Inf(a)<Inf(Lb)) ? Inf(a) : Inf(Lb),
00665         Sup(a) = (Sup(a)>Sup(Lb)) ? Sup(a) : Sup(Lb);
00666     return a;
00667 }
00668 
00669 inline lx_interval & operator |= (lx_interval &a,const interval &b) throw() 
00670 {
00671     lx_interval Lb(0,l_interval(b));
00672     Inf(a) = (Inf(a)<Inf(Lb)) ? Inf(a) : Inf(Lb),
00673         Sup(a) = (Sup(a)>Sup(Lb)) ? Sup(a) : Sup(Lb);
00674     return a;
00675 }
00676 
00677 inline lx_interval operator | (const lx_real &a, const lx_interval &b) throw() 
00678 {
00679     return lx_interval( (a<Inf(b)) ? a : Inf(b),
00680                        (a>Sup(b)) ? a : Sup(b) );
00681 }
00682 
00683 inline lx_interval operator | (const real &a, const lx_interval &b) throw() 
00684 {
00685     lx_real La(a);
00686     return lx_interval( (La<Inf(b)) ? La : Inf(b),
00687                        (La>Sup(b)) ? La : Sup(b) );
00688 }
00689 
00690 inline lx_interval operator | (const l_real &a, const lx_interval &b) throw() 
00691 {
00692     lx_real La(0,a);
00693     return lx_interval( (La<Inf(b)) ? La : Inf(b),
00694                        (La>Sup(b)) ? La : Sup(b) );
00695 }
00696 
00697 inline lx_interval operator | (const lx_interval &a, const lx_real &b) throw() 
00698 {
00699     return lx_interval( (Inf(a)<b) ? Inf(a) : b,
00700                        (Sup(a)>b) ? Sup(a) : b );
00701 }
00702 
00703 inline lx_interval operator | (const lx_interval &a, const real &b) throw() 
00704 {
00705     lx_real Lb(b);
00706     return lx_interval( (Inf(a)<Lb) ? Inf(a) : Lb,
00707                        (Sup(a)>Lb) ? Sup(a) : Lb );
00708 }
00709 
00710 inline lx_interval operator | (const lx_interval &a, const l_real &b) throw() 
00711 {
00712     lx_real Lb(0.0,b);
00713     return lx_interval( (Inf(a)<Lb) ? Inf(a) : Lb,
00714                        (Sup(a)>Lb) ? Sup(a) : Lb );
00715 }
00716 
00717 inline lx_interval & operator |= (lx_interval &a, const real &b) throw() 
00718 {
00719     lx_real Lb(b);
00720     Inf(a) = (Inf(a)<Lb) ? Inf(a) : Lb, Sup(a) = (Sup(a)>Lb) ? Sup(a) : Lb;
00721     return a;
00722 }
00723 
00724 inline lx_interval & operator |= (lx_interval &a, const l_real &b) throw() 
00725 {
00726     lx_real Lb(0.0,b);
00727     Inf(a) = (Inf(a)<Lb) ? Inf(a) : Lb, Sup(a) = (Sup(a)>Lb) ? Sup(a) : Lb;
00728     return a;
00729 }
00730 
00731 
00732 inline lx_interval & operator |= (lx_interval &a, const lx_real &b) throw() 
00733 {
00734     Inf(a) = (Inf(a)<b) ? Inf(a) : b, Sup(a) = (Sup(a)>b) ? Sup(a) : b;
00735     return a;
00736 }
00737 
00738 inline lx_interval operator |(const lx_real &a, const lx_real &b) throw()
00739 {
00740     if(a>b) return lx_interval(b,a);
00741     else    return lx_interval(a,b);
00742 }
00743 
00744 // --------------------------- Intersection -----------------------------
00745 
00746 inline lx_interval operator & (const lx_interval &a, const lx_interval &b) 
00747     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00748 {
00749     return lx_interval( (Inf(a)>Inf(b)) ? Inf(a) : Inf(b),
00750                        (Sup(a)<Sup(b)) ? Sup(a) : Sup(b));
00751 }
00752 
00753 inline lx_interval operator & (const lx_interval &a, const l_interval &b) 
00754     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00755 {
00756     lx_interval Lb(0.0,b);
00757     return lx_interval( (Inf(a)>Inf(Lb)) ? Inf(a) : Inf(Lb),
00758                        (Sup(a)<Sup(Lb)) ? Sup(a) : Sup(Lb));
00759 }
00760 
00761 inline lx_interval & operator &= (lx_interval &a, const l_interval &b) 
00762     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00763 {
00764     lx_interval Lb(0.0,b);
00765     Inf(a) = (Inf(a)>Inf(Lb)) ? Inf(a) : Inf(Lb),
00766         Sup(a) = (Sup(a)<Sup(Lb)) ? Sup(a) : Sup(Lb);
00767     if (Inf(a)>Sup(a))
00768         cxscthrow(ERROR_LINTERVAL_EMPTY_INTERVAL("lx_interval & operator &=(lx_interval &a,const l_interval &b)"));
00769     return a;
00770 }
00771 
00772 inline lx_interval operator & (const l_interval &a, const lx_interval &b) 
00773     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00774 {
00775     lx_interval La(0.0,a);
00776     return lx_interval( (Inf(La)>Inf(b)) ? Inf(La) : Inf(b),
00777                        (Sup(La)<Sup(b)) ? Sup(La) : Sup(b));
00778 }
00779 
00780 inline lx_interval operator & (const lx_interval &a, const interval &b) 
00781     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00782 {
00783     lx_interval Lb(0.0,l_interval(b));
00784     return lx_interval( (Inf(a)>Inf(Lb)) ? Inf(a) : Inf(Lb),
00785                        (Sup(a)<Sup(Lb)) ? Sup(a) : Sup(Lb));
00786 }
00787 
00788 inline lx_interval & operator &= (lx_interval &a, const interval &b) 
00789     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00790 {
00791     lx_interval Lb(0.0,l_interval(b));
00792     Inf(a) = (Inf(a)>Inf(Lb)) ? Inf(a) : Inf(Lb),
00793         Sup(a) = (Sup(a)<Sup(Lb)) ? Sup(a) : Sup(Lb);
00794     if (Inf(a)>Sup(a))
00795         cxscthrow(ERROR_LINTERVAL_EMPTY_INTERVAL("lx_interval & operator &=(lx_interval &a,const interval &b)"));
00796     return a;
00797 }
00798 
00799 inline lx_interval operator & (const interval &a, const lx_interval &b) 
00800     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00801 {
00802     lx_interval La(0.0,l_interval(a));
00803     return lx_interval( (Inf(La)>Inf(b)) ? Inf(La) : Inf(b),
00804                        (Sup(La)<Sup(b)) ? Sup(La) : Sup(b));
00805 }
00806 
00807 inline lx_interval & operator &= (lx_interval &a, const lx_interval &b) 
00808     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00809 {
00810     Inf(a)=(Inf(a)>Inf(b))?Inf(a):Inf(b),Sup(a)=(Sup(a)<Sup(b))?Sup(a):Sup(b);
00811     if (Inf(a)>Sup(a))
00812         cxscthrow(ERROR_LINTERVAL_EMPTY_INTERVAL("lx_interval & operator &=(lx_interval &a,const lx_interval &b)"));
00813    return a;
00814 }
00815 
00816 inline lx_interval operator & (const lx_interval &a, const lx_real &b) 
00817     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00818 {
00819    return lx_interval( (Inf(a)>b) ? Inf(a) : b,
00820                       (Sup(a)<b) ? Sup(a) : b );
00821 }
00822 
00823 inline lx_interval operator & (const lx_interval &a, const real &b) 
00824     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00825 {
00826     lx_real Lb(b);
00827     return lx_interval( (Inf(a)>Lb) ? Inf(a) : Lb,
00828                        (Sup(a)<Lb) ? Sup(a) : Lb );
00829 }
00830 
00831 inline lx_interval operator & (const lx_interval &a, const l_real &b) 
00832     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00833 {
00834     lx_real Lb(0.0,b);
00835     return lx_interval( (Inf(a)>Lb) ? Inf(a) : Lb,
00836                        (Sup(a)<Lb) ? Sup(a) : Lb );
00837 }
00838 
00839 inline lx_interval operator & (const lx_real &a, const lx_interval &b) 
00840     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00841 {
00842     return lx_interval( (a>Inf(b)) ? a : Inf(b),
00843                        (a<Sup(b)) ? a : Sup(b) );
00844 }
00845 
00846 inline lx_interval operator & (const real &a, const lx_interval &b) 
00847     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00848 {
00849     lx_real La(a);
00850     return lx_interval( (La>Inf(b)) ? La : Inf(b),
00851                        (La<Sup(b)) ? La : Sup(b) );
00852 }
00853 
00854 inline lx_interval operator & (const l_real &a, const lx_interval &b) 
00855     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00856 {
00857     lx_real La(0.0,a);
00858     return lx_interval( (La>Inf(b)) ? La : Inf(b),
00859                        (La<Sup(b)) ? La : Sup(b) );
00860 }
00861 
00862 inline lx_interval & operator &= (lx_interval &a,const lx_real &b) 
00863     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00864 {
00865     Inf(a) = (Inf(a)>b) ? Inf(a) : b, Sup(a) = (Sup(a)<b) ? Sup(a) : b;
00866     if(Inf(a)>Sup(a))
00867         cxscthrow(ERROR_LINTERVAL_EMPTY_INTERVAL("lx_interval & operator &=(lx_interval &a,const lx_real &b)"));
00868     return a;
00869 }
00870 
00871 inline lx_interval & operator &= (lx_interval &a, const real &b) 
00872     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00873 {
00874     lx_real Lb(b);
00875     Inf(a) = (Inf(a)>Lb) ? Inf(a) : Lb, Sup(a) = (Sup(a)<Lb) ? Sup(a) : Lb;
00876     if(Inf(a)>Sup(a))
00877         cxscthrow(ERROR_LINTERVAL_EMPTY_INTERVAL("lx_interval & operator &=(lx_interval &a,const real &b)"));
00878     return a;
00879 }
00880 
00881 inline lx_interval & operator &= (lx_interval &a, const l_real &b) 
00882     throw(ERROR_LINTERVAL_EMPTY_INTERVAL) 
00883 {
00884     lx_real Lb(0.0,b);
00885     Inf(a) = (Inf(a)>Lb) ? Inf(a) : Lb, Sup(a) = (Sup(a)<Lb) ? Sup(a) : Lb;
00886     if(Inf(a)>Sup(a))
00887         cxscthrow(ERROR_LINTERVAL_EMPTY_INTERVAL("lx_interval & operator &=(lx_interval &a,const l_real &b)"));
00888     return a;
00889 }
00890 
00891 // ------------------------- SetInf, SetSup -----------------------------
00892 
00893 inline lx_interval & SetInf(lx_interval& a, const lx_real& b) 
00894     throw(ERROR_LINTERVAL_EMPTY_INTERVAL)
00895 {
00896     return a = lx_interval(b,Sup(a));
00897 }
00898 
00899 inline lx_interval & SetInf(lx_interval& a, const l_real& b) 
00900     throw(ERROR_LINTERVAL_EMPTY_INTERVAL)
00901 {
00902     return a = lx_interval(lx_real(0.0,b),Sup(a));
00903 }
00904 
00905 inline lx_interval & SetInf(lx_interval& a, const real& b) 
00906     throw(ERROR_LINTERVAL_EMPTY_INTERVAL)
00907 {
00908     return a = lx_interval(lx_real(0.0,l_real(b)),Sup(a));
00909 }
00910 
00911 inline lx_interval & SetSup(lx_interval& a, const lx_real& b) 
00912     throw(ERROR_LINTERVAL_EMPTY_INTERVAL)
00913 {
00914     return a = lx_interval(Inf(a),b);
00915 }
00916 
00917 inline lx_interval & SetSup(lx_interval& a, const l_real& b) 
00918     throw(ERROR_LINTERVAL_EMPTY_INTERVAL)
00919 {
00920     return a = lx_interval(Inf(a),lx_real(0.0,b));
00921 }
00922 
00923 inline lx_interval & SetSup(lx_interval& a, const real& b) 
00924     throw(ERROR_LINTERVAL_EMPTY_INTERVAL)
00925 {
00926     return a = lx_interval(Inf(a),lx_real(0.0,l_real(b)));
00927 }
00928 
00929 
00930 } // end namespace cxsc