C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
l_real.cpp
1 /*
2 ** CXSC is a C++ library for eXtended Scientific Computing (V 2.5.4)
3 **
4 ** Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
5 ** Universitaet Karlsruhe, Germany
6 ** (C) 2000-2014 Wiss. Rechnen/Softwaretechnologie
7 ** Universitaet Wuppertal, Germany
8 **
9 ** This library is free software; you can redistribute it and/or
10 ** modify it under the terms of the GNU Library General Public
11 ** License as published by the Free Software Foundation; either
12 ** version 2 of the License, or (at your option) any later version.
13 **
14 ** This library is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ** Library General Public License for more details.
18 **
19 ** You should have received a copy of the GNU Library General Public
20 ** License along with this library; if not, write to the Free
21 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23 
24 /* CVS $Id: l_real.cpp,v 1.34 2014/01/30 17:23:46 cxsc Exp $ */
25 
26 #include <memory.h>
27 
28 #include "l_real.hpp"
29 #include "dot.hpp"
30 #include "idot.hpp"
31 #include "interval.hpp"
32 #include "l_interval.hpp"
33 
34 namespace cxsc {
35 
36 #ifdef CXSC_USE_TLS_PREC
37 
38 #ifdef _WIN32
39 __declspec(thread) int stagprec = 2;
40 #else
41 __thread int stagprec = 2;
42 #endif
43 
44 #else
45 
46 int stagprec = 2;
47 
48 #endif
49 
50 
51 interval::interval(const l_real & a) throw()
52 {
53  dotprecision dot(a);
54  rnd(dot,inf,sup);
55 }
56 
57 interval & interval::operator =(const l_real & a) throw()
58 {
59  dotprecision dot(a);
60  rnd(dot,inf,sup);
61  return *this;
62 }
63 
64 idotprecision::idotprecision(const l_real & a) throw() : inf(0),
65  sup(0)
66 {
67  *this+=a;
68 }
69 
71  inf(0),
72  sup(0)
73 {
74  inf+=a;
75  sup+=b;
76 }
77 
78 
79 
80 void l_real::_clear(int p) throw()
81 {
82  // filling a l_real number from element p up to the end with zero.
83  for (int i=p; i<=prec; i++)
84  this->elem(i)=0.0;
85 }
86 
87 
88 void l_real::_akku_out(const dotprecision& d) throw()
89 {
90  // The dotprecision value is rounded to the activated l_real number
91  // in its own precision.
92  dotprecision dot(d);
93  _clear(1);
94  this->elem(1) = rnd(dot);
95  if (prec>1)
96  {
97  int i=2, weiter;
98  do {
99  dot -= this->elem(i-1);
100  this->elem(i) = rnd(dot);
101  i++;
102  weiter = this->elem(i-1) != 0; // Blomquist 02.10.02.
103  } while (weiter && (i <= prec));
104  }
105 }
106 
107 void l_real::_akku_out_up(const dotprecision& d) throw()
108 {
109  // The dotprecision value is rounded up to the activated l_real
110  // number in its own precision.
111  // Blomquist, 20.11.2006;
112  bool weiter;
113  dotprecision dot(d);
114  _clear(1);
115  this->elem(1) = (prec==1)? rnd(dot,RND_UP) : rnd(dot);
116  if (prec>1)
117  {
118  int i=2;
119  do {
120  dot -= this->elem(i-1);
121  weiter = (sign(dot) != 0);
122  if (weiter)
123  this->elem(i) = (i==prec)?
124  rnd(dot,RND_UP) : rnd(dot);
125  i++;
126  } while (weiter && (i <= prec));
127  }
128 }
129 
130 void l_real::_akku_out_down(const dotprecision& d) throw()
131 {
132  // The dotprecision value is rounded up to the activated l_real
133  // number in its own precision.
134  // Blomquist, 20.11.2006;
135  bool weiter;
136  dotprecision dot(d);
137  _clear(1);
138  this->elem(1) = (prec==1)? rnd(dot,RND_DOWN) : rnd(dot);
139  if (prec>1)
140  {
141  int i=2;
142  do {
143  dot -= this->elem(i-1);
144  weiter = (sign(dot) != 0);
145  if (weiter)
146  this->elem(i) = (i==prec)?
147  rnd(dot,RND_DOWN) : rnd(dot);
148  i++;
149  } while (weiter && (i <= prec));
150  }
151 }
152 
153 void l_real::_akku_add(dotprecision& d) const throw()
154 {
155  // adding the activated l_real number to the accumulator d.
156  for (int i=1; i<=prec; i++)
157  {
158  if (this->elem(i) != 0) d += this->elem(i);
159  }
160 }
161 
162 void l_real::_akku_sub(dotprecision& d) const throw()
163 {
164  // subtracting the activated l_real number from the accumulator d.
165  for (int i=1; i<=prec; i++)
166  {
167  if (this->elem(i) != 0) d -= this->elem(i);
168  }
169 }
170 
171 //---------------------------------------------------------------------------
172 // Constructors and destructors
173 //
174 l_real::l_real() throw()
175 {
176  data=new real[stagprec];
177  if(data)
178  prec=stagprec;
179  else
180  prec=0;
181 }
182 
183 l_real::~l_real() throw()
184 {
185  delete [] data;
186 }
187 
188 l_real::l_real(const l_real& lr) throw()
189  : data(new real[lr.prec])
190 {
191  if(data)
192  {
193  prec=lr.prec;
194  memcpy(data,lr.data,sizeof(real)*prec);
195  } else
196  prec=0;
197 }
198 
199 l_real::l_real(const real & r) throw()
200  : prec(1),
201  data(new real[1])
202 {
203  data[0]=r;
204 }
205 
206 l_real::l_real(const double & db) throw()
207  : prec(1), data(new real[1])
208 {
209  data[0] = db; // Blomquist 10.09.02. Deklaration in l_real.hpp
210 }
211 
212 l_real::l_real(int i) throw()
213  : prec(1),
214  data(new real[1])
215 {
216  data[0]=i;
217 }
218 
219 l_real::l_real(long i) throw()
220  : prec(1),
221  data(new real[1])
222 {
223  data[0]=i;
224 }
225 //---------------------------------------------------------------------------
226 // Type transfers
227 
228 real::real(const l_real& lr) throw()
229 {
230  dotprecision dot(0.0);
231  lr._akku_add(dot);
232  w=rnd(dot).w;
233 }
234 
235 dotprecision::dotprecision(const l_real& lr) throw() : akku(new a_btyp[A_LENGTH])
236 {
237  memset(akku,0,BUFFERSIZE);
238  lr._akku_add(*this);
239 }
240 
242 {
243  memset(akku,0,BUFFERSIZE);
244  lr._akku_add(*this);
245  return *this;
246 }
247 
248 l_real::l_real(const dotprecision & d) throw() : prec(stagprec),
249  data(new real[prec])
250 {
251  _akku_out(d);
252 }
253 
254 //---------------------------------------------------------------------------
255 // assignments
256 //
257 l_real& l_real::operator=(const real& r) throw()
258 {
259  // Siehe _l_real(real..)
260 
261  if(prec!=1)
262  {
263  delete [] data;
264  data=new real[1];
265  if(data)
266  prec=1;
267  else
268  prec=0;
269  }
270  elem(1)=r;
271  return *this;
272 }
273 
274 l_real& l_real::operator=(const l_real& lr) throw()
275 {
276  // Siehe c++-FAQ assignment-operators.html#[12.1]
277 
278  // This code gracefully (albeit implicitly) handles self assignment
279  real* tmp = new real[lr.prec];
280  // It would be OK if an exception got thrown here
281 
282  if((prec=lr.prec)>0)
283  memcpy(tmp,lr.data,sizeof(real)*prec);
284 
285  delete [] data;
286  data = tmp;
287  return *this;
288 }
289 
291 {
292  if(prec!=stagprec)
293  {
294  delete [] data;
295  data=new real[prec=stagprec];
296  }
297  _akku_out(d);
298  return *this;
299 }
300 
301 
302 real& l_real::operator[](int i) const throw()
303 {
304  if (i<1 || i>prec)
305  {
306  // throw!
307  i=1;
308  }
309  return data[i-1];
310 }
311 
312 int StagPrec(const l_real& lr) throw()
313 {
314  return lr.prec;
315 }
316 
317 std::istream& operator>>(std::istream& s, l_real& lr) throw()
318 {
319  dotprecision dot;
320  s >> dot;
321  lr._akku_out(dot);
322  return s;
323 }
324 
325 std::ostream& operator<<(std::ostream& s, const l_real& lr) throw()
326 {
327  dotprecision dot(0.0);
328  lr._akku_add(dot);
329  s << dot;
330  return s;
331 }
332 std::string& operator>>(std::string& s, l_real& lr) throw()
333 {
334  dotprecision dot;
335  s >> dot;
336  lr._akku_out(dot);
337  return s;
338 }
339 
340 std::string& operator<<(std::string& s, const l_real& lr) throw()
341 {
342  dotprecision dot(0.0);
343  lr._akku_add(dot);
344  s << dot;
345  return s;
346 }
347 void operator>>(const std::string& s, l_real& lr) throw()
348 {
349  std::string r(s);
350  r>>lr;
351 }
352 void operator>>(const char *s, l_real& lr) throw()
353 {
354  std::string r(s);
355  r>>lr;
356 }
357 
358 
359 void accumulate(dotprecision& d, const real& r, const l_real& lr) throw()
360 {
361 // accumulate(d, l_real(r), lr); Blomquist: Old version, not from me!
362  for (int i=1; i<=lr.prec; i++) // Blomquist: My new version, 24.09.02
363  accumulate(d, lr.elem(i), r);
364 }
365 
366 void accumulate(dotprecision& d, const l_real& lr, const real& r) throw()
367 {
368 // accumulate(d, lr, l_real(r)); Blomquist: Old version, not from me!
369  for (int i=1; i<=lr.prec; i++) // Blomquist: My new version, 24.09.02
370  accumulate(d, lr.elem(i), r);
371 }
372 
373 void accumulate(dotprecision& d, const l_real& lr1, const l_real&lr2) throw()
374 {
375  int i, j;
376 
377  for (i=1; i<=lr1.prec; i++)
378  for (j=1; j<=lr2.prec; j++)
379 // if (abs(lr1.elem(i) * lr2.elem(j)) > MinReal) // alte Zeile von Toussaint
380  accumulate(d, lr1.elem(i), lr2.elem(j));
381 }
382 
383 void accumulate(idotprecision & a, const real & b, const l_real & c) throw() { accumulate(a,l_interval(b),l_interval(c)); }
384 void accumulate(idotprecision & a, const l_real & b, const real & c) throw() { accumulate(a,l_interval(b),l_interval(c)); }
385 void accumulate(idotprecision & a, const l_real & b, const l_real & c) throw() { accumulate(a,l_interval(b),l_interval(c)); }
386 
388 { // Blomquist, 20.11.2006;
389  l_real lr;
390  lr._akku_out_up(a);
391  return lr;
392 }
393 
395 { // Blomquist, 20.11.2006;
396  l_real lr;
397  lr._akku_out_down(a);
398  return lr;
399 }
400 
401 l_real operator-(const l_real& lr, const real& r) throw() { return lr-_l_real(r); }
402 l_real operator-(const real& r, const l_real& lr) throw() { return _l_real(r)-lr; }
403 l_real operator+(const l_real& lr, const real& r) throw() { return lr+_l_real(r); }
404 l_real operator+(const real& r, const l_real& lr) throw() { return _l_real(r)+lr; }
405 l_real operator*(const l_real& lr, const real& r) throw() { return lr*_l_real(r); }
406 l_real operator*(const real& r, const l_real& lr) throw() { return _l_real(r)*lr; }
407 l_real operator/(const l_real& lr, const real& r) throw() { return lr/_l_real(r); }
408 l_real operator/(const real& r, const l_real& lr) throw() { return _l_real(r)/lr; }
409 
410 dotprecision operator-(const l_real& lr, const dotprecision& r) throw()
411 {
412  return _dotprecision(lr)-r;
413 }
414 dotprecision operator-(const dotprecision& r, const l_real& lr) throw()
415 {
416  return r-_dotprecision(lr);
417 }
418 dotprecision operator+(const l_real& lr, const dotprecision& r) throw()
419 {
420  return _dotprecision(lr)+r;
421 }
422 dotprecision operator+(const dotprecision& r, const l_real& lr) throw()
423 {
424  return r+_dotprecision(lr);
425 }
426 
427 
428 l_real& operator-=(l_real& lr, const real& r) throw()
429 { lr = lr-_l_real(r); return lr; }
430 
431 l_real& operator+=(l_real& lr, const real& r) throw()
432 { lr = lr+_l_real(r); return lr; }
433 
434 l_real& operator*=(l_real& lr, const real& r) throw()
435 { lr = lr*_l_real(r); return lr; }
436 
437 l_real& operator/=(l_real& lr, const real& r) throw()
438 { lr = lr/_l_real(r); return lr; }
439 
440 real& operator-=(real& r, const l_real& lr) throw() { r = r-_real(lr); return r; }
441 real& operator+=(real& r, const l_real& lr) throw() { r = r+_real(lr); return r; }
442 real& operator*=(real& r, const l_real& lr) throw() { r = r*_real(lr); return r; }
443 real& operator/=(real& r, const l_real& lr) throw() { r = r/_real(lr); return r; }
444 
445 bool operator==(const l_real& lr, const real& r) throw() { return lr==_l_real(r); }
446 bool operator==(const real& r, const l_real& lr) throw() { return _l_real(r)==lr; }
447 bool operator!=(const l_real& lr, const real& r) throw() { return lr!=_l_real(r); }
448 bool operator!=(const real& r, const l_real& lr) throw() { return _l_real(r)!=lr; }
449 
450 bool operator<=(const l_real& lr, const real& r) throw() { return lr<=_l_real(r); }
451 bool operator<=(const real& r, const l_real& lr) throw() { return _l_real(r)<=lr; }
452 bool operator>=(const l_real& lr, const real& r) throw() { return lr>=_l_real(r); }
453 bool operator>=(const real& r, const l_real& lr) throw() { return _l_real(r)>=lr; }
454 
455 bool operator<(const l_real& lr, const real& r) throw() { return lr<_l_real(r); }
456 bool operator<(const real& r, const l_real& lr) throw() { return _l_real(r)<lr; }
457 bool operator>(const l_real& lr, const real& r) throw() { return lr>_l_real(r); }
458 bool operator>(const real& r, const l_real& lr) throw() { return _l_real(r)>lr; }
459 
460 bool operator==(const l_real& lr, const dotprecision& d) throw() { return _dotprecision(lr)==d; }
461 bool operator==(const dotprecision& d, const l_real& lr) throw() { return d==_dotprecision(lr); }
462 bool operator!=(const l_real& lr, const dotprecision& d) throw() { return _dotprecision(lr)!=d; }
463 bool operator!=(const dotprecision& d, const l_real& lr) throw() { return d!=_dotprecision(lr); }
464 
465 bool operator<=(const l_real& lr, const dotprecision& d) throw() { return _dotprecision(lr)<=d; }
466 bool operator<=(const dotprecision& d, const l_real& lr) throw() { return d<=_dotprecision(lr); }
467 bool operator>=(const l_real& lr, const dotprecision& d) throw() { return _dotprecision(lr)>=d; }
468 bool operator>=(const dotprecision& d, const l_real& lr) throw() { return d>=_dotprecision(lr); }
469 
470 bool operator<(const l_real& lr, const dotprecision& d) throw() { return _dotprecision(lr)<d; }
471 bool operator<(const dotprecision& d, const l_real& lr) throw() { return d<_dotprecision(lr); }
472 bool operator>(const l_real& lr, const dotprecision& d) throw() { return _dotprecision(lr)>d; }
473 bool operator>(const dotprecision& d, const l_real& lr) throw() { return d>_dotprecision(lr); }
474 
475 l_real operator-(const l_real& lr1) throw()
476 {
477  l_real lr2(lr1);
478  for (int i=1; i<=lr1.prec; i++)
479  lr2.elem(i) = -(lr1.elem(i));
480  return lr2;
481 }
482 l_real operator+(const l_real& lr1) throw()
483 {
484  return lr1;
485 }
486 
487 l_real operator-(const l_real& lr1, const l_real& lr2) throw()
488 {
489  l_real lr3;
490  dotprecision dot(0.0);
491  lr1._akku_add(dot);
492  lr2._akku_sub(dot);
493  lr3._akku_out(dot);
494  return lr3;
495 }
496 
497 l_real operator+(const l_real& lr1, const l_real& lr2) throw()
498 {
499  l_real lr3;
500  dotprecision dot(0.0);
501  lr1._akku_add(dot);
502  lr2._akku_add(dot);
503  lr3._akku_out(dot);
504 
505  return lr3;
506 }
507 
508 l_real operator*(const l_real& lr1, const l_real& lr2) throw()
509 {
510  l_real lr3;
511  dotprecision dot(0.0);
512  accumulate(dot, lr1, lr2);
513  lr3._akku_out(dot);
514  return lr3;
515 }
516 
517 l_real operator/(const l_real& lr1, const l_real& lr2) throw(DIV_BY_ZERO)
518 { // Blomquist, 09.12.02; throw() ---> throw(DIV_BY_ZERO)
519  real a, b;
520  l_real lr3;
521  lr3._clear(1);
522  dotprecision dot1(0.0);
523  dotprecision dot2(0.0);
524  lr1._akku_add(dot1);
525  lr2._akku_add(dot2);
526  a = rnd(dot1, RND_DOWN);
527  b = rnd(dot2, RND_UP);
528  if (!b)
529  { // Blomquist: cxscthrow(DIV_BY_ ... )
530  cxscthrow(DIV_BY_ZERO("l_real operator/(const l_real&, const l_real&)"));
531  } else
532  {
533  lr3.elem(1) = a/b;
534  for (int i=2; i<=stagprec; i++)
535  {
536  if (!a)
537  break;
538  for (int j=1; j<=lr2.prec; j++)
539  if (!!lr3.elem(i-1) && !!lr2.elem(j) )
540  accumulate(dot1, lr3.elem(i-1), -lr2.elem(j));
541  a = rnd(dot1, RND_DOWN);
542  lr3.elem(i) = a/b;
543  }
544  } // no division by zero
545  return lr3;
546 }
547 
548 
549 l_real & operator-=(l_real& lr1, const l_real& lr2) throw() { return lr1 = lr1-lr2; }
550 l_real & operator+=(l_real& lr1, const l_real& lr2) throw() { return lr1 = lr1+lr2; }
551 l_real & operator*=(l_real& lr1, const l_real& lr2) throw() { return lr1 = lr1*lr2; }
552 l_real & operator/=(l_real& lr1, const l_real& lr2) throw() { return lr1 = lr1/lr2; }
553 
554 bool operator==(const l_real& lr1, const l_real& lr2) throw()
555 {
556  dotprecision dot1(0.0);
557  dotprecision dot2(0.0);
558  lr1._akku_add(dot1);
559  lr2._akku_add(dot2);
560  return (dot1==dot2);
561 }
562 
563 bool operator<=(const l_real& lr1, const l_real& lr2) throw()
564 {
565  dotprecision dot1(0.0);
566  dotprecision dot2(0.0);
567  lr1._akku_add(dot1);
568  lr2._akku_add(dot2);
569  return (dot1<=dot2);
570 }
571 
572 bool operator!(const l_real& lr) throw()
573 {
574  dotprecision dot(0.0);
575  lr._akku_add(dot);
576  return (!dot);
577 }
578 
579 bool operator!=(const l_real& lr1, const l_real& lr2) throw() { return !(lr1==lr2); }
580 bool operator< (const l_real& lr1, const l_real& lr2) throw() { return !(lr2<=lr1); }
581 bool operator> (const l_real& lr1, const l_real& lr2) throw() { return !(lr1<=lr2); }
582 bool operator>=(const l_real& lr1, const l_real& lr2) throw() { return (lr2<=lr1); }
583 
584 // ID-LR
585 
586  idotprecision operator +(const idotprecision &a,const l_real &b) throw()
587 {
588  return idotprecision(a.inf+b,a.sup+b);
589 }
590 
591  idotprecision operator +(const l_real &b,const idotprecision &a) throw()
592 {
593  return idotprecision(a.inf+b,a.sup+b);
594 }
595 
596  idotprecision operator -(const idotprecision &a,const l_real &b) throw()
597 {
598  return idotprecision(a.inf-b,a.sup-b);
599 }
600 
601  idotprecision operator -(const l_real &a,const idotprecision &b) throw()
602 {
603  return idotprecision(a-b.sup,a-b.inf);
604 }
605 
606 idotprecision operator |(const l_real &a,const idotprecision &b) throw()
607 {
608  return idotprecision((a<b.inf)?_dotprecision(a):b.inf,(a>b.sup)?_dotprecision(a):b.sup);
609 }
610 
611  idotprecision operator |(const idotprecision &a,const l_real &b) throw()
612 {
613  return idotprecision((a.inf<b)?a.inf:_dotprecision(b),(a.sup>b)?a.sup:_dotprecision(b));
614 }
615 
616  idotprecision operator &(const l_real &a,const idotprecision &b) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL)
617 {
618  return idotprecision((a>b.inf)?_dotprecision(a):b.inf,(a<b.sup)?_dotprecision(a):b.sup);
619 }
620 
621  idotprecision operator &(const idotprecision &a,const l_real &b) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL)
622 {
623  return idotprecision((a.inf>b)?a.inf:_dotprecision(b),(a.sup<b)?a.sup:_dotprecision(b));
624 }
625 
626 // LR-ID
627 idotprecision & operator +=(idotprecision &a,const l_real &b) throw() { return a+=dotprecision(b); }
628 idotprecision & operator -=(idotprecision &a,const l_real &b) throw() { return a-=dotprecision(b); }
629 idotprecision & operator |=(idotprecision &a,const l_real &b) throw() { return a|=dotprecision(b); }
630 idotprecision & operator &=(idotprecision &a,const l_real &b) throw(ERROR_IDOTPRECISION_EMPTY_INTERVAL) { return a&=dotprecision(b); }
631 
632 
633 bool operator ==(const interval &i,const l_real &r) throw() { return Inf(i)==r && Sup(i)==r; }
634 bool operator !=(const interval &i,const l_real &r) throw() { return Inf(i)!=r || Sup(i)!=r; }
635 bool operator <(const interval &i,const l_real &r) throw() { return false; }
636 bool operator >(const interval &i,const l_real &r) throw() { return Inf(i)<r && Sup(i)>r; }
637 bool operator <=(const interval &i,const l_real &r) throw() { return Inf(i)==r && Sup(i)==r; }
638 bool operator >=(const interval &i,const l_real &r) throw() { return Inf(i)<=r && Sup(i)>=r; }
639 
640 bool operator ==(const l_real &r,const interval &i) throw() { return Inf(i)==r && Sup(i)==r; }
641 bool operator !=(const l_real &r,const interval &i) throw() { return Inf(i)!=r || Sup(i)!=r; }
642 bool operator <(const l_real &r,const interval &i) throw() { return Inf(i)<r && Sup(i)>r; }
643 bool operator >(const l_real &r,const interval &i) throw() { return false; }
644 bool operator <=(const l_real &r,const interval &i) throw() { return Inf(i)<=r && Sup(i)>=r; }
645 bool operator >=(const l_real &r,const interval &i) throw() { return Inf(i)==r && Sup(i)==r; }
646 
647 bool operator ==(const idotprecision &i,const l_real &r) throw() { return Inf(i)==r && Sup(i)==r; }
648 bool operator !=(const idotprecision &i,const l_real &r) throw() { return Inf(i)!=r || Sup(i)!=r; }
649 bool operator <(const idotprecision &i,const l_real &r) throw() { return false; }
650 bool operator >(const idotprecision &i,const l_real &r) throw() { return Inf(i)<r && Sup(i)>r; }
651 bool operator <=(const idotprecision &i,const l_real &r) throw() { return Inf(i)==r && Sup(i)==r; }
652 bool operator >=(const idotprecision &i,const l_real &r) throw() { return Inf(i)<=r && Sup(i)>=r; }
653 
654 bool operator ==(const l_real &r,const idotprecision &i) throw() { return Inf(i)==r && Sup(i)==r; }
655 bool operator !=(const l_real &r,const idotprecision &i) throw() { return Inf(i)!=r || Sup(i)!=r; }
656 bool operator <(const l_real &r,const idotprecision &i) throw() { return Inf(i)<r && Sup(i)>r; }
657 bool operator >(const l_real &r,const idotprecision &i) throw() { return false; }
658 bool operator <=(const l_real &r,const idotprecision &i) throw() { return Inf(i)<=r && Sup(i)>=r; }
659 bool operator >=(const l_real &r,const idotprecision &i) throw() { return Inf(i)==r && Sup(i)==r; }
660 
661 real & real::operator = (const l_real& a) throw()
662 { // Blomquist, 12.11.2008;
663  real x(a);
664  return *this = x;
665 }
666 
667 //---------------------------------------------------------------------------
668 // Other functions:
669 //
670 l_real abs(const l_real& lr1) throw()
671 {
672  l_real lr2;
673  dotprecision dot(0.0);
674  lr1._akku_add(dot);
675 
676  if (dot < 0.0)
677  dot = -dot;
678 
679  lr2._akku_out(dot);
680 
681  return lr2;
682 }
683 
684 int sign(const l_real& lr) throw()
685 {
686  dotprecision dot(0.0);
687  lr._akku_add(dot);
688  return sign(dot);
689 }
690 
691 l_real adjust(const l_real & x) throw()
692 {
693  l_real y;
694 
695  if (x.prec == stagprec)
696  y = x;
697  else if (x.prec > stagprec)
698  {
699  dotprecision dot(0.0);
700  x._akku_add(dot);
701  y._akku_out(dot);
702  } else
703  {
704  int i;
705  for (i = 0; i <= stagprec-x.prec-1; i++)
706  y.data[i] = 0;
707  for (i = stagprec-x.prec; i <= stagprec-1; i++)
708  y.data[i] = x.data[i-(stagprec-x.prec)];
709  }
710 
711  return y;
712 }
713 
725 int expo_sm(const l_real& x)
726 // Calculating expo(x[k]) of the smallest |x[k]|<>0.
727 {
728  int k(x.prec);
729  l_real y(x);
730 
731  while (y.elem(k)==0 && k>1) k--;
732  return expo(y.elem(k));
733 }
734 
744 int expo_gr(const l_real& x)
745 // Calculating expo(x[k]) of the greatest |x[k]|.
746 {
747  int k(1),p(x.prec);
748  l_real y(x);
749 
750  while (y.elem(k)==0 && k<p) k++;
751  return expo(y.elem(k));
752 }
753 
754 
755 } // namespace cxsc
756 
dotprecision _dotprecision(const real &d)
Definition: dot.hpp:304
The Multiple-Precision Data Type l_interval.
Definition: l_interval.hpp:71
int expo_sm(const l_interval &x)
Definition: l_interval.inl:539
cimatrix & operator/=(cimatrix &m, const cinterval &c)
Implementation of division and allocation operation.
Definition: cimatrix.inl:1623
The Data Type idotprecision.
Definition: idot.hpp:47
The Multiple-Precision Data Type l_real.
Definition: l_real.hpp:77
The Data Type dotprecision.
Definition: dot.hpp:111
friend dotprecision & Sup(idotprecision &a)
Returns the supremum of a dotprecison interval.
Definition: idot.hpp:412
The namespace cxsc, providing all functionality of the class library C-XSC.
Definition: cdot.cpp:29
civector operator*(const cimatrix_subv &rv, const cinterval &s)
Implementation of multiplication operation.
Definition: cimatrix.inl:731
real & operator[](int) const
Access to the single components used to store the long data type value.
Definition: l_real.cpp:302
The Scalar Type interval.
Definition: interval.hpp:54
friend std::istream & operator>>(std::istream &s, idotprecision &a)
Implementation of standard input method.
Definition: idot.cpp:54
friend bool operator>=(const idotprecision &, const idotprecision &)
Implementation of standard greater-or-equal-than operation.
Definition: idot.inl:333
l_real & operator=(const l_real &)
Implementation of standard assigning operator.
Definition: l_real.cpp:274
friend bool operator>(const idotprecision &, const idotprecision &)
Implementation of standard greater-than operation.
Definition: idot.inl:341
friend idotprecision & operator|=(idotprecision &, const idotprecision &)
Allocates the convex hull of the arguments to the first argument.
Definition: idot.inl:271
l_real rnd_up(const dotprecision &a)
Rounds the argument up to the next l_real value.
Definition: l_real.cpp:387
friend std::ostream & operator<<(std::ostream &s, const idotprecision &a)
Implementation of standard output method.
Definition: idot.cpp:34
friend idotprecision operator&(const idotprecision &, const idotprecision &)
Returns the intersection of the arguments.
Definition: idot.inl:162
friend idotprecision operator-(const idotprecision &)
Implementation of standard algebraic negative sign operation.
Definition: idot.inl:109
friend bool operator==(const idotprecision &, const idotprecision &)
Implementation of standard equality operation.
Definition: idot.inl:310
dotprecision & operator=(const dotprecision &)
Implementation of standard assigning operator.
Definition: dot.cpp:84
friend idotprecision & operator+=(idotprecision &, const idotprecision &)
Implementation of standard algebraic addition and allocation operation.
Definition: idot.inl:241
friend idotprecision abs(const idotprecision &a)
Returns the absolute value of a dotprecision interval.
Definition: idot.inl:479
friend void accumulate(idotprecision &, const interval &, const interval &)
The accurate scalar product of the last two arguments added to the value of the first argument...
Definition: idot.cpp:129
friend bool operator!(const idotprecision &)
Implementation of standard negation operation.
Definition: idot.inl:475
dotprecision(void)
Constructor of class dotprecision.
Definition: dot.cpp:62
interval()
Constructor of class interval.
Definition: interval.hpp:64
friend idotprecision & operator&=(idotprecision &, const idotprecision &)
Allocates the intersection of the arguments to the first argument.
Definition: idot.inl:279
interval & operator=(const real &a)
Implementation of standard assigning operator.
Definition: interval.inl:52
friend idotprecision operator|(const idotprecision &, const idotprecision &)
Returns the convex hull of the arguments.
Definition: idot.inl:114
l_real(void)
Constructor of class l_real.
Definition: l_real.cpp:174
real(void)
Constructor of class real.
Definition: real.hpp:122
friend idotprecision & operator-=(idotprecision &, const idotprecision &)
Implementation of standard algebraic subtraction and allocation operation.
Definition: idot.inl:243
friend bool operator<=(const idotprecision &, const idotprecision &)
Implementation of standard less-or-equal-than operation.
Definition: idot.inl:329
idotprecision()
Constructor of class idotprecision.
Definition: idot.hpp:57
int expo_gr(const l_interval &x)
Definition: l_interval.inl:522
l_real rnd_down(const dotprecision &a)
Rounds the argument down to the next l_real value.
Definition: l_real.cpp:394
civector operator/(const cimatrix_subv &rv, const cinterval &s)
Implementation of division operation.
Definition: cimatrix.inl:730
cimatrix & operator*=(cimatrix &m, const cinterval &c)
Implementation of multiplication and allocation operation.
Definition: cimatrix.inl:1605
friend idotprecision operator+(const idotprecision &)
Implementation of standard algebraic positive sign operation.
Definition: idot.inl:110
The Scalar Type real.
Definition: real.hpp:113
friend bool operator!=(const idotprecision &, const idotprecision &)
Implementation of standard negated equality operation.
Definition: idot.inl:311
friend dotprecision & Inf(idotprecision &a)
Returns the infimum of a dotprecison interval.
Definition: idot.hpp:410
friend bool operator<(const idotprecision &, const idotprecision &)
Implementation of standard less-than operation.
Definition: idot.inl:337