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
35namespace cxsc {
36
37
38// ---- RTS - Definitionen ----
39
40
41 // Form des dotprec. Akkus:
42 // Pointer auf a_btyp
43 // ist Pointer auf long
44typedef d_otpr Dotprecision;
45
46// ----------------------------
47} // namespace cxsc
48
49#include "real.hpp"
50#include "ioflags.hpp"
51
52namespace cxsc {
53
54class dotprecision;
55class idotprecision;
56
57template<typename S, typename T>
58static inline void addDot( dotprecision&, const S&, const T&);
59template<typename S, typename T>
60static inline void addDot( cdotprecision&, const S&, const T&);
61template<typename S, typename T>
62static inline void addDot( cidotprecision&, const S&, const T&);
63template<typename S, typename T>
64static inline void addDot_op( dotprecision&, const S&, const T&);
65template<typename S, typename T>
66static inline void addDot_op( cdotprecision&, const S&, const T&);
67template<typename S>
68static 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
85extern __declspec(thread) unsigned int opdotprec;
86#else
87extern __thread unsigned int opdotprec;
88#endif
89
90#else
91
92extern 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) noexcept;
126 dotprecision(const dotprecision &) noexcept;
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 &) noexcept;
144 dotprecision & operator =(const real &) noexcept;
146 dotprecision & operator =(const l_real &) noexcept; // in l_real.cpp
147
148 // ---- Typecasts -----------------------------------------
150 explicit dotprecision(const real &) noexcept;
152 explicit dotprecision(const l_real &) noexcept;
154
159 friend inline dotprecision _dotprecision(const real &d) noexcept;
160
161 // ---- Destruktor -----------------------------------------
162 ~dotprecision(void) ;
163
164 // ---- Input/Output -----------------------------------------
166 friend std::string & operator <<(std::string &,const dotprecision &) noexcept;
168 friend std::string & operator >>(std::string &,dotprecision &) noexcept;
170 friend void operator >>(const std::string &,dotprecision &) noexcept;
172 friend void operator >>(const char *,dotprecision &) noexcept;
174 friend std::ostream & operator <<(std::ostream &,const dotprecision &) noexcept;
176 friend std::istream & operator >>(std::istream &,dotprecision &) noexcept;
177
178 // ---- Std.Operators -----------------------------------------
180 friend dotprecision operator -(const dotprecision &) noexcept;
182 friend dotprecision operator +(const dotprecision &) noexcept;
183
185 friend dotprecision operator +(const dotprecision &,const dotprecision &) noexcept;
187 friend dotprecision operator -(const dotprecision &,const dotprecision &) noexcept;
189 friend inline idotprecision operator |(const dotprecision &,const dotprecision &) noexcept;
190
192 friend dotprecision operator +(const dotprecision &,const real &) noexcept;
194 friend dotprecision operator +(const real &,const dotprecision &) noexcept;
196 friend dotprecision operator -(const dotprecision &,const real &) noexcept;
198 friend dotprecision operator -(const real &,const dotprecision &) noexcept;
200 friend inline idotprecision operator |(const real &,const dotprecision &) noexcept;
202 friend inline idotprecision operator |(const dotprecision &,const real &) noexcept;
203
205 friend dotprecision & operator +=(dotprecision &,const dotprecision &) noexcept;
207 friend dotprecision & operator -=(dotprecision &,const dotprecision &) noexcept;
208
210 friend dotprecision & operator +=(dotprecision &,const real &) noexcept;
212 friend dotprecision & operator -=(dotprecision &,const real &) noexcept;
213
214 // ---- Comp.Operat. ------------------------------------------
216 friend bool operator !(const dotprecision &) noexcept;
217// operator void *() const noexcept { if(sign(*this)) return (void *)1; else return 0;}
218
220 friend bool operator ==(const dotprecision &,const dotprecision &) noexcept;
222 friend bool operator !=(const dotprecision &,const dotprecision &) noexcept;
224 friend bool operator <(const dotprecision &,const dotprecision &) noexcept;
226 friend bool operator >(const dotprecision &,const dotprecision &) noexcept;
228 friend bool operator <=(const dotprecision &,const dotprecision &) noexcept;
230 friend bool operator >=(const dotprecision &,const dotprecision &) noexcept;
231
233 friend bool operator ==(const real &,const dotprecision &) noexcept;
235 friend bool operator !=(const real &,const dotprecision &) noexcept;
237 friend bool operator <(const real &,const dotprecision &) noexcept;
239 friend bool operator >(const real &,const dotprecision &) noexcept;
241 friend bool operator <=(const real &,const dotprecision &) noexcept;
243 friend bool operator >=(const real &,const dotprecision &) noexcept;
244
246 friend bool operator ==(const dotprecision &,const real &) noexcept;
248 friend bool operator !=(const dotprecision &,const real &) noexcept;
250 friend bool operator <(const dotprecision &,const real &) noexcept;
252 friend bool operator >(const dotprecision &,const real &) noexcept;
254 friend bool operator <=(const dotprecision &,const real &) noexcept;
256 friend bool operator >=(const dotprecision &,const real &) noexcept;
257
258 // ---- Others ------------------------------------------------
260 friend void rnd (const dotprecision&, real&, rndtype) noexcept;
262 friend void rnd (const dotprecision&, real&, real&) noexcept;
264 friend void rnd (const dotprecision&, interval&) noexcept; // Blomquist
266 friend real rnd (const dotprecision&, rndtype) noexcept;
267
269 friend dotprecision abs(const dotprecision &) noexcept;
271 friend int sign(const dotprecision &) noexcept;
273 friend dotprecision & accumulate (dotprecision&, const real&, const real&) noexcept;
274
276 friend dotprecision & accumulate_approx (dotprecision&, const real&, const real&) noexcept;
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) noexcept; // Negates current dotprecision
300};
301
302
303
304 inline dotprecision _dotprecision(const real &d) noexcept { return dotprecision(d); }
305 std::string & operator <<(std::string &,const dotprecision &) noexcept;
306 std::string & operator >>(std::string &,dotprecision &) noexcept;
307 void operator >>(const std::string &,dotprecision &) noexcept;
308 void operator >>(const char *,dotprecision &) noexcept;
309 std::ostream & operator <<(std::ostream &,const dotprecision &) noexcept;
310 std::istream & operator >>(std::istream &,dotprecision &) noexcept;
311 dotprecision operator -(const dotprecision &) noexcept;
312 dotprecision operator +(const dotprecision &) noexcept;
313 dotprecision operator +(const dotprecision &,const dotprecision &) noexcept;
314 dotprecision operator -(const dotprecision &,const dotprecision &) noexcept;
315 inline idotprecision operator |(const dotprecision &,const dotprecision &) noexcept;
316 dotprecision operator +(const dotprecision &,const real &) noexcept;
317 dotprecision operator +(const real &,const dotprecision &) noexcept;
318 dotprecision operator -(const dotprecision &,const real &) noexcept;
319 dotprecision operator -(const real &,const dotprecision &) noexcept;
320 inline idotprecision operator |(const real &,const dotprecision &) noexcept;
321 inline idotprecision operator |(const dotprecision &,const real &) noexcept;
323 dotprecision & operator -=(dotprecision &,const dotprecision &) noexcept;
324 dotprecision & operator +=(dotprecision &,const real &) noexcept;
325 dotprecision & operator -=(dotprecision &,const real &) noexcept;
326 bool operator !(const dotprecision &) noexcept;
327 bool operator ==(const dotprecision &,const dotprecision &) noexcept;
328 bool operator !=(const dotprecision &,const dotprecision &) noexcept;
329 bool operator <(const dotprecision &,const dotprecision &) noexcept;
330 bool operator >(const dotprecision &,const dotprecision &) noexcept;
331 bool operator <=(const dotprecision &,const dotprecision &) noexcept;
332 bool operator >=(const dotprecision &,const dotprecision &) noexcept;
333 bool operator ==(const real &,const dotprecision &) noexcept;
334 bool operator !=(const real &,const dotprecision &) noexcept;
335 bool operator <(const real &,const dotprecision &) noexcept;
336 bool operator >(const real &,const dotprecision &) noexcept;
337 bool operator <=(const real &,const dotprecision &) noexcept;
338 bool operator >=(const real &,const dotprecision &) noexcept;
339 bool operator ==(const dotprecision &,const real &) noexcept;
340 bool operator !=(const dotprecision &,const real &) noexcept;
341 bool operator <(const dotprecision &,const real &) noexcept;
342 bool operator >(const dotprecision &,const real &) noexcept;
343 bool operator <=(const dotprecision &,const real &) noexcept;
344 bool operator >=(const dotprecision &,const real &) noexcept;
345 void rnd (const dotprecision&, real&, rndtype = RND_NEXT) noexcept;
346 void rnd (const dotprecision&, real&, real&) noexcept;
347 void rnd (const dotprecision&, interval&) noexcept;
348 real rnd (const dotprecision&, rndtype = RND_NEXT) noexcept;
349 dotprecision abs(const dotprecision &) noexcept;
350 int sign(const dotprecision &) noexcept;
351 dotprecision & accumulate (dotprecision&, const real&, const real&) noexcept;
352
353
354} // namespace cxsc
355
356
357#endif // _CXSC_DOT_HPP_INCLUDED
The Data Type cdotprecision.
Definition cdot.hpp:61
The Data Type cidotprecision.
Definition cidot.hpp:58
The Data Type dotprecision.
Definition dot.hpp:112
friend dotprecision operator+(const dotprecision &) noexcept
Implementation of standard algebraic positive sign operation.
Definition dot.cpp:193
friend bool operator>=(const dotprecision &, const dotprecision &) noexcept
Implementation of standard greater-or-equal-than operation.
Definition dot.cpp:336
friend dotprecision _dotprecision(const real &d) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
Definition dot.hpp:304
friend int sign(const dotprecision &) noexcept
The sign of a dotprecision value.
Definition dot.cpp:503
friend bool operator>(const dotprecision &, const dotprecision &) noexcept
Implementation of standard greater-than operation.
Definition dot.cpp:335
friend dotprecision & accumulate(dotprecision &, const real &, const real &) noexcept
The accurate scalar product of the last two arguments added to the value of the first argument.
Definition dot.cpp:519
friend dotprecision & accumulate_approx(dotprecision &, const real &, const real &) noexcept
The accurate scalar product of the last two arguments added to the value of the first argument (no er...
void set_err(real e)
Set the current error value, use with caution.
Definition dot.hpp:139
friend bool operator<=(const dotprecision &, const dotprecision &) noexcept
Implementation of standard less-or-equal-than operation.
Definition dot.cpp:241
friend dotprecision & operator-=(dotprecision &, const dotprecision &) noexcept
Implementation of standard algebraic subtraction and allocation operation.
Definition dot.cpp:177
friend bool operator!(const dotprecision &) noexcept
Implementation of standard negation operation.
Definition dot.cpp:352
friend std::string & operator<<(std::string &, const dotprecision &) noexcept
Implementation of standard output method.
Definition dotio.cpp:55
friend dotprecision abs(const dotprecision &) noexcept
The absolute value of a dotprecision value.
Definition dot.cpp:510
friend bool operator==(const dotprecision &, const dotprecision &) noexcept
Implementation of standard equality operation.
Definition dot.cpp:201
friend bool operator<(const dotprecision &, const dotprecision &) noexcept
Implementation of standard less-than operation.
Definition dot.cpp:334
dotprecision(void) noexcept
Constructor of class dotprecision.
Definition dot.cpp:62
friend dotprecision operator-(const dotprecision &) noexcept
Implementation of standard algebraic negative sign operation.
Definition dot.cpp:186
friend bool operator!=(const dotprecision &, const dotprecision &) noexcept
Implementation of standard negated equality operation.
Definition dot.cpp:333
int get_k() const
Get currently set precision for computation of dot products.
Definition dot.hpp:129
void set_dotprec(unsigned int i)
Set precision for computation of dot products.
Definition dot.hpp:135
friend dotprecision & operator+=(dotprecision &, const dotprecision &) noexcept
Implementation of standard algebraic addition and allocation operation.
Definition dot.cpp:164
friend void rnd(const dotprecision &, real &, rndtype) noexcept
Converting the exact dotprecision value with one rounding into a real value.
Definition dot.cpp:355
dotprecision & operator=(const dotprecision &) noexcept
Implementation of standard assigning operator.
Definition dot.cpp:84
friend std::string & operator>>(std::string &, dotprecision &) noexcept
Implementation of standard input method.
Definition dotio.cpp:121
int get_dotprec() const
Get currently set precision for computation of dot products.
Definition dot.hpp:133
void set_k(unsigned int i)
Set precision for computation of dot products.
Definition dot.hpp:131
real get_err() const
Get the current error value (if dot products not computed in maximum precision)
Definition dot.hpp:137
friend idotprecision operator|(const dotprecision &, const dotprecision &) noexcept
Returns the convex hull of the arguments.
Definition idot.inl:133
The Data Type idotprecision.
Definition idot.hpp:48
The Scalar Type interval.
Definition interval.hpp:55
The Multiple-Precision Data Type l_real.
Definition l_real.hpp:78
The Scalar Type real.
Definition real.hpp:114
The namespace cxsc, providing all functionality of the class library C-XSC.
Definition cdot.cpp:29
cdotprecision & operator+=(cdotprecision &cd, const l_complex &lc) noexcept
Implementation of standard algebraic addition and allocation operation.
Definition cdot.inl:251
ivector abs(const cimatrix_subv &mv) noexcept
Returns the absolute value of the matrix.
Definition cimatrix.inl:737
dotprecision _dotprecision(const real &d) noexcept
Definition dot.hpp:304