C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
dot.hpp
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: dot.hpp,v 1.35 2014/01/30 17:23:44 cxsc Exp $ */
25 
26 #ifndef _CXSC_DOT_HPP_INCLUDED
27 #define _CXSC_DOT_HPP_INCLUDED
28 
29 #include <iostream>
30 #include <string>
31 
32 #include "compiler.h"
33 #include "RtsTyp.h"
34 
35 namespace cxsc {
36 
37 
38 // ---- RTS - Definitionen ----
39 
40 
41  // Form des dotprec. Akkus:
42  // Pointer auf a_btyp
43  // ist Pointer auf long
44 typedef d_otpr Dotprecision;
45 
46 // ----------------------------
47 } // namespace cxsc
48 
49 #include "real.hpp"
50 #include "ioflags.hpp"
51 
52 namespace cxsc {
53 
54 class dotprecision;
55 class idotprecision;
56 
57 template<typename S, typename T>
58 static inline void addDot( dotprecision&, const S&, const T&);
59 template<typename S, typename T>
60 static inline void addDot( cdotprecision&, const S&, const T&);
61 template<typename S, typename T>
62 static inline void addDot( cidotprecision&, const S&, const T&);
63 template<typename S, typename T>
64 static inline void addDot_op( dotprecision&, const S&, const T&);
65 template<typename S, typename T>
66 static inline void addDot_op( cdotprecision&, const S&, const T&);
67 template<typename S>
68 static inline void addSum( dotprecision&, const S&);
69 
70 
71 //----------------------------------------------------------------------
72 // global verfgbare Dotprecision Variablen
73 //
74 // dotakku[0..3] stehen fuer Matrix, Langzahl u.a. Pakete zur
75 // Verfuegung
76 // dotakku[4] wird in den skalaren Paketen intern verwendet
77 
78 //#define MAXDOTAKKU 5
79 //extern dotprecision dotakku[MAXDOTAKKU];
80 
81 //Global precision for operators
82 #ifdef CXSC_USE_TLS_PREC
83 
84 #ifdef _WIN32
85 extern __declspec(thread) unsigned int opdotprec;
86 #else
87 extern __thread unsigned int opdotprec;
88 #endif
89 
90 #else
91 
92 extern unsigned int opdotprec;
93 
94 #endif
95 
96 
97 
99 
112 {
113  private:
114  // ---- Dataelements -----------------------------------------
115  Dotprecision akku;
117  real err;
119  int k;
120 
121  public:
122  // ---- Constructors -----------------------------------------
124  dotprecision(void) throw();
126  dotprecision(const dotprecision &) throw();
127 
129  inline int get_k() const { return k; }
131  inline void set_k(unsigned int i) { k=i; }
133  inline int get_dotprec() const { return k; }
135  inline void set_dotprec(unsigned int i) { k=i; }
137  inline real get_err() const { return err; }
139  inline void set_err(real e) { err = e; }
140 
142  dotprecision & operator =(const dotprecision &) throw();
144  dotprecision & operator =(const real &) throw();
146  dotprecision & operator =(const l_real &) throw(); // in l_real.cpp
147 
148  // ---- Typecasts -----------------------------------------
150  explicit dotprecision(const real &) throw();
152  explicit dotprecision(const l_real &) throw();
154 
159  friend inline dotprecision _dotprecision(const real &d) throw();
160 
161  // ---- Destruktor -----------------------------------------
162  ~dotprecision(void) ;
163 
164  // ---- Input/Output -----------------------------------------
166  friend std::string & operator <<(std::string &,const dotprecision &) throw();
168  friend std::string & operator >>(std::string &,dotprecision &) throw();
170  friend void operator >>(const std::string &,dotprecision &) throw();
172  friend void operator >>(const char *,dotprecision &) throw();
174  friend std::ostream & operator <<(std::ostream &,const dotprecision &) throw();
176  friend std::istream & operator >>(std::istream &,dotprecision &) throw();
177 
178  // ---- Std.Operators -----------------------------------------
180  friend dotprecision operator -(const dotprecision &) throw();
182  friend dotprecision operator +(const dotprecision &) throw();
183 
185  friend dotprecision operator +(const dotprecision &,const dotprecision &) throw();
187  friend dotprecision operator -(const dotprecision &,const dotprecision &) throw();
189  friend inline idotprecision operator |(const dotprecision &,const dotprecision &) throw();
190 
192  friend dotprecision operator +(const dotprecision &,const real &) throw();
194  friend dotprecision operator +(const real &,const dotprecision &) throw();
196  friend dotprecision operator -(const dotprecision &,const real &) throw();
198  friend dotprecision operator -(const real &,const dotprecision &) throw();
200  friend inline idotprecision operator |(const real &,const dotprecision &) throw();
202  friend inline idotprecision operator |(const dotprecision &,const real &) throw();
203 
205  friend dotprecision & operator +=(dotprecision &,const dotprecision &) throw();
207  friend dotprecision & operator -=(dotprecision &,const dotprecision &) throw();
208 
210  friend dotprecision & operator +=(dotprecision &,const real &) throw();
212  friend dotprecision & operator -=(dotprecision &,const real &) throw();
213 
214  // ---- Comp.Operat. ------------------------------------------
216  friend bool operator !(const dotprecision &) throw();
217 // operator void *() const throw() { if(sign(*this)) return (void *)1; else return 0;}
218 
220  friend bool operator ==(const dotprecision &,const dotprecision &) throw();
222  friend bool operator !=(const dotprecision &,const dotprecision &) throw();
224  friend bool operator <(const dotprecision &,const dotprecision &) throw();
226  friend bool operator >(const dotprecision &,const dotprecision &) throw();
228  friend bool operator <=(const dotprecision &,const dotprecision &) throw();
230  friend bool operator >=(const dotprecision &,const dotprecision &) throw();
231 
233  friend bool operator ==(const real &,const dotprecision &) throw();
235  friend bool operator !=(const real &,const dotprecision &) throw();
237  friend bool operator <(const real &,const dotprecision &) throw();
239  friend bool operator >(const real &,const dotprecision &) throw();
241  friend bool operator <=(const real &,const dotprecision &) throw();
243  friend bool operator >=(const real &,const dotprecision &) throw();
244 
246  friend bool operator ==(const dotprecision &,const real &) throw();
248  friend bool operator !=(const dotprecision &,const real &) throw();
250  friend bool operator <(const dotprecision &,const real &) throw();
252  friend bool operator >(const dotprecision &,const real &) throw();
254  friend bool operator <=(const dotprecision &,const real &) throw();
256  friend bool operator >=(const dotprecision &,const real &) throw();
257 
258  // ---- Others ------------------------------------------------
260  friend void rnd (const dotprecision&, real&, rndtype) throw();
262  friend void rnd (const dotprecision&, real&, real&) throw();
264  friend void rnd (const dotprecision&, interval&) throw(); // Blomquist
266  friend real rnd (const dotprecision&, rndtype) throw();
267 
269  friend dotprecision abs(const dotprecision &) throw();
271  friend int sign(const dotprecision &) throw();
273  friend dotprecision & accumulate (dotprecision&, const real&, const real&) throw();
274 
276  friend dotprecision & accumulate_approx (dotprecision&, const real&, const real&) throw();
277 
278  template<typename S, typename T>
279  friend INLINE void addDot( dotprecision&, const S&, const T&);
280  template<typename S, typename T>
281  friend INLINE void addDot( cdotprecision&, const S&, const T&);
282  template<typename S, typename T>
283  friend INLINE void addDot( cidotprecision&, const S&, const T&);
284 
285  template<typename S, typename T>
286  friend INLINE void addDot_op( dotprecision&, const S&, const T&);
287  template<typename S, typename T>
288  friend INLINE void addDot_op( cdotprecision&, const S&, const T&);
289 
290  template<typename S>
291  friend INLINE void addSum( dotprecision&, const S&);
292 
293 
294  // ---- internal functions ------------------------------------
295  inline Dotprecision* ptr() { return &akku; }
296 
297 
298  private:
299  dotprecision & negdot(void) throw(); // Negates current dotprecision
300 };
301 
302 
303 
304  inline dotprecision _dotprecision(const real &d) throw() { return dotprecision(d); }
305  std::string & operator <<(std::string &,const dotprecision &) throw();
306  std::string & operator >>(std::string &,dotprecision &) throw();
307  void operator >>(const std::string &,dotprecision &) throw();
308  void operator >>(const char *,dotprecision &) throw();
309  std::ostream & operator <<(std::ostream &,const dotprecision &) throw();
310  std::istream & operator >>(std::istream &,dotprecision &) throw();
311  dotprecision operator -(const dotprecision &) throw();
312  dotprecision operator +(const dotprecision &) throw();
313  dotprecision operator +(const dotprecision &,const dotprecision &) throw();
314  dotprecision operator -(const dotprecision &,const dotprecision &) throw();
315  inline idotprecision operator |(const dotprecision &,const dotprecision &) throw();
316  dotprecision operator +(const dotprecision &,const real &) throw();
317  dotprecision operator +(const real &,const dotprecision &) throw();
318  dotprecision operator -(const dotprecision &,const real &) throw();
319  dotprecision operator -(const real &,const dotprecision &) throw();
320  inline idotprecision operator |(const real &,const dotprecision &) throw();
321  inline idotprecision operator |(const dotprecision &,const real &) throw();
322  dotprecision & operator +=(dotprecision &,const dotprecision &) throw();
323  dotprecision & operator -=(dotprecision &,const dotprecision &) throw();
324  dotprecision & operator +=(dotprecision &,const real &) throw();
325  dotprecision & operator -=(dotprecision &,const real &) throw();
326  bool operator !(const dotprecision &) throw();
327  bool operator ==(const dotprecision &,const dotprecision &) throw();
328  bool operator !=(const dotprecision &,const dotprecision &) throw();
329  bool operator <(const dotprecision &,const dotprecision &) throw();
330  bool operator >(const dotprecision &,const dotprecision &) throw();
331  bool operator <=(const dotprecision &,const dotprecision &) throw();
332  bool operator >=(const dotprecision &,const dotprecision &) throw();
333  bool operator ==(const real &,const dotprecision &) throw();
334  bool operator !=(const real &,const dotprecision &) throw();
335  bool operator <(const real &,const dotprecision &) throw();
336  bool operator >(const real &,const dotprecision &) throw();
337  bool operator <=(const real &,const dotprecision &) throw();
338  bool operator >=(const real &,const dotprecision &) throw();
339  bool operator ==(const dotprecision &,const real &) throw();
340  bool operator !=(const dotprecision &,const real &) throw();
341  bool operator <(const dotprecision &,const real &) throw();
342  bool operator >(const dotprecision &,const real &) throw();
343  bool operator <=(const dotprecision &,const real &) throw();
344  bool operator >=(const dotprecision &,const real &) throw();
345  void rnd (const dotprecision&, real&, rndtype = RND_NEXT) throw();
346  void rnd (const dotprecision&, real&, real&) throw();
347  void rnd (const dotprecision&, interval&) throw();
348  real rnd (const dotprecision&, rndtype = RND_NEXT) throw();
349  dotprecision abs(const dotprecision &) throw();
350  int sign(const dotprecision &) throw();
351  dotprecision & accumulate (dotprecision&, const real&, const real&) throw();
352 
353 
354 } // namespace cxsc
355 
356 
357 #endif // _CXSC_DOT_HPP_INCLUDED
cxsc::dotprecision::operator=
dotprecision & operator=(const dotprecision &)
Implementation of standard assigning operator.
Definition: dot.cpp:84
cxsc::dotprecision::_dotprecision
friend dotprecision _dotprecision(const real &d)
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
Definition: dot.hpp:304
cxsc::dotprecision::abs
friend dotprecision abs(const dotprecision &)
The absolute value of a dotprecision value.
Definition: dot.cpp:510
cxsc::dotprecision::operator+=
friend dotprecision & operator+=(dotprecision &, const dotprecision &)
Implementation of standard algebraic addition and allocation operation.
Definition: dot.cpp:164
cxsc::interval
The Scalar Type interval.
Definition: interval.hpp:54
cxsc::dotprecision::set_dotprec
void set_dotprec(unsigned int i)
Set precision for computation of dot products.
Definition: dot.hpp:135
cxsc::dotprecision::operator|
friend idotprecision operator|(const dotprecision &, const dotprecision &)
Returns the convex hull of the arguments.
Definition: idot.inl:133
cxsc::idotprecision
The Data Type idotprecision.
Definition: idot.hpp:47
cxsc::dotprecision::rnd
friend void rnd(const dotprecision &, real &, rndtype)
Converting the exact dotprecision value with one rounding into a real value.
Definition: dot.cpp:355
cxsc::abs
ivector abs(const cimatrix_subv &mv)
Returns the absolute value of the matrix.
Definition: cimatrix.inl:737
cxsc::dotprecision::operator==
friend bool operator==(const dotprecision &, const dotprecision &)
Implementation of standard equality operation.
Definition: dot.cpp:201
cxsc::dotprecision::operator>=
friend bool operator>=(const dotprecision &, const dotprecision &)
Implementation of standard greater-or-equal-than operation.
Definition: dot.cpp:336
cxsc::dotprecision
The Data Type dotprecision.
Definition: dot.hpp:111
cxsc::dotprecision::operator<=
friend bool operator<=(const dotprecision &, const dotprecision &)
Implementation of standard less-or-equal-than operation.
Definition: dot.cpp:241
cxsc::dotprecision::accumulate
friend dotprecision & accumulate(dotprecision &, const real &, const real &)
The accurate scalar product of the last two arguments added to the value of the first argument.
Definition: dot.cpp:519
cxsc::dotprecision::set_err
void set_err(real e)
Set the current error value, use with caution.
Definition: dot.hpp:139
cxsc::cidotprecision
The Data Type cidotprecision.
Definition: cidot.hpp:57
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::dotprecision::operator-
friend dotprecision operator-(const dotprecision &)
Implementation of standard algebraic negative sign operation.
Definition: dot.cpp:186
cxsc::operator+=
cdotprecision & operator+=(cdotprecision &cd, const l_complex &lc)
Implementation of standard algebraic addition and allocation operation.
Definition: cdot.inl:251
cxsc::l_real
The Multiple-Precision Data Type l_real.
Definition: l_real.hpp:77
cxsc::dotprecision::operator>>
friend std::string & operator>>(std::string &, dotprecision &)
Implementation of standard input method.
Definition: dotio.cpp:121
cxsc::dotprecision::get_k
int get_k() const
Get currently set precision for computation of dot products.
Definition: dot.hpp:129
cxsc::cdotprecision
The Data Type cdotprecision.
Definition: cdot.hpp:60
cxsc::dotprecision::accumulate_approx
friend dotprecision & accumulate_approx(dotprecision &, const real &, const real &)
The accurate scalar product of the last two arguments added to the value of the first argument (no er...
cxsc::dotprecision::operator<
friend bool operator<(const dotprecision &, const dotprecision &)
Implementation of standard less-than operation.
Definition: dot.cpp:334
cxsc::dotprecision::dotprecision
dotprecision(void)
Constructor of class dotprecision.
Definition: dot.cpp:62
cxsc::dotprecision::get_err
real get_err() const
Get the current error value (if dot products not computed in maximum precision)
Definition: dot.hpp:137
cxsc::dotprecision::operator!
friend bool operator!(const dotprecision &)
Implementation of standard negation operation.
Definition: dot.cpp:352
cxsc::dotprecision::operator+
friend dotprecision operator+(const dotprecision &)
Implementation of standard algebraic positive sign operation.
Definition: dot.cpp:193
cxsc::dotprecision::get_dotprec
int get_dotprec() const
Get currently set precision for computation of dot products.
Definition: dot.hpp:133
cxsc::dotprecision::sign
friend int sign(const dotprecision &)
The sign of a dotprecision value.
Definition: dot.cpp:503
cxsc::dotprecision::operator>
friend bool operator>(const dotprecision &, const dotprecision &)
Implementation of standard greater-than operation.
Definition: dot.cpp:335
cxsc::_dotprecision
dotprecision _dotprecision(const real &d)
Definition: dot.hpp:304
cxsc::dotprecision::operator<<
friend std::string & operator<<(std::string &, const dotprecision &)
Implementation of standard output method.
Definition: dotio.cpp:55
cxsc::real
The Scalar Type real.
Definition: real.hpp:113
cxsc::dotprecision::operator-=
friend dotprecision & operator-=(dotprecision &, const dotprecision &)
Implementation of standard algebraic subtraction and allocation operation.
Definition: dot.cpp:177
cxsc::dotprecision::operator!=
friend bool operator!=(const dotprecision &, const dotprecision &)
Implementation of standard negated equality operation.
Definition: dot.cpp:333