C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
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: real.cpp,v 1.28 2014/01/30 17:23:48 cxsc Exp $ */
25 
26 #include "real.hpp"
27 #include "ioflags.hpp"
28 
29 namespace cxsc {
30 
31 //----------------------------------------------------------------------------
32 // MakeHexReal - erstellt aus den binaer angegebenen Einzelteilen einer
33 // IEEE 64-bit Gleitkommazahl eine solche, hierbei ist
34 // sign Flag 'zu erzeugener real ist negativ'
35 // expo Exponent (11 Bit 0x000 - 0x7FF)
36 // manthigh obere 20 Bit der Mantisse (Bit 32 - 53)
37 // mantlow untere 32 Bit der Mantisse (Bit 0 - 31)
38 //
39 // - die Mantisse ist normalisiert dargestellt, d.h.
40 // implizit wird noch ein Bit 1 als Vorkommastelle
41 // vorangestellt.
42 // Eine Ausnahme bilden die Zahlen mit Exponent = 0,
43 // oder Exponent = 0x7FF (alle Exponentenbits = 1)
44 //
52 const real& MakeHexReal(int sign, unsigned int expo, a_btyp manthigh, a_btyp mantlow)
53 {
54  static real a;
55  ((a_btyp*)&a)[LOWREAL] = mantlow,
56  ((a_btyp*)&a)[HIGHREAL] = manthigh & 0xFFFFFL,
57  ((a_btyp*)&a)[HIGHREAL] |= ((a_btyp) (expo & 0x7FF)) << 20,
58  ((a_btyp*)&a)[HIGHREAL] |= (sign ? 0x80000000L : 0x00000000);
59  return a;
60 }
61 
62 const real MinReal = MakeHexReal(0, 0x001, 0x00000L, 0x00000000L);
63 const real minreal = MakeHexReal(0, 0x000, 0x00000L, 0x00000001L);
64 // Blomquist, 26.09.02; minreal = smallest positive real number.
65 const real MaxReal = MakeHexReal(0, 0x7FE, 0xFFFFFL, 0xFFFFFFFFL);
66 const real Infinity = MakeHexReal(0, 0x7FF, 0x00000L, 0x00000000L);
67 const real SignalingNaN = MakeHexReal(1, 0x7FF, 0x80000L, 0x00000000L);
68 const real QuietNaN = MakeHexReal(0, 0x7FF, 0x00000L, 0x00000001L);
69 const real Epsilon = power(2,-53);
70 const real Factor = power(2, 27) + 1;
71 
72 
73 // The following constants are roundet to the nearest machine nunmber:
74 
75 const real Pi_real = 7074237752028440.0 / 2251799813685248.0; // Pi
76 const real Pi2_real = 7074237752028440.0/1125899906842624.0; // 2*Pi
77 const real Pi3_real = 5305678314021330.0/562949953421312.0; // 3*Pi
78 const real Pid2_real = 7074237752028440.0/4503599627370496.0; // Pi/2
79 const real Pid3_real = 4716158501352294.0/4503599627370496.0; // Pi/3
80 const real Pid4_real = 7074237752028440.0/9007199254740992.0; // Pi/4
81 const real Pir_real = 5734161139222659.0/18014398509481984.0; // 1/Pi
82 const real Pi2r_real = 5734161139222659.0/36028797018963968.0; // 1/(2*Pi)
83 const real Pip2_real = 5556093337880030.0/562949953421312.0; // Pi^2
84 const real SqrtPi_real = 7982422502469483.0/4503599627370496.0;// sqrt(Pi)
85 const real Sqrt2Pi_real = 5644425081792262.0/2251799813685248.0; // sqrt(2Pi)
86 const real SqrtPir_real = 5081767996463981.0/9007199254740992.0; // 1/sqrt(Pi)
87 const real Sqrt2Pir_real = 7186705221432913.0/18014398509481984.0; // 1/sqrt(2Pi)
88 const real Sqrt2_real = 6369051672525773.0/4503599627370496.0; // sqrt(2)
89 const real Sqrt5_real = 5035177455121576.0 / 2251799813685248.0; // sqrt(5)
90 const real Sqrt7_real = 5957702309312746.0 / 2251799813685248.0; // sqrt(7)
91 const real Sqrt2r_real = 6369051672525773.0/9007199254740992.0;// 1/sqrt(2)
92 const real Sqrt3_real = 7800463371553962.0/4503599627370496.0; // sqrt(3)
93 const real Sqrt3d2_real = 7800463371553962.0/9007199254740992.0; // sqrt(3)/2
94 const real Sqrt3r_real = 5200308914369308.0/9007199254740992.0;// 1/sqrt(3)
95 const real Ln2_real = 6243314768165359.0 / 9007199254740992.0; // ln(2)
96 const real Ln2r_real = 6497320848556798.0 / 4503599627370496.0; // 1/ln(2)
97 const real Ln10_real = 5184960683398422.0 / 2251799813685248.0; // ln(10)
98 const real Ln10r_real = 7823553867474190.0/18014398509481984.0; // 1/ln(10)
99 const real LnPi_real = 5155405087351229.0 / 4503599627370496.0; // ln(Pi)
100 const real Ln2Pi_real = 8277062471433909.0/4503599627370496.0; // ln(2Pi)
101 const real E_real = 6121026514868073.0 / 2251799813685248.0; // e
102 const real Er_real = 6627126856707896.0 / 18014398509481984.0; // 1/e
103 const real Ep2_real = 8319337573440942.0 / 1125899906842624.0; // e^2
104 const real Ep2r_real = 4875967449235916.0/36028797018963968.0; // 1/e^2
105 const real EpPi_real = 6513525919879994.0/281474976710656.0; // e^(Pi)
106 const real Ep2Pi_real = 4710234414611993.0/8796093022208.0; // e^(2Pi)
107 const real EpPid2_real = 5416116035097439.0/1125899906842624.0; // e^(Pi/2)
108 const real EpPid4_real = 4938827609611434.0/2251799813685248.0; // e^(Pi/4)
109 
110 } // namespace cxsc
cxsc::SqrtPi_real
const real SqrtPi_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:84
cxsc::Sqrt2Pir_real
const real Sqrt2Pir_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:87
cxsc::QuietNaN
const real QuietNaN
Representation of Not-a-Number in floating-point format.
Definition: real.cpp:68
cxsc::MinReal
const real MinReal
Smallest normalized representable floating-point number.
Definition: real.cpp:62
cxsc::Pid3_real
const real Pid3_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:79
cxsc::Ln10_real
const real Ln10_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:97
cxsc::minreal
const real minreal
Smallest positive denormalized representable floating-point number.
Definition: real.cpp:63
cxsc::Sqrt2Pi_real
const real Sqrt2Pi_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:85
cxsc::Pip2_real
const real Pip2_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:83
cxsc::Ep2Pi_real
const real Ep2Pi_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:106
cxsc::Pid2_real
const real Pid2_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:78
cxsc::MakeHexReal
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
cxsc::E_real
const real E_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:101
cxsc::Ln2r_real
const real Ln2r_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:96
cxsc::Ep2r_real
const real Ep2r_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:104
cxsc::Ln10r_real
const real Ln10r_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:98
cxsc::Sqrt3r_real
const real Sqrt3r_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:94
cxsc::Sqrt3_real
const real Sqrt3_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:92
cxsc::Pir_real
const real Pir_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:81
cxsc::Infinity
const real Infinity
Representation of positive infinity in floating-point format.
Definition: real.cpp:66
cxsc::SqrtPir_real
const real SqrtPir_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:86
cxsc::Pid4_real
const real Pid4_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:80
cxsc::Ln2_real
const real Ln2_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:95
cxsc::Pi3_real
const real Pi3_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:77
cxsc::Ep2_real
const real Ep2_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:103
cxsc::Sqrt3d2_real
const real Sqrt3d2_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:93
cxsc::SignalingNaN
const real SignalingNaN
Not defined result in floating-point format.
Definition: real.cpp:67
cxsc::power
cinterval power(const cinterval &z, int n)
Calculates .
Definition: cimath.cpp:1941
cxsc::Sqrt5_real
const real Sqrt5_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:89
cxsc
The namespace cxsc, providing all functionality of the class library C-XSC.
Definition: cdot.cpp:29
cxsc::Ln2Pi_real
const real Ln2Pi_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:100
cxsc::EpPid4_real
const real EpPid4_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:108
cxsc::MaxReal
const real MaxReal
Greatest representable floating-point number.
Definition: real.cpp:65
cxsc::Pi_real
const real Pi_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:75
cxsc::Sqrt2r_real
const real Sqrt2r_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:91
cxsc::LnPi_real
const real LnPi_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:99
cxsc::Pi2r_real
const real Pi2r_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:82
cxsc::Pi2_real
const real Pi2_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:76
cxsc::EpPi_real
const real EpPi_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:105
cxsc::Sqrt7_real
const real Sqrt7_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:90
cxsc::Epsilon
const real Epsilon
Machine epsilon.
Definition: real.cpp:69
cxsc::Sqrt2_real
const real Sqrt2_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:88
cxsc::Er_real
const real Er_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:102
cxsc::real
The Scalar Type real.
Definition: real.hpp:113
cxsc::EpPid2_real
const real EpPid2_real
Constant for rounded to the nearest machine number.
Definition: real.cpp:107