C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
real.cpp
00001 /*
00002 **  CXSC is a C++ library for eXtended Scientific Computing (V 2.5.4)
00003 **
00004 **  Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
00005 **                          Universitaet Karlsruhe, Germany
00006 **            (C) 2000-2014 Wiss. Rechnen/Softwaretechnologie
00007 **                          Universitaet Wuppertal, Germany   
00008 **
00009 **  This library is free software; you can redistribute it and/or
00010 **  modify it under the terms of the GNU Library General Public
00011 **  License as published by the Free Software Foundation; either
00012 **  version 2 of the License, or (at your option) any later version.
00013 **
00014 **  This library is distributed in the hope that it will be useful,
00015 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 **  Library General Public License for more details.
00018 **
00019 **  You should have received a copy of the GNU Library General Public
00020 **  License along with this library; if not, write to the Free
00021 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 /* CVS $Id: real.cpp,v 1.28 2014/01/30 17:23:48 cxsc Exp $ */
00025 
00026 #include "real.hpp"
00027 #include "ioflags.hpp"
00028 
00029 namespace cxsc {
00030 
00031 //----------------------------------------------------------------------------
00032 // MakeHexReal - erstellt aus den binaer angegebenen Einzelteilen einer
00033 //               IEEE 64-bit Gleitkommazahl eine solche, hierbei ist
00034 //                 sign         Flag 'zu erzeugener real ist negativ'
00035 //                 expo         Exponent (11 Bit 0x000 - 0x7FF)
00036 //                 manthigh     obere  20 Bit der Mantisse (Bit 32 - 53)
00037 //                 mantlow      untere 32 Bit der Mantisse (Bit  0 - 31)
00038 //
00039 //             - die Mantisse ist normalisiert dargestellt, d.h.
00040 //               implizit wird noch ein Bit 1 als Vorkommastelle
00041 //               vorangestellt.
00042 //               Eine Ausnahme bilden die Zahlen mit Exponent = 0,
00043 //               oder Exponent = 0x7FF (alle Exponentenbits = 1)
00044 //
00052 const real& MakeHexReal(int sign, unsigned int expo, a_btyp manthigh, a_btyp mantlow)
00053 {
00054   static real a;
00055   ((a_btyp*)&a)[LOWREAL]   = mantlow,
00056   ((a_btyp*)&a)[HIGHREAL]  = manthigh & 0xFFFFFL,
00057   ((a_btyp*)&a)[HIGHREAL] |= ((a_btyp) (expo & 0x7FF)) << 20,
00058   ((a_btyp*)&a)[HIGHREAL] |= (sign ? 0x80000000L : 0x00000000);
00059   return a;
00060 }
00061 
00062 const real MinReal      = MakeHexReal(0, 0x001, 0x00000L, 0x00000000L);
00063 const real minreal      = MakeHexReal(0, 0x000, 0x00000L, 0x00000001L);
00064 // Blomquist, 26.09.02; minreal = smallest positive real number.
00065 const real MaxReal      = MakeHexReal(0, 0x7FE, 0xFFFFFL, 0xFFFFFFFFL);
00066 const real Infinity     = MakeHexReal(0, 0x7FF, 0x00000L, 0x00000000L);
00067 const real SignalingNaN = MakeHexReal(1, 0x7FF, 0x80000L, 0x00000000L);
00068 const real QuietNaN     = MakeHexReal(0, 0x7FF, 0x00000L, 0x00000001L);
00069 const real Epsilon      = power(2,-53);
00070 const real Factor       = power(2, 27) + 1;
00071 
00072 
00073 // The following constants are roundet to the nearest machine nunmber:
00074 
00075 const real Pi_real = 7074237752028440.0 / 2251799813685248.0;  // Pi
00076 const real Pi2_real = 7074237752028440.0/1125899906842624.0;   // 2*Pi
00077 const real Pi3_real = 5305678314021330.0/562949953421312.0;    // 3*Pi
00078 const real Pid2_real = 7074237752028440.0/4503599627370496.0;  // Pi/2
00079 const real Pid3_real = 4716158501352294.0/4503599627370496.0;  // Pi/3
00080 const real Pid4_real = 7074237752028440.0/9007199254740992.0;  // Pi/4
00081 const real Pir_real = 5734161139222659.0/18014398509481984.0;  // 1/Pi
00082 const real Pi2r_real = 5734161139222659.0/36028797018963968.0; // 1/(2*Pi)
00083 const real Pip2_real = 5556093337880030.0/562949953421312.0;   // Pi^2
00084 const real SqrtPi_real = 7982422502469483.0/4503599627370496.0;// sqrt(Pi)
00085 const real Sqrt2Pi_real = 5644425081792262.0/2251799813685248.0; // sqrt(2Pi)
00086 const real SqrtPir_real = 5081767996463981.0/9007199254740992.0; // 1/sqrt(Pi)
00087 const real Sqrt2Pir_real = 7186705221432913.0/18014398509481984.0; // 1/sqrt(2Pi)
00088 const real Sqrt2_real = 6369051672525773.0/4503599627370496.0; // sqrt(2)
00089 const real Sqrt5_real = 5035177455121576.0 / 2251799813685248.0; // sqrt(5)
00090 const real Sqrt7_real = 5957702309312746.0 / 2251799813685248.0; // sqrt(7)
00091 const real Sqrt2r_real = 6369051672525773.0/9007199254740992.0;// 1/sqrt(2)
00092 const real Sqrt3_real = 7800463371553962.0/4503599627370496.0; // sqrt(3)
00093 const real Sqrt3d2_real = 7800463371553962.0/9007199254740992.0;  // sqrt(3)/2
00094 const real Sqrt3r_real = 5200308914369308.0/9007199254740992.0;// 1/sqrt(3)
00095 const real Ln2_real = 6243314768165359.0 / 9007199254740992.0; // ln(2)
00096 const real Ln2r_real = 6497320848556798.0 / 4503599627370496.0; // 1/ln(2)
00097 const real Ln10_real = 5184960683398422.0 / 2251799813685248.0; // ln(10)
00098 const real Ln10r_real = 7823553867474190.0/18014398509481984.0; // 1/ln(10)
00099 const real LnPi_real = 5155405087351229.0 / 4503599627370496.0; // ln(Pi)
00100 const real Ln2Pi_real = 8277062471433909.0/4503599627370496.0;  // ln(2Pi)
00101 const real E_real = 6121026514868073.0 / 2251799813685248.0;    // e
00102 const real Er_real = 6627126856707896.0 / 18014398509481984.0;  // 1/e
00103 const real Ep2_real = 8319337573440942.0 / 1125899906842624.0;  // e^2
00104 const real Ep2r_real = 4875967449235916.0/36028797018963968.0;  // 1/e^2
00105 const real EpPi_real = 6513525919879994.0/281474976710656.0;    // e^(Pi)
00106 const real Ep2Pi_real = 4710234414611993.0/8796093022208.0;     // e^(2Pi)
00107 const real EpPid2_real = 5416116035097439.0/1125899906842624.0; // e^(Pi/2)
00108 const real EpPid4_real = 4938827609611434.0/2251799813685248.0; // e^(Pi/4)
00109 
00110 } // namespace cxsc