C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
idot.inl
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: idot.inl,v 1.25 2014/01/30 17:23:45 cxsc Exp $ */
25 
26 namespace cxsc {
27 
28 // ---- Konstruktoren ----
29 
31  : inf(a), sup(b), k(0)
32 {
33  if(a>b)
34  cxscthrow(ERROR_IDOTPRECISION_EMPTY_INTERVAL("inline idotprecision::idotprecision(const dotprecision &a,const dotprecision &b)"));
35  inf.set_k(0);
36  sup.set_k(0);
37 }
38 
40  : inf(a.inf), sup(a.sup), k(a.k)
41 {
42  // if (a > b) errmon (ERR_INTERVAL(EMPTY)); throw!
43 }
44 
45 // ---- Typwandlungen ----
51 inline idotprecision _idotprecision(const real & a)
52 {
53  return idotprecision (a,a);
54 }
60 inline idotprecision _idotprecision(const real & a, const real & b)
61 {
62  return idotprecision (a,b);
63 }
69 inline idotprecision _unchecked_idotprecision(const real & a, const real & b) {
70  idotprecision tmp;
71  tmp.inf = a;
72  tmp.sup = b;
73  return tmp;
74 }
75 
82 {
83  return idotprecision (a,a);
84 }
91 {
92  return idotprecision (a,b);
93 }
100  idotprecision tmp;
101  tmp.inf = a;
102  tmp.sup = b;
103  return tmp;
104 }
105 
106 
107 // ---- Standardfunkt ---- (arithmetische Operatoren)
108 
109 inline idotprecision operator-(const idotprecision &a) noexcept { return idotprecision (-a.sup, -a.inf); }
110 inline idotprecision operator+(const idotprecision &a) noexcept { return a; }
111 
112 inline idotprecision operator+(const idotprecision &a,const idotprecision &b) noexcept { return idotprecision(a.inf+b.inf,a.sup+b.sup); }
113 inline idotprecision operator-(const idotprecision &a,const idotprecision &b) noexcept { return idotprecision(a.inf-b.sup,a.sup-b.inf); }
114 inline idotprecision operator |(const idotprecision &a,const idotprecision &b) noexcept
115 {
116  return idotprecision((a.inf<b.inf)?a.inf:b.inf,(a.sup>b.sup)?a.sup:b.sup);
117 }
118 // ID-D
119 
120 inline idotprecision operator +(const idotprecision &a,const dotprecision &b) noexcept { return idotprecision(a.inf+b,a.sup+b); }
121 inline idotprecision operator +(const dotprecision &b,const idotprecision &a) noexcept { return idotprecision(a.inf+b,a.sup+b); }
122 inline idotprecision operator -(const idotprecision &a,const dotprecision &b) noexcept { return idotprecision(a.inf-b,a.sup-b); }
123 inline idotprecision operator -(const dotprecision &a,const idotprecision &b) noexcept { return idotprecision(a-b.sup,a-b.inf); }
124 
125 inline idotprecision operator |(const dotprecision &a,const idotprecision &b) noexcept
126 {
127  return idotprecision((a<b.inf)?a:b.inf,(a>b.sup)?a:b.sup);
128 }
129 inline idotprecision operator |(const idotprecision &a,const dotprecision &b) noexcept
130 {
131  return idotprecision((a.inf<b)?a.inf:b,(a.sup>b)?a.sup:b);
132 }
133 inline idotprecision operator |(const dotprecision &a,const dotprecision &b) noexcept
134 {
135  if(a>b) return idotprecision(b,a);
136  else return idotprecision(a,b);
137 }
138 inline idotprecision operator &(const dotprecision &a,const idotprecision &b)
139 {
140  return idotprecision((a>b.inf)?a:b.inf,(a<b.sup)?a:b.sup);
141 }
142 inline idotprecision operator &(const idotprecision &a,const dotprecision &b)
143 {
144  return idotprecision((a.inf>b)?a.inf:b,(a.sup<b)?a.sup:b);
145 }
146 
147 // ID-L
148 
149 inline idotprecision operator +(const idotprecision &a,const long &b) noexcept { return idotprecision(a.inf+b,a.sup+b); }
150 inline idotprecision operator +(const long &b,const idotprecision &a) noexcept { return idotprecision(a.inf+b,a.sup+b); }
151 inline idotprecision operator -(const idotprecision &a,const long &b) noexcept { return idotprecision(a.inf-b,a.sup-b); }
152 inline idotprecision operator -(const long &a,const idotprecision &b) noexcept { return idotprecision(a-b.sup,a-b.inf); }
153 
154 inline idotprecision operator |(const long &a,const idotprecision &b) noexcept
155 {
156  return idotprecision((a<b.inf)?dotprecision(a):b.inf,(a>b.sup)?dotprecision(a):b.sup);
157 }
158 inline idotprecision operator |(const idotprecision &a,const long &b) noexcept
159 {
160  return idotprecision((a.inf<b)?a.inf:dotprecision(b),(a.sup>b)?a.sup:dotprecision(b));
161 }
162 inline idotprecision operator &(const idotprecision &a,const idotprecision &b)
163 {
164  return idotprecision((a.inf>b.inf)?a.inf:b.inf,(a.sup<b.sup)?a.sup:b.sup);
165 }
166 inline idotprecision operator &(const long &a,const idotprecision &b)
167 {
168  return idotprecision((a>b.inf)?dotprecision(a):b.inf,(a<b.sup)?dotprecision(a):b.sup);
169 }
170 inline idotprecision operator &(const idotprecision &a,const long &b)
171 {
172  return idotprecision((a.inf>b)?a.inf:dotprecision(b),(a.sup<b)?a.sup:dotprecision(b));
173 }
174 
175 // ID-R
176 
177 inline idotprecision operator +(const idotprecision &a,const real &b) noexcept { return idotprecision(a.inf+b,a.sup+b); }
178 inline idotprecision operator +(const real &b,const idotprecision &a) noexcept { return idotprecision(a.inf+b,a.sup+b); }
179 inline idotprecision operator -(const idotprecision &a,const real &b) noexcept { return idotprecision(a.inf-b,a.sup-b); }
180 inline idotprecision operator -(const real &a,const idotprecision &b) noexcept { return idotprecision(a-b.sup,a-b.inf); }
181 
182 inline idotprecision operator |(const real &a,const idotprecision &b) noexcept
183 {
184  return idotprecision((a<b.inf)?dotprecision(a):b.inf,(a>b.sup)?dotprecision(a):b.sup);
185 }
186 inline idotprecision operator |(const idotprecision &a,const real &b) noexcept
187 {
188  return idotprecision((a.inf<b)?a.inf:dotprecision(b),(a.sup>b)?a.sup:dotprecision(b));
189 }
190 inline idotprecision operator &(const real &a,const idotprecision &b)
191 {
192  return idotprecision((a>b.inf)?dotprecision(a):b.inf,(a<b.sup)?dotprecision(a):b.sup);
193 }
194 inline idotprecision operator &(const idotprecision &a,const real &b)
195 {
196  return idotprecision((a.inf>b)?a.inf:dotprecision(b),(a.sup<b)?a.sup:dotprecision(b));
197 }
198 
199 
200 // ID-I
201 
202 inline idotprecision operator +(const idotprecision &a,const interval &b) noexcept { return idotprecision(a.inf+b.inf,a.sup+b.sup); }
203 inline idotprecision operator +(const interval &b,const idotprecision &a) noexcept { return idotprecision(a.inf+b.inf,a.sup+b.sup); }
204 inline idotprecision operator -(const idotprecision &a,const interval &b) noexcept { return idotprecision(a.inf-b.sup,a.sup-b.inf); }
205 inline idotprecision operator -(const interval &a,const idotprecision &b) noexcept { return idotprecision(a.inf-b.sup,a.sup-b.inf); }
206 
207 inline idotprecision operator |(const interval &a,const idotprecision &b) noexcept
208 {
209  return idotprecision((a.inf<b.inf)?dotprecision(a.inf):b.inf,(a.sup>b.sup)?dotprecision(a.sup):b.sup);
210 }
211 inline idotprecision operator |(const idotprecision &a,const interval &b) noexcept
212 {
213  return idotprecision((a.inf<b.inf)?a.inf:dotprecision(b.inf),(a.sup>b.sup)?a.sup:dotprecision(b.sup));
214 }
215 inline idotprecision operator &(const interval &a,const idotprecision &b)
216 {
217  return idotprecision((a.inf>b.inf)?dotprecision(a.inf):b.inf,(a.sup<b.sup)?dotprecision(a.sup):b.sup);
218 }
219 inline idotprecision operator &(const idotprecision &a,const interval &b)
220 {
221  return idotprecision((a.inf>b.inf)?a.inf:dotprecision(b.inf),(a.sup<b.sup)?a.sup:dotprecision(b.sup));
222 }
223 
224 // D-R
225 
226 inline idotprecision operator |(const dotprecision &a,const real &b) noexcept
227 {
228  if(a<b)
229  return idotprecision(a,dotprecision(b));
230  return idotprecision(dotprecision(b),a);
231 }
232 inline idotprecision operator |(const real &b,const dotprecision &a) noexcept
233 {
234  if(a<b)
235  return idotprecision(a,dotprecision(b));
236  return idotprecision(dotprecision(b),a);
237 }
238 
239 
240 
241 inline idotprecision & operator +=(idotprecision &a,const idotprecision &b) noexcept { a.inf+=b.inf,a.sup+=b.sup; return a;}
242 inline idotprecision & operator +=(idotprecision &a,const dotprecision &b) noexcept { a.inf+=b,a.sup+=b; return a;}
243 inline idotprecision & operator -=(idotprecision &a,const idotprecision &b) noexcept { a.inf-=b.inf,a.sup-=b.sup; return a;}
244 inline idotprecision & operator -=(idotprecision &a,const dotprecision &b) noexcept { a.inf-=b,a.sup-=b; return a;}
245 inline idotprecision & operator +=(idotprecision &a,const interval &b) noexcept
246 {
247  a.inf+=Inf(b);
248  a.sup+=Sup(b);
249  return a;
250 }
251 inline idotprecision & operator -=(idotprecision &a,const interval &b) noexcept
252 {
253  a.inf-=Sup(b);
254  a.sup-=Inf(b);
255  return a;
256 }
257 inline idotprecision & operator +=(idotprecision &a,const real &b) noexcept
258 {
259  a.inf+=b;
260  a.sup+=b;
261  return a;
262 }
263 inline idotprecision & operator -=(idotprecision &a,const real &b) noexcept
264 {
265  a.inf-=b;
266  a.sup-=b;
267  return a;
268 }
269 
270 
271 inline idotprecision & operator |=(idotprecision &a,const idotprecision &b) noexcept
272 {
273  if(b.inf<a.inf)
274  a.inf=b.inf;
275  if(b.sup>a.sup)
276  a.sup=b.sup;
277  return a;
278 }
279 inline idotprecision & operator &=(idotprecision &a,const idotprecision &b)
280 {
281  if(b.inf>a.inf)
282  a.inf=b.inf;
283  if(b.sup<a.sup)
284  a.sup=b.sup;
285 
286  if(a.inf>a.sup)
287  cxscthrow(ERROR_IDOTPRECISION_EMPTY_INTERVAL("inline idotprecision & operator &=(idotprecision &a,const idotprecision &b)"));
288  return a;
289 }
290 inline idotprecision & operator |=(idotprecision &a,const dotprecision &b) noexcept
291 {
292  if(b<a.inf)
293  a.inf=b;
294  if(b>a.sup)
295  a.sup=b;
296  return a;
297 }
298 inline idotprecision & operator &=(idotprecision &a,const dotprecision &b)
299 {
300  if(b>a.inf)
301  a.inf=b;
302  if(b<a.sup)
303  a.sup=b;
304  if(a.inf>a.sup)
305  cxscthrow(ERROR_IDOTPRECISION_EMPTY_INTERVAL("inline idotprecision & operator &=(idotprecision &a,const dotprecision &b)"));
306  return a;
307 }
308 
309 // --- Vergleichsoperationen ----
310 inline bool operator ==(const idotprecision &a,const idotprecision &b) noexcept { return(a.inf==b.inf && a.sup==b.sup); }
311 inline bool operator !=(const idotprecision &a,const idotprecision &b) noexcept { return(a.inf!=b.inf || a.sup!=b.sup); }
312 inline bool operator ==(const dotprecision &r,const idotprecision &a) noexcept { return(r==a.inf && r==a.sup); }
313 inline bool operator !=(const dotprecision &r,const idotprecision &a) noexcept { return(r!=a.inf || r!=a.sup); }
314 inline bool operator ==(const idotprecision &a,const dotprecision &r) noexcept { return(r==a.inf && r==a.sup); }
315 inline bool operator !=(const idotprecision &a,const dotprecision &r) noexcept { return(r!=a.inf || r!=a.sup); }
316 
317 inline bool operator ==(const real &r,const idotprecision &a) noexcept { return(r==a.inf && r==a.sup); }
318 inline bool operator !=(const real &r,const idotprecision &a) noexcept { return(r!=a.inf || r!=a.sup); }
319 inline bool operator ==(const idotprecision &a,const real &r) noexcept { return(r==a.inf && r==a.sup); }
320 inline bool operator !=(const idotprecision &a,const real &r) noexcept { return(r!=a.inf || r!=a.sup); }
321 
322 inline bool operator ==(const interval &a,const idotprecision &b) noexcept { return(Inf(a)==b.inf && Sup(a)==b.sup); }
323 inline bool operator !=(const interval &a,const idotprecision &b) noexcept { return(Inf(a)!=b.inf || Sup(a)!=b.sup); }
324 inline bool operator ==(const idotprecision &a,const interval &b) noexcept { return(a.inf==Inf(b) && a.sup==Sup(b)); }
325 inline bool operator !=(const idotprecision &a,const interval &b) noexcept { return(a.inf!=Inf(b) || a.sup!=Sup(b)); }
326 
327 // --- Mengenvergleiche ---
328 // <,>,...
329 inline bool operator <=(const idotprecision &a,const idotprecision &b) noexcept
330 {
331  return(a.inf>=b.inf && a.sup<=b.sup);
332 }
333 inline bool operator >=(const idotprecision &a,const idotprecision &b) noexcept
334 {
335  return(a.inf<=b.inf && a.sup>=b.sup);
336 }
337 inline bool operator <(const idotprecision &a,const idotprecision &b) noexcept
338 {
339  return(a.inf>b.inf && a.sup<b.sup);
340 }
341 inline bool operator >(const idotprecision &a,const idotprecision &b) noexcept
342 {
343  return(a.inf<b.inf && a.sup>b.sup);
344 }
345 
346 inline bool operator <=(const dotprecision &a,const idotprecision &b) noexcept
347 {
348  return(a>=b.inf && a<=b.sup);
349 }
350 inline bool operator >=(const dotprecision &a,const idotprecision &b) noexcept
351 {
352  return(a<=b.inf && a>=b.sup);
353 }
354 inline bool operator <(const dotprecision &a,const idotprecision &b) noexcept
355 {
356  return(a>b.inf && a<b.sup);
357 }
358 
359 inline bool operator <=(const idotprecision &a,const dotprecision &b) noexcept
360 {
361  return(a.inf>=b && a.sup<=b);
362 }
363 inline bool operator >=(const idotprecision &a,const dotprecision &b) noexcept
364 {
365  return(a.inf<=b && a.sup>=b);
366 }
367 inline bool operator >(const idotprecision &a,const dotprecision &b) noexcept
368 {
369  return(a.inf<b && a.sup>b);
370 }
371 
372 inline bool operator <=(const real &a,const idotprecision &b) noexcept
373 {
374  return(a>=b.inf && a<=b.sup);
375 }
376 inline bool operator >=(const real &a,const idotprecision &b) noexcept
377 {
378  return(a<=b.inf && a>=b.sup);
379 }
380 inline bool operator <(const real &a,const idotprecision &b) noexcept
381 {
382  return(a>b.inf && a<b.sup);
383 }
384 
385 inline bool operator <=(const idotprecision &a,const real &b) noexcept
386 {
387  return(a.inf>=b && a.sup<=b);
388 }
389 inline bool operator >=(const idotprecision &a,const real &b) noexcept
390 {
391  return(a.inf<=b && a.sup>=b);
392 }
393 inline bool operator >(const idotprecision &a,const real &b) noexcept
394 {
395  return(a.inf<b && a.sup>b);
396 }
397 
398 inline bool operator <=(const interval &a,const idotprecision &b) noexcept
399 {
400  return(Inf(a)>=b.inf && Sup(a)<=b.sup);
401 }
402 inline bool operator >=(const interval &a,const idotprecision &b) noexcept
403 {
404  return(Inf(a)<=b.inf && Sup(a)>=b.sup);
405 }
406 inline bool operator <(const interval &a,const idotprecision &b) noexcept
407 {
408  return(Inf(a)>b.inf && Sup(a)<b.sup);
409 }
410 inline bool operator >(const interval &a,const idotprecision &b) noexcept
411 {
412  return(Inf(a)<b.inf && Sup(a)>b.sup);
413 }
414 
415 inline bool operator <=(const idotprecision &a,const interval &b) noexcept
416 {
417  return(a.inf>=Inf(b) && a.sup<=Sup(b));
418 }
419 inline bool operator >=(const idotprecision &a,const interval &b) noexcept
420 {
421  return(a.inf<=Inf(b) && a.sup>=Sup(b));
422 }
423 inline bool operator <(const idotprecision &a,const interval &b) noexcept
424 {
425  return(a.inf>Inf(b) && a.sup<Sup(b));
426 }
427 inline bool operator >(const idotprecision &a,const interval &b) noexcept
428 {
429  return(a.inf<Inf(b) && a.sup>Sup(b));
430 }
431 
432 // ----- Funktionen -----
433 
434 inline idotprecision & SetInf (idotprecision & a, const dotprecision & b) noexcept
435 { // ggf. exception
436  a.inf=b;
437  return a;
438 }
439 inline idotprecision & SetSup (idotprecision & a, const dotprecision & b) noexcept
440 {
441  a.sup=b;
442  return a;
443 }
444 inline idotprecision & SetInf (idotprecision & a, const real & b) noexcept
445 { // ggf. exception
446  a.inf=b;
447  return a;
448 }
449 inline idotprecision & SetSup (idotprecision & a, const real & b) noexcept
450 {
451  a.sup=b;
452  return a;
453 }
454 inline idotprecision & UncheckedSetInf (idotprecision & a, const dotprecision & b) noexcept
455 {
456  a.inf=b;
457  return a;
458 }
459 inline idotprecision & UncheckedSetSup (idotprecision & a, const dotprecision & b) noexcept
460 {
461  a.sup=b;
462  return a;
463 }
464 inline idotprecision & UncheckedSetInf (idotprecision & a, const real & b) noexcept
465 {
466  a.inf=b;
467  return a;
468 }
469 inline idotprecision & UncheckedSetSup (idotprecision & a, const real & b) noexcept
470 {
471  a.sup=b;
472  return a;
473 }
474 
475 inline bool operator !(const idotprecision &a) noexcept { return (a.inf <= dotprecision(0.0) && a.sup >= dotprecision(0.0)); }
476 
477 inline bool IsEmpty(const idotprecision &a) noexcept { return (a.inf>a.sup); }
478 
479 inline idotprecision abs(const idotprecision &a) noexcept
480 {
481  dotprecision h1 = abs(a.inf);
482  dotprecision h2 = abs(a.sup);
483 
484  if (IsEmpty(a)) return a;
485  if (!a)
486  return idotprecision(dotprecision(0.0), (h1 > h2) ? h1 : h2);
487  if (h1 > h2)
488  return idotprecision(h2, h1);
489 
490  return idotprecision(h1, h2);
491 }
492 
493 inline void accumulate (idotprecision & a, const interval & b, const real & c) noexcept { accumulate(a,b,_interval(c)); }
494 inline void accumulate (idotprecision & a, const real & b, const interval & c) noexcept { accumulate(a,_interval(b),c); }
495 inline void accumulate (idotprecision & a, const real & b, const real & c) noexcept { accumulate(a,_interval(b),_interval(c)); }
496 
497 } // namespace cxsc
498 
cxsc::interval
The Scalar Type interval.
Definition: interval.hpp:55
cxsc::abs
ivector abs(const cimatrix_subv &mv) noexcept
Returns the absolute value of the matrix.
Definition: cimatrix.inl:737
cxsc::_idotprecision
idotprecision _idotprecision(const real &a)
Definition: idot.inl:51
cxsc::_unchecked_idotprecision
idotprecision _unchecked_idotprecision(const real &a, const real &b)
Definition: idot.inl:69
cxsc::idotprecision
The Data Type idotprecision.
Definition: idot.hpp:48
cxsc::dotprecision
The Data Type dotprecision.
Definition: dot.hpp:112
cxsc::dotprecision::set_k
void set_k(unsigned int i)
Set precision for computation of dot products.
Definition: dot.hpp:131
cxsc
The namespace cxsc, providing all functionality of the class library C-XSC.
Definition: cdot.cpp:29
cxsc::operator+=
cdotprecision & operator+=(cdotprecision &cd, const l_complex &lc) noexcept
Implementation of standard algebraic addition and allocation operation.
Definition: cdot.inl:251
cxsc::idotprecision::idotprecision
idotprecision()
Constructor of class idotprecision.
Definition: idot.hpp:57
cxsc::real
The Scalar Type real.
Definition: real.hpp:114