C-XSC - A C++ Class Library for Extended Scientific Computing 2.5.4
real.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: real.hpp,v 1.42 2014/01/30 17:23:48 cxsc Exp $ */
25
26#ifndef _CXSC_REAL_HPP_INCLUDED
27#define _CXSC_REAL_HPP_INCLUDED
28
29#include <iostream>
30#include <string>
31
32// namespace cxsc {
33
34#include "compiler.h"
35#include "RtsTyp.h"
36#include "ioflags.hpp"
37
38#include "except.hpp"
40
44namespace cxsc {
45
46class rvector;
47class rmatrix;
48class rvector_slice;
49class rmatrix_slice;
50
51#define addu addup
52#define addd adddown
53#define subu subup
54#define subd subdown
55#define mulu multup
56#define muld multdown
57#define divu divup
58#define divd divdown
59
60// ---------------------------------------------------------------------------
61// ---- ----
62// ---- class real (declaration) ----
63// ---- ----
64// ---------------------------------------------------------------------------
65
67
113class real
114{
115 private:
116 // ---- private data ----------------------------------------
117 double w;
118
119 public:
120 // ---- implicit constructors -------------------------------
122 real(void) noexcept { }
124 real(const float &a) noexcept : w(a) { }
126 real(const double &a) noexcept : w(a) { }
128 real(const int a) noexcept : w(a) { }
130 real(const long a) noexcept : w(a) { }
131
132 // ---- explicit constructors -------------------------------
134 explicit real(const l_real &) noexcept;
135
136 // The following are defined in the specific vector, matrix-files
137#if(CXSC_INDEX_CHECK)
139 explicit INLINE real(const rvector &) ;
141 explicit INLINE real(const rvector_slice &);
143 explicit INLINE real(const rmatrix &) ;
145 explicit INLINE real(const rmatrix_slice &);
146#else
148 explicit INLINE real(const rvector &) noexcept;
150 explicit INLINE real(const rvector_slice &) noexcept;
152 explicit INLINE real(const rmatrix &) noexcept;
154 explicit INLINE real(const rmatrix_slice &) noexcept;
155#endif
156
157
158 // ---- assignments -----------------------------------------
159
160 // ---- compatibility typecasts -----------------------------
161
163 friend inline double _double(const real &a) noexcept;
165 friend inline real _real(const double &a) noexcept;
166
167#if(CXSC_INDEX_CHECK)
169
174 friend INLINE real _real(const rvector &) ;
176
181 friend INLINE real _real(const rvector_slice &);
183
188 friend INLINE real _real(const rmatrix &) ;
190
195 friend INLINE real _real(const rmatrix_slice &);
196#else
198
203 friend INLINE real _real(const rvector &) noexcept;
205
210 friend INLINE real _real(const rvector_slice &) noexcept;
212
217 friend INLINE real _real(const rmatrix &) noexcept;
219
224 friend INLINE real _real(const rmatrix_slice &) noexcept;
225#endif
226
227 // ---- Input/Output ---------------------------------------
228
230 friend std::ostream & operator <<(std::ostream &,const real &) noexcept;
232 friend std::istream & operator >>(std::istream &,real &) noexcept;
234 friend std::string & operator <<(std::string &,const real &) noexcept;
236 friend std::string & operator >>(std::string &,real &) noexcept;
238 friend void operator >>(const char *,real &) noexcept;
240 friend void operator >>(const std::string &,real &) noexcept;
241
242 // ---- Std.Operators ---------------------------------------
243 // As the real-arithmetic should be as fast as double all
244 // operators are inlined.
245
247 friend inline real operator -(const real &) noexcept;
249 friend inline real operator +(const real &) noexcept;
250
252 friend inline real operator +(const real &,const real &) noexcept;
254 friend inline real operator -(const real &,const real &) noexcept;
256 friend inline real operator *(const real &,const real &) noexcept;
258 friend inline real operator /(const real &,const real &) noexcept;
259
261 friend inline real& operator +=(real &, const real &) noexcept;
263 friend inline real& operator -=(real &, const real &) noexcept;
265 friend inline real& operator *=(real &, const real &) noexcept;
267 friend inline real& operator /=(real &, const real &) noexcept;
268
269 // ---- Comp.Operat. ---------------------------------------
270
272 friend inline bool operator! (const real& a) noexcept;
274 friend inline bool operator== (const real& a, const real& b) noexcept;
276 friend inline bool operator!= (const real& a, const real& b) noexcept;
278 friend inline bool operator< (const real& a, const real& b) noexcept;
280 friend inline bool operator<= (const real& a, const real& b) noexcept;
282 friend inline bool operator>= (const real& a, const real& b) noexcept;
284 friend inline bool operator> (const real& a, const real& b) noexcept;
285
287 friend inline bool operator== (const real& a, const int & b) noexcept;
289 friend inline bool operator!= (const real& a, const int & b) noexcept;
291 friend inline bool operator== (const int & a, const real& b) noexcept;
293 friend inline bool operator!= (const int & a, const real& b) noexcept;
295 friend inline bool operator== (const real& a, const long & b) noexcept;
297 friend inline bool operator!= (const real& a, const long & b) noexcept;
299 friend inline bool operator== (const long & a, const real& b) noexcept;
301 friend inline bool operator!= (const long & a, const real& b) noexcept;
303 friend inline bool operator== (const real& a, const float & b) noexcept;
305 friend inline bool operator!= (const real& a, const float & b) noexcept;
307 friend inline bool operator== (const float & a, const real& b) noexcept;
309 friend inline bool operator!= (const float & a, const real& b) noexcept;
311 friend inline bool operator== (const real& a, const double & b) noexcept;
313 friend inline bool operator!= (const real& a, const double & b) noexcept;
315 friend inline bool operator== (const double & a, const real& b) noexcept;
317 friend inline bool operator!= (const double & a, const real& b) noexcept;
318
319 // ---- Rounding Operators ---------------------------------
320
322 friend inline real addup(const real &, const real &);
324 friend inline real adddown(const real &, const real &);
326 friend inline real subup(const real &, const real &);
328 friend inline real subdown(const real &, const real &);
330 friend inline real multup(const real &, const real &);
332 friend inline real multdown(const real &, const real &);
334 friend inline real divup(const real &, const real &);
336 friend inline real divdown(const real &, const real &);
337
338 // ---- Others -------------------------------------------
339
341 friend inline real abs(const real &a) noexcept;
343 friend inline int sign(const real &) noexcept;
344
346 friend inline real pred(const real &) noexcept;
348 friend inline real succ(const real &) noexcept;
350 friend inline a_intg expo(const real &) noexcept;
352 friend inline real comp(const real &,a_intg) noexcept;
354 friend inline real mant(const real &) noexcept;
355
356 real & operator = (const lx_real&) noexcept; // Blomquist, 12.11.2008;
357 real & operator = (const l_real&) noexcept; // Blomquist, 12.11.2008;
358}; // end of class real
359
360inline real comp(const real &,a_intg) noexcept;
361
362// ---------------------------------------------------------------------------
363// ---- ----
364// ---- friend functions of class real (not inline) ----
365// ---- ----
366// ---------------------------------------------------------------------------
367
368std::ostream & operator <<(std::ostream &,const real &) noexcept;
369std::istream & operator >>(std::istream &,real &) noexcept;
370std::string & operator <<(std::string &,const real &) noexcept;
371std::string & operator >>(std::string &,real &) noexcept;
372void operator >>(const char *,real &) noexcept;
373void operator >>(const std::string &,real &) noexcept;
374
375// ---------------------------------------------------------------------------
376// ---- ----
377// ---- global functions associated with class real ----
378// ---- ----
379// ---------------------------------------------------------------------------
380
382inline real max(const real & a, const real & b);
384inline real min(const real & a, const real & b);
386inline real Max(const real & a, const real & b);
387
388//----------------------------------------------------------------------
389// MakeHexReal - erstellt aus den binaer angegebenen Einzelteilen einer
390// IEEE 64-bit Gleitkommazahl eine solche
391
393const real& MakeHexReal (
394 int sign, unsigned int expo, a_btyp manthigh, a_btyp mantlow);
395
397inline bool IsInfinity(const real &a);
399inline bool IsQuietNaN(const real &a);
401inline bool IsSignalingNaN(const real &a);
402
403//-------------------------------------------------------------------------
404// times2pown - Fast multiplication of reference parameter r with 2^n -----
406inline void times2pown(real& r,const int n); // Blomquist 1.10.02. {real.inl}
407
409inline real pow2n(const int n) noexcept; // returns 2^n;
410
412string realToHex(const real& a);
413
414// ---------------------------------------------------------------------------
415// ---- ----
416// ---- special constants associated with class real ----
417// ---- ----
418// ---------------------------------------------------------------------------
419
420// ---- special constants -----------------------------------------
422extern const real MinReal;
424extern const real minreal;
426extern const real MaxReal;
428extern const real Infinity;
430extern const real SignalingNaN;
432extern const real QuietNaN;
434extern const real Epsilon;
435extern const real Factor;
436
438extern const real Pi_real; // Pi
440extern const real Pi2_real; // 2*Pi
442extern const real Pi3_real; // 3*Pi
444extern const real Pid2_real; // Pi/2
446extern const real Pid3_real; // Pi/3
448extern const real Pid4_real; // Pi/4
450extern const real Pir_real; // 1/Pi
452extern const real Pi2r_real; // 1/(2*Pi)
454extern const real Pip2_real; // Pi^2
456extern const real SqrtPi_real; // sqrt(Pi)
458extern const real Sqrt2Pi_real; // sqrt(2Pi)
460extern const real SqrtPir_real; // 1/sqrt(Pi)
462extern const real Sqrt2Pir_real; // 1/sqrt(2Pi)
464extern const real Sqrt2_real; // sqrt(2)
466extern const real Sqrt5_real; // sqrt(5)
468extern const real Sqrt7_real; // sqrt(7)
470extern const real Sqrt2r_real; // 1/sqrt(2)
472extern const real Sqrt3_real; // sqrt(3)
474extern const real Sqrt3d2_real; // sqrt(3)/2
476extern const real Sqrt3r_real; // 1/sqrt(3)
478extern const real Ln2_real; // ln(2)
480extern const real Ln2r_real; // 1/ln(2)
482extern const real Ln10_real; // ln(10)
484extern const real Ln10r_real; // 1/ln(10)
486extern const real LnPi_real; // ln(Pi)
488extern const real Ln2Pi_real; // ln(2Pi)
490extern const real E_real; // e
492extern const real Er_real; // 1/e
494extern const real Ep2_real; // e^2
496extern const real Ep2r_real; // 1/e^2
498extern const real EpPi_real; // e^(Pi)
500extern const real Ep2Pi_real; // e^(2Pi)
502extern const real EpPid2_real; // e^(Pi/2)
504extern const real EpPid4_real; // e^(Pi/4)
505
506} // namespace cxsc
507
508#include "real.inl"
509#include "rmath.hpp"
510// }
511#endif // _CXSC_REAL_HPP_INCLUDED
512
The Multiple-Precision Data Type l_real.
Definition l_real.hpp:78
The Scalar Type real.
Definition real.hpp:114
friend bool operator!=(const real &a, const real &b) noexcept
Implementation of standard negated equality operation.
friend real & operator+=(real &, const real &) noexcept
Implementation of standard algebraic addition and allocation operation.
friend bool operator>=(const real &a, const real &b) noexcept
Implementation of standard greater-or-equal-than operation.
friend bool operator!(const real &a) noexcept
Implementation of standard negation operation.
friend real pred(const real &) noexcept
The predecessor of a real value.
friend real multup(const real &, const real &)
Multiplication of two real values and rounding the result upwards.
friend a_intg expo(const real &) noexcept
The exponent of a real value.
friend real adddown(const real &, const real &)
Addition of two real values and rounding the result downwards.
friend bool operator>(const real &a, const real &b) noexcept
Implementation of standard greater-than operation.
friend INLINE real _real(const rvector_slice &) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
friend real succ(const real &) noexcept
The successor of a real value.
friend real & operator-=(real &, const real &) noexcept
Implementation of standard algebraic subtraction and allocation operation.
friend real subdown(const real &, const real &)
Subtraction of two real values and rounding the result downwards.
friend real comp(const real &, a_intg) noexcept
Composes an IEEE floating point value out of an given mantissa and exponent.
friend bool operator<=(const real &a, const real &b) noexcept
Implementation of standard less-or-equal-than operation.
friend real mant(const real &) noexcept
The mantissa of a real value.
friend bool operator==(const real &a, const real &b) noexcept
Implementation of standard equality operation.
friend real multdown(const real &, const real &)
Multiplication of two real values and rounding the result downwards.
friend real operator/(const real &, const real &) noexcept
Implementation of standard algebraic division operation.
friend bool operator<(const real &a, const real &b) noexcept
Implementation of standard less-than operation.
friend real & operator*=(real &, const real &) noexcept
Implementation of standard algebraic multiplication and allocation operation.
friend real & operator/=(real &, const real &) noexcept
Implementation of standard algebraic division and allocation operation.
friend double _double(const real &a) noexcept
Typecast to convert a real value into a double value.
friend real addup(const real &, const real &)
Addition of two real values and rounding the result upwards.
friend INLINE real _real(const rmatrix &) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
friend std::istream & operator>>(std::istream &, real &) noexcept
Implementation of standard input method.
Definition realio.cpp:263
friend real divup(const real &, const real &)
Division of two real values and rounding the result upwards.
friend real operator+(const real &) noexcept
Implementation of standard algebraic positive sign operation.
friend real operator-(const real &) noexcept
Implementation of standard algebraic negative sign operation.
friend real subup(const real &, const real &)
Subtraction of two real values and rounding the result upwards.
friend real operator*(const real &, const real &) noexcept
Implementation of standard algebraic multiplication operation.
friend INLINE real _real(const rvector &) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
friend int sign(const real &) noexcept
The sign of a real value.
real(void) noexcept
Constructor of class real.
Definition real.hpp:122
real(const double &a) noexcept
Constructor of class real.
Definition real.hpp:126
friend INLINE real _real(const rmatrix_slice &) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
friend std::ostream & operator<<(std::ostream &, const real &) noexcept
Implementation of standard output method.
Definition realio.cpp:185
friend real divdown(const real &, const real &)
Division of two real values and rounding the result downwards.
friend real _real(const double &a) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
real(const long a) noexcept
Constructor of class real.
Definition real.hpp:130
real(const float &a) noexcept
Constructor of class real.
Definition real.hpp:124
friend real abs(const real &a) noexcept
The absolute value of a real value.
real(const int a) noexcept
Constructor of class real.
Definition real.hpp:128
INLINE real(const rmatrix_slice &) noexcept
Constructor of class real.
The Data Type rmatrix_slice.
Definition rmatrix.hpp:1443
The Data Type rmatrix.
Definition rmatrix.hpp:471
The Data Type rvector_slice.
Definition rvector.hpp:1064
The Data Type rvector.
Definition rvector.hpp:58
The namespace cxsc, providing all functionality of the class library C-XSC.
Definition cdot.cpp:29
const real EpPid4_real
Constant for rounded to the nearest machine number.
Definition real.cpp:108
const real Er_real
Constant for rounded to the nearest machine number.
Definition real.cpp:102
const real MinReal
Smallest normalized representable floating-point number.
Definition real.cpp:62
const real Sqrt3r_real
Constant for rounded to the nearest machine number.
Definition real.cpp:94
const real Sqrt2_real
Constant for rounded to the nearest machine number.
Definition real.cpp:88
bool IsQuietNaN(const real &a)
Returns if the given real value represents the value of a quiet NaN.
const real Ln10_real
Constant for rounded to the nearest machine number.
Definition real.cpp:97
const real Sqrt7_real
Constant for rounded to the nearest machine number.
Definition real.cpp:90
const real MaxReal
Greatest representable floating-point number.
Definition real.cpp:65
const real SqrtPi_real
Constant for rounded to the nearest machine number.
Definition real.cpp:84
const real Pid4_real
Constant for rounded to the nearest machine number.
Definition real.cpp:80
const real Ln2_real
Constant for rounded to the nearest machine number.
Definition real.cpp:95
const real SqrtPir_real
Constant for rounded to the nearest machine number.
Definition real.cpp:86
const real Pip2_real
Constant for rounded to the nearest machine number.
Definition real.cpp:83
const real Sqrt2r_real
Constant for rounded to the nearest machine number.
Definition real.cpp:91
const real minreal
Smallest positive denormalized representable floating-point number.
Definition real.cpp:63
const real QuietNaN
Representation of Not-a-Number in floating-point format.
Definition real.cpp:68
const real E_real
Constant for rounded to the nearest machine number.
Definition real.cpp:101
const real SignalingNaN
Not defined result in floating-point format.
Definition real.cpp:67
const real Sqrt2Pi_real
Constant for rounded to the nearest machine number.
Definition real.cpp:85
const real Ln2r_real
Constant for rounded to the nearest machine number.
Definition real.cpp:96
const real Epsilon
Machine epsilon.
Definition real.cpp:69
bool IsSignalingNaN(const real &a)
Returns if the given real value represents the value of a signaling NaN.
string realToHex(const real &a)
Returns a real number in hexadecimal format as string.
Definition realio.cpp:58
const real EpPi_real
Constant for rounded to the nearest machine number.
Definition real.cpp:105
const real Pir_real
Constant for rounded to the nearest machine number.
Definition real.cpp:81
const real & MakeHexReal(int sign, unsigned int expo, a_btyp manthigh, a_btyp mantlow)
Produces an IEEE 64-bit floating-point number from given binary coded parts of an IEEE 64-bit floatin...
Definition real.cpp:52
const real Ep2_real
Constant for rounded to the nearest machine number.
Definition real.cpp:103
const real Pi3_real
Constant for rounded to the nearest machine number.
Definition real.cpp:77
const real Pid3_real
Constant for rounded to the nearest machine number.
Definition real.cpp:79
const real Infinity
Representation of positive infinity in floating-point format.
Definition real.cpp:66
const real LnPi_real
Constant for rounded to the nearest machine number.
Definition real.cpp:99
const real Sqrt5_real
Constant for rounded to the nearest machine number.
Definition real.cpp:89
const real Sqrt3_real
Constant for rounded to the nearest machine number.
Definition real.cpp:92
const real Ln2Pi_real
Constant for rounded to the nearest machine number.
Definition real.cpp:100
const real Pid2_real
Constant for rounded to the nearest machine number.
Definition real.cpp:78
real pow2n(const int n) noexcept
Returns the value of .
const real Pi2_real
Constant for rounded to the nearest machine number.
Definition real.cpp:76
void times2pown(cinterval &x, int n) noexcept
Fast multiplication of reference parameter [z] with .
Definition cimath.cpp:2059
const real EpPid2_real
Constant for rounded to the nearest machine number.
Definition real.cpp:107
real Max(const real &a, const real &b)
Returns the greater value of two real values (for Compatibility with former r_util....
const real Pi2r_real
Constant for rounded to the nearest machine number.
Definition real.cpp:82
const real Sqrt2Pir_real
Constant for rounded to the nearest machine number.
Definition real.cpp:87
const real Pi_real
Constant for rounded to the nearest machine number.
Definition real.cpp:75
const real Sqrt3d2_real
Constant for rounded to the nearest machine number.
Definition real.cpp:93
const real Ep2r_real
Constant for rounded to the nearest machine number.
Definition real.cpp:104
const real Ln10r_real
Constant for rounded to the nearest machine number.
Definition real.cpp:98
bool IsInfinity(const real &a)
Returns if the given real value represents the value infinity.
const real Ep2Pi_real
Constant for rounded to the nearest machine number.
Definition real.cpp:106