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: l_real.cpp,v 1.34 2014/01/30 17:23:46 cxsc Exp $ */ 00025 00026 #include <memory.h> 00027 00028 #include "l_real.hpp" 00029 #include "dot.hpp" 00030 #include "idot.hpp" 00031 #include "interval.hpp" 00032 #include "l_interval.hpp" 00033 00034 namespace cxsc { 00035 00036 #ifdef CXSC_USE_TLS_PREC 00037 00038 #ifdef _WIN32 00039 __declspec(thread) int stagprec = 2; 00040 #else 00041 __thread int stagprec = 2; 00042 #endif 00043 00044 #else 00045 00046 int stagprec = 2; 00047 00048 #endif 00049 00050 00051 interval::interval(const l_real & a) throw() 00052 { 00053 dotprecision dot(a); 00054 rnd(dot,inf,sup); 00055 } 00056 00057 interval & interval::operator =(const l_real & a) throw() 00058 { 00059 dotprecision dot(a); 00060 rnd(dot,inf,sup); 00061 return *this; 00062 } 00063 00064 idotprecision::idotprecision(const l_real & a) throw() : inf(0), 00065 sup(0) 00066 { 00067 *this+=a; 00068 } 00069 00070 idotprecision::idotprecision(const l_real & a,const l_real & b) : 00071 inf(0), 00072 sup(0) 00073 { 00074 inf+=a; 00075 sup+=b; 00076 } 00077 00078 00079 00080 void l_real::_clear(int p) throw() 00081 { 00082 // filling a l_real number from element p up to the end with zero. 00083 for (int i=p; i<=prec; i++) 00084 this->elem(i)=0.0; 00085 } 00086 00087 00088 void l_real::_akku_out(const dotprecision& d) throw() 00089 { 00090 // The dotprecision value is rounded to the activated l_real number 00091 // in its own precision. 00092 dotprecision dot(d); 00093 _clear(1); 00094 this->elem(1) = rnd(dot); 00095 if (prec>1) 00096 { 00097 int i=2, weiter; 00098 do { 00099 dot -= this->elem(i-1); 00100 this->elem(i) = rnd(dot); 00101 i++; 00102 weiter = this->elem(i-1) != 0; // Blomquist 02.10.02. 00103 } while (weiter && (i <= prec)); 00104 } 00105 } 00106 00107 void l_real::_akku_out_up(const dotprecision& d) throw() 00108 { 00109 // The dotprecision value is rounded up to the activated l_real 00110 // number in its own precision. 00111 // Blomquist, 20.11.2006; 00112 bool weiter; 00113 dotprecision dot(d); 00114 _clear(1); 00115 this->elem(1) = (prec==1)? rnd(dot,RND_UP) : rnd(dot); 00116 if (prec>1) 00117 { 00118 int i=2; 00119 do { 00120 dot -= this->elem(i-1); 00121 weiter = (sign(dot) != 0); 00122 if (weiter) 00123 this->elem(i) = (i==prec)? 00124 rnd(dot,RND_UP) : rnd(dot); 00125 i++; 00126 } while (weiter && (i <= prec)); 00127 } 00128 } 00129 00130 void l_real::_akku_out_down(const dotprecision& d) throw() 00131 { 00132 // The dotprecision value is rounded up to the activated l_real 00133 // number in its own precision. 00134 // Blomquist, 20.11.2006; 00135 bool weiter; 00136 dotprecision dot(d); 00137 _clear(1); 00138 this->elem(1) = (prec==1)? rnd(dot,RND_DOWN) : rnd(dot); 00139 if (prec>1) 00140 { 00141 int i=2; 00142 do { 00143 dot -= this->elem(i-1); 00144 weiter = (sign(dot) != 0); 00145 if (weiter) 00146 this->elem(i) = (i==prec)? 00147 rnd(dot,RND_DOWN) : rnd(dot); 00148 i++; 00149 } while (weiter && (i <= prec)); 00150 } 00151 } 00152 00153 void l_real::_akku_add(dotprecision& d) const throw() 00154 { 00155 // adding the activated l_real number to the accumulator d. 00156 for (int i=1; i<=prec; i++) 00157 { 00158 if (this->elem(i) != 0) d += this->elem(i); 00159 } 00160 } 00161 00162 void l_real::_akku_sub(dotprecision& d) const throw() 00163 { 00164 // subtracting the activated l_real number from the accumulator d. 00165 for (int i=1; i<=prec; i++) 00166 { 00167 if (this->elem(i) != 0) d -= this->elem(i); 00168 } 00169 } 00170 00171 //--------------------------------------------------------------------------- 00172 // Constructors and destructors 00173 // 00174 l_real::l_real() throw() 00175 { 00176 data=new real[stagprec]; 00177 if(data) 00178 prec=stagprec; 00179 else 00180 prec=0; 00181 } 00182 00183 l_real::~l_real() throw() 00184 { 00185 delete [] data; 00186 } 00187 00188 l_real::l_real(const l_real& lr) throw() 00189 : data(new real[lr.prec]) 00190 { 00191 if(data) 00192 { 00193 prec=lr.prec; 00194 memcpy(data,lr.data,sizeof(real)*prec); 00195 } else 00196 prec=0; 00197 } 00198 00199 l_real::l_real(const real & r) throw() 00200 : prec(1), 00201 data(new real[1]) 00202 { 00203 data[0]=r; 00204 } 00205 00206 l_real::l_real(const double & db) throw() 00207 : prec(1), data(new real[1]) 00208 { 00209 data[0] = db; // Blomquist 10.09.02. Deklaration in l_real.hpp 00210 } 00211 00212 l_real::l_real(int i) throw() 00213 : prec(1), 00214 data(new real[1]) 00215 { 00216 data[0]=i; 00217 } 00218 00219 l_real::l_real(long i) throw() 00220 : prec(1), 00221 data(new real[1]) 00222 { 00223 data[0]=i; 00224 } 00225 //--------------------------------------------------------------------------- 00226 // Type transfers 00227 00228 real::real(const l_real& lr) throw() 00229 { 00230 dotprecision dot(0.0); 00231 lr._akku_add(dot); 00232 w=rnd(dot).w; 00233 } 00234 00235 dotprecision::dotprecision(const l_real& lr) throw() : akku(new a_btyp[A_LENGTH]) 00236 { 00237 memset(akku,0,BUFFERSIZE); 00238 lr._akku_add(*this); 00239 } 00240 00241 dotprecision & dotprecision::operator =(const l_real & lr) throw() 00242 { 00243 memset(akku,0,BUFFERSIZE); 00244 lr._akku_add(*this); 00245 return *this; 00246 } 00247 00248 l_real::l_real(const dotprecision & d) throw() : prec(stagprec), 00249 data(new real[prec]) 00250 { 00251 _akku_out(d); 00252 } 00253 00254 //--------------------------------------------------------------------------- 00255 // assignments 00256 // 00257 l_real& l_real::operator=(const real& r) throw() 00258 { 00259 // Siehe _l_real(real..) 00260 00261 if(prec!=1) 00262 { 00263 delete [] data; 00264 data=new real[1]; 00265 if(data) 00266 prec=1; 00267 else 00268 prec=0; 00269 } 00270 elem(1)=r; 00271 return *this; 00272 } 00273 00274 l_real& l_real::operator=(const l_real& lr) throw() 00275 { 00276 // Siehe c++-FAQ assignment-operators.html#[12.1] 00277 00278 // This code gracefully (albeit implicitly) handles self assignment 00279 real* tmp = new real[lr.prec]; 00280 // It would be OK if an exception got thrown here 00281 00282 if((prec=lr.prec)>0) 00283 memcpy(tmp,lr.data,sizeof(real)*prec); 00284 00285 delete [] data; 00286 data = tmp; 00287 return *this; 00288 } 00289 00290 l_real& l_real::operator=(const dotprecision & d) throw() 00291 { 00292 if(prec!=stagprec) 00293 { 00294 delete [] data; 00295 data=new real[prec=stagprec]; 00296 } 00297 _akku_out(d); 00298 return *this; 00299 } 00300 00301 00302 real& l_real::operator[](int i) const throw() 00303 { 00304 if (i<1 || i>prec) 00305 { 00306 // throw! 00307 i=1; 00308 } 00309 return data[i-1]; 00310 } 00311 00312 int StagPrec(const l_real& lr) throw() 00313 { 00314 return lr.prec; 00315 } 00316 00317 std::istream& operator>>(std::istream& s, l_real& lr) throw() 00318 { 00319 dotprecision dot; 00320 s >> dot; 00321 lr._akku_out(dot); 00322 return s; 00323 } 00324 00325 std::ostream& operator<<(std::ostream& s, const l_real& lr) throw() 00326 { 00327 dotprecision dot(0.0); 00328 lr._akku_add(dot); 00329 s << dot; 00330 return s; 00331 } 00332 std::string& operator>>(std::string& s, l_real& lr) throw() 00333 { 00334 dotprecision dot; 00335 s >> dot; 00336 lr._akku_out(dot); 00337 return s; 00338 } 00339 00340 std::string& operator<<(std::string& s, const l_real& lr) throw() 00341 { 00342 dotprecision dot(0.0); 00343 lr._akku_add(dot); 00344 s << dot; 00345 return s; 00346 } 00347 void operator>>(const std::string& s, l_real& lr) throw() 00348 { 00349 std::string r(s); 00350 r>>lr; 00351 } 00352 void operator>>(const char *s, l_real& lr) throw() 00353 { 00354 std::string r(s); 00355 r>>lr; 00356 } 00357 00358 00359 void accumulate(dotprecision& d, const real& r, const l_real& lr) throw() 00360 { 00361 // accumulate(d, l_real(r), lr); Blomquist: Old version, not from me! 00362 for (int i=1; i<=lr.prec; i++) // Blomquist: My new version, 24.09.02 00363 accumulate(d, lr.elem(i), r); 00364 } 00365 00366 void accumulate(dotprecision& d, const l_real& lr, const real& r) throw() 00367 { 00368 // accumulate(d, lr, l_real(r)); Blomquist: Old version, not from me! 00369 for (int i=1; i<=lr.prec; i++) // Blomquist: My new version, 24.09.02 00370 accumulate(d, lr.elem(i), r); 00371 } 00372 00373 void accumulate(dotprecision& d, const l_real& lr1, const l_real&lr2) throw() 00374 { 00375 int i, j; 00376 00377 for (i=1; i<=lr1.prec; i++) 00378 for (j=1; j<=lr2.prec; j++) 00379 // if (abs(lr1.elem(i) * lr2.elem(j)) > MinReal) // alte Zeile von Toussaint 00380 accumulate(d, lr1.elem(i), lr2.elem(j)); 00381 } 00382 00383 void accumulate(idotprecision & a, const real & b, const l_real & c) throw() { accumulate(a,l_interval(b),l_interval(c)); } 00384 void accumulate(idotprecision & a, const l_real & b, const real & c) throw() { accumulate(a,l_interval(b),l_interval(c)); } 00385 void accumulate(idotprecision & a, const l_real & b, const l_real & c) throw() { accumulate(a,l_interval(b),l_interval(c)); } 00386 00387 l_real rnd_up(const dotprecision& a) 00388 { // Blomquist, 20.11.2006; 00389 l_real lr; 00390 lr._akku_out_up(a); 00391 return lr; 00392 } 00393 00394 l_real rnd_down(const dotprecision& a) 00395 { // Blomquist, 20.11.2006; 00396 l_real lr; 00397 lr._akku_out_down(a); 00398 return lr; 00399 } 00400 00401 l_real operator-(const l_real& lr, const real& r) throw() { return lr-_l_real(r); } 00402 l_real operator-(const real& r, const l_real& lr) throw() { return _l_real(r)-lr; } 00403 l_real operator+(const l_real& lr, const real& r) throw() { return lr+_l_real(r); } 00404 l_real operator+(const real& r, const l_real& lr) throw() { return _l_real(r)+lr; } 00405 l_real operator*(const l_real& lr, const real& r) throw() { return lr*_l_real(r); } 00406 l_real operator*(const real& r, const l_real& lr) throw() { return _l_real(r)*lr; } 00407 l_real operator/(const l_real& lr, const real& r) throw() { return lr/_l_real(r); } 00408 l_real operator/(const real& r, const l_real& lr) throw() { return _l_real(r)/lr; } 00409 00410 dotprecision operator-(const l_real& lr, const dotprecision& r) throw() 00411 { 00412 return _dotprecision(lr)-r; 00413 } 00414 dotprecision operator-(const dotprecision& r, const l_real& lr) throw() 00415 { 00416 return r-_dotprecision(lr); 00417 } 00418 dotprecision operator+(const l_real& lr, const dotprecision& r) throw() 00419 { 00420 return _dotprecision(lr)+r; 00421 } 00422 dotprecision operator+(const dotprecision& r, const l_real& lr) throw() 00423 { 00424 return r+_dotprecision(lr); 00425 } 00426 00427 00428 l_real& operator-=(l_real& lr, const real& r) throw() 00429 { lr = lr-_l_real(r); return lr; } 00430 00431 l_real& operator+=(l_real& lr, const real& r) throw() 00432 { lr = lr+_l_real(r); return lr; } 00433 00434 l_real& operator*=(l_real& lr, const real& r) throw() 00435 { lr = lr*_l_real(r); return lr; } 00436 00437 l_real& operator/=(l_real& lr, const real& r) throw() 00438 { lr = lr/_l_real(r); return lr; } 00439 00440 real& operator-=(real& r, const l_real& lr) throw() { r = r-_real(lr); return r; } 00441 real& operator+=(real& r, const l_real& lr) throw() { r = r+_real(lr); return r; } 00442 real& operator*=(real& r, const l_real& lr) throw() { r = r*_real(lr); return r; } 00443 real& operator/=(real& r, const l_real& lr) throw() { r = r/_real(lr); return r; } 00444 00445 bool operator==(const l_real& lr, const real& r) throw() { return lr==_l_real(r); } 00446 bool operator==(const real& r, const l_real& lr) throw() { return _l_real(r)==lr; } 00447 bool operator!=(const l_real& lr, const real& r) throw() { return lr!=_l_real(r); } 00448 bool operator!=(const real& r, const l_real& lr) throw() { return _l_real(r)!=lr; } 00449 00450 bool operator<=(const l_real& lr, const real& r) throw() { return lr<=_l_real(r); } 00451 bool operator<=(const real& r, const l_real& lr) throw() { return _l_real(r)<=lr; } 00452 bool operator>=(const l_real& lr, const real& r) throw() { return lr>=_l_real(r); } 00453 bool operator>=(const real& r, const l_real& lr) throw() { return _l_real(r)>=lr; } 00454 00455 bool operator<(const l_real& lr, const real& r) throw() { return lr<_l_real(r); } 00456 bool operator<(const real& r, const l_real& lr) throw() { return _l_real(r)<lr; } 00457 bool operator>(const l_real& lr, const real& r) throw() { return lr>_l_real(r); } 00458 bool operator>(const real& r, const l_real& lr) throw() { return _l_real(r)>lr; } 00459 00460 bool operator==(const l_real& lr, const dotprecision& d) throw() { return _dotprecision(lr)==d; } 00461 bool operator==(const dotprecision& d, const l_real& lr) throw() { return d==_dotprecision(lr); } 00462 bool operator!=(const l_real& lr, const dotprecision& d) throw() { return _dotprecision(lr)!=d; } 00463 bool operator!=(const dotprecision& d, const l_real& lr) throw() { return d!=_dotprecision(lr); } 00464 00465 bool operator<=(const l_real& lr, const dotprecision& d) throw() { return _dotprecision(lr)<=d; } 00466 bool operator<=(const dotprecision& d, const l_real& lr) throw() { return d<=_dotprecision(lr); } 00467 bool operator>=(const l_real& lr, const dotprecision& d) throw() { return _dotprecision(lr)>=d; } 00468 bool operator>=(const dotprecision& d, const l_real& lr) throw() { return d>=_dotprecision(lr); } 00469 00470 bool operator<(const l_real& lr, const dotprecision& d) throw() { return _dotprecision(lr)<d; } 00471 bool operator<(const dotprecision& d, const l_real& lr) throw() { return d<_dotprecision(lr); } 00472 bool operator>(const l_real& lr, const dotprecision& d) throw() { return _dotprecision(lr)>d; } 00473 bool operator>(const dotprecision& d, const l_real& lr) throw() { return d>_dotprecision(lr); } 00474 00475 l_real operator-(const l_real& lr1) throw() 00476 { 00477 l_real lr2(lr1); 00478 for (int i=1; i<=lr1.prec; i++) 00479 lr2.elem(i) = -(lr1.elem(i)); 00480 return lr2; 00481 } 00482 l_real operator+(const l_real& lr1) throw() 00483 { 00484 return lr1; 00485 } 00486 00487 l_real operator-(const l_real& lr1, const l_real& lr2) throw() 00488 { 00489 l_real lr3; 00490 dotprecision dot(0.0); 00491 lr1._akku_add(dot); 00492 lr2._akku_sub(dot); 00493 lr3._akku_out(dot); 00494 return lr3; 00495 } 00496 00497 l_real operator+(const l_real& lr1, const l_real& lr2) throw() 00498 { 00499 l_real lr3; 00500 dotprecision dot(0.0); 00501 lr1._akku_add(dot); 00502 lr2._akku_add(dot); 00503 lr3._akku_out(dot); 00504 00505 return lr3; 00506 } 00507 00508 l_real operator*(const l_real& lr1, const l_real& lr2) throw() 00509 { 00510 l_real lr3; 00511 dotprecision dot(0.0); 00512 accumulate(dot, lr1, lr2); 00513 lr3._akku_out(dot); 00514 return lr3; 00515 } 00516 00517 l_real operator/(const l_real& lr1, const l_real& lr2) throw(DIV_BY_ZERO) 00518 { // Blomquist, 09.12.02; throw() ---> throw(DIV_BY_ZERO) 00519 real a, b; 00520 l_real lr3; 00521 lr3._clear(1); 00522 dotprecision dot1(0.0); 00523 dotprecision dot2(0.0); 00524 lr1._akku_add(dot1); 00525 lr2._akku_add(dot2); 00526 a = rnd(dot1, RND_DOWN); 00527 b = rnd(dot2, RND_UP); 00528 if (!b) 00529 { // Blomquist: cxscthrow(DIV_BY_ ... ) 00530 cxscthrow(DIV_BY_ZERO("l_real operator/(const l_real&, const l_real&)")); 00531 } else 00532 { 00533 lr3.elem(1) = a/b; 00534 for (int i=2; i<=stagprec; i++) 00535 { 00536 if (!a) 00537 break; 00538 for (int j=1; j<=lr2.prec; j++) 00539 if (!!lr3.elem(i-1) && !!lr2.elem(j) ) 00540 accumulate(dot1, lr3.elem(i-1), -lr2.elem(j)); 00541 a = rnd(dot1, RND_DOWN); 00542 lr3.elem(i) = a/b; 00543 } 00544 } // no division by zero 00545 return lr3; 00546 } 00547 00548 00549 l_real & operator-=(l_real& lr1, const l_real& lr2) throw() { return lr1 = lr1-lr2; } 00550 l_real & operator+=(l_real& lr1, const l_real& lr2) throw() { return lr1 = lr1+lr2; } 00551 l_real & operator*=(l_real& lr1, const l_real& lr2) throw() { return lr1 = lr1*lr2; } 00552 l_real & operator/=(l_real& lr1, const l_real& lr2) throw() { return lr1 = lr1/lr2; } 00553 00554 bool operator==(const l_real& lr1, const l_real& lr2) throw() 00555 { 00556 dotprecision dot1(0.0); 00557 dotprecision dot2(0.0); 00558 lr1._akku_add(dot1); 00559 lr2._akku_add(dot2); 00560 return (dot1==dot2); 00561 } 00562 00563 bool operator<=(const l_real& lr1, const l_real& lr2) throw() 00564 { 00565 dotprecision dot1(0.0); 00566 dotprecision dot2(0.0); 00567 lr1._akku_add(dot1); 00568 lr2._akku_add(dot2); 00569 return (dot1<=dot2); 00570 } 00571 00572 bool operator!(const l_real& lr) throw() 00573 { 00574 dotprecision dot(0.0); 00575 lr._akku_add(dot); 00576 return (!dot); 00577 } 00578 00579 bool operator!=(const l_real& lr1, const l_real& lr2) throw() { return !(lr1==lr2); } 00580 bool operator< (const l_real& lr1, const l_real& lr2) throw() { return !(lr2<=lr1); } 00581 bool operator> (const l_real& lr1, const l_real& lr2) throw() { return !(lr1<=lr2); } 00582 bool operator>=(const l_real& lr1, const l_real& lr2) throw() { return (lr2<=lr1); } 00583 00584 // ID-LR 00585 00586 idotprecision operator +(const idotprecision &a,const l_real &b) throw() 00587 { 00588 return idotprecision(a.inf+b,a.sup+b); 00589 } 00590 00591 idotprecision operator +(const l_real &b,const idotprecision &a) throw() 00592 { 00593 return idotprecision(a.inf+b,a.sup+b); 00594 } 00595 00596 idotprecision operator -(const idotprecision &a,const l_real &b) throw() 00597 { 00598 return idotprecision(a.inf-b,a.sup-b); 00599 } 00600 00601 idotprecision operator -(const l_real &a,const idotprecision &b) throw() 00602 { 00603 return idotprecision(a-b.sup,a-b.inf); 00604 } 00605 00606 idotprecision operator |(const l_real &a,const idotprecision &b) throw() 00607 { 00608 return idotprecision((a<b.inf)?_dotprecision(a):b.inf,(a>b.sup)?_dotprecision(a):b.sup); 00609 } 00610 00611 idotprecision operator |(const idotprecision &a,const l_real &b) throw() 00612 { 00613 return idotprecision((a.inf<b)?a.inf:_dotprecision(b),(a.sup>b)?a.sup:_dotprecision(b)); 00614 } 00615 00616 idotprecision operator &(const l_real &a,const idotprecision &b) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL) 00617 { 00618 return idotprecision((a>b.inf)?_dotprecision(a):b.inf,(a<b.sup)?_dotprecision(a):b.sup); 00619 } 00620 00621 idotprecision operator &(const idotprecision &a,const l_real &b) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL) 00622 { 00623 return idotprecision((a.inf>b)?a.inf:_dotprecision(b),(a.sup<b)?a.sup:_dotprecision(b)); 00624 } 00625 00626 // LR-ID 00627 idotprecision & operator +=(idotprecision &a,const l_real &b) throw() { return a+=dotprecision(b); } 00628 idotprecision & operator -=(idotprecision &a,const l_real &b) throw() { return a-=dotprecision(b); } 00629 idotprecision & operator |=(idotprecision &a,const l_real &b) throw() { return a|=dotprecision(b); } 00630 idotprecision & operator &=(idotprecision &a,const l_real &b) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL) { return a&=dotprecision(b); } 00631 00632 00633 bool operator ==(const interval &i,const l_real &r) throw() { return Inf(i)==r && Sup(i)==r; } 00634 bool operator !=(const interval &i,const l_real &r) throw() { return Inf(i)!=r || Sup(i)!=r; } 00635 bool operator <(const interval &i,const l_real &r) throw() { return false; } 00636 bool operator >(const interval &i,const l_real &r) throw() { return Inf(i)<r && Sup(i)>r; } 00637 bool operator <=(const interval &i,const l_real &r) throw() { return Inf(i)==r && Sup(i)==r; } 00638 bool operator >=(const interval &i,const l_real &r) throw() { return Inf(i)<=r && Sup(i)>=r; } 00639 00640 bool operator ==(const l_real &r,const interval &i) throw() { return Inf(i)==r && Sup(i)==r; } 00641 bool operator !=(const l_real &r,const interval &i) throw() { return Inf(i)!=r || Sup(i)!=r; } 00642 bool operator <(const l_real &r,const interval &i) throw() { return Inf(i)<r && Sup(i)>r; } 00643 bool operator >(const l_real &r,const interval &i) throw() { return false; } 00644 bool operator <=(const l_real &r,const interval &i) throw() { return Inf(i)<=r && Sup(i)>=r; } 00645 bool operator >=(const l_real &r,const interval &i) throw() { return Inf(i)==r && Sup(i)==r; } 00646 00647 bool operator ==(const idotprecision &i,const l_real &r) throw() { return Inf(i)==r && Sup(i)==r; } 00648 bool operator !=(const idotprecision &i,const l_real &r) throw() { return Inf(i)!=r || Sup(i)!=r; } 00649 bool operator <(const idotprecision &i,const l_real &r) throw() { return false; } 00650 bool operator >(const idotprecision &i,const l_real &r) throw() { return Inf(i)<r && Sup(i)>r; } 00651 bool operator <=(const idotprecision &i,const l_real &r) throw() { return Inf(i)==r && Sup(i)==r; } 00652 bool operator >=(const idotprecision &i,const l_real &r) throw() { return Inf(i)<=r && Sup(i)>=r; } 00653 00654 bool operator ==(const l_real &r,const idotprecision &i) throw() { return Inf(i)==r && Sup(i)==r; } 00655 bool operator !=(const l_real &r,const idotprecision &i) throw() { return Inf(i)!=r || Sup(i)!=r; } 00656 bool operator <(const l_real &r,const idotprecision &i) throw() { return Inf(i)<r && Sup(i)>r; } 00657 bool operator >(const l_real &r,const idotprecision &i) throw() { return false; } 00658 bool operator <=(const l_real &r,const idotprecision &i) throw() { return Inf(i)<=r && Sup(i)>=r; } 00659 bool operator >=(const l_real &r,const idotprecision &i) throw() { return Inf(i)==r && Sup(i)==r; } 00660 00661 real & real::operator = (const l_real& a) throw() 00662 { // Blomquist, 12.11.2008; 00663 real x(a); 00664 return *this = x; 00665 } 00666 00667 //--------------------------------------------------------------------------- 00668 // Other functions: 00669 // 00670 l_real abs(const l_real& lr1) throw() 00671 { 00672 l_real lr2; 00673 dotprecision dot(0.0); 00674 lr1._akku_add(dot); 00675 00676 if (dot < 0.0) 00677 dot = -dot; 00678 00679 lr2._akku_out(dot); 00680 00681 return lr2; 00682 } 00683 00684 int sign(const l_real& lr) throw() 00685 { 00686 dotprecision dot(0.0); 00687 lr._akku_add(dot); 00688 return sign(dot); 00689 } 00690 00691 l_real adjust(const l_real & x) throw() 00692 { 00693 l_real y; 00694 00695 if (x.prec == stagprec) 00696 y = x; 00697 else if (x.prec > stagprec) 00698 { 00699 dotprecision dot(0.0); 00700 x._akku_add(dot); 00701 y._akku_out(dot); 00702 } else 00703 { 00704 int i; 00705 for (i = 0; i <= stagprec-x.prec-1; i++) 00706 y.data[i] = 0; 00707 for (i = stagprec-x.prec; i <= stagprec-1; i++) 00708 y.data[i] = x.data[i-(stagprec-x.prec)]; 00709 } 00710 00711 return y; 00712 } 00713 00725 int expo_sm(const l_real& x) 00726 // Calculating expo(x[k]) of the smallest |x[k]|<>0. 00727 { 00728 int k(x.prec); 00729 l_real y(x); 00730 00731 while (y.elem(k)==0 && k>1) k--; 00732 return expo(y.elem(k)); 00733 } 00734 00744 int expo_gr(const l_real& x) 00745 // Calculating expo(x[k]) of the greatest |x[k]|. 00746 { 00747 int k(1),p(x.prec); 00748 l_real y(x); 00749 00750 while (y.elem(k)==0 && k<p) k++; 00751 return expo(y.elem(k)); 00752 } 00753 00754 00755 } // namespace cxsc 00756