00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _CXSC_REAL_HPP_INCLUDED
00027 #define _CXSC_REAL_HPP_INCLUDED
00028
00029 #include <iostream>
00030 #include <string>
00031
00032
00033
00034 #include "compiler.h"
00035 #include "RtsTyp.h"
00036 #include "ioflags.hpp"
00037
00038 #include "except.hpp"
00040
00044 namespace cxsc {
00045
00046 class rvector;
00047 class rmatrix;
00048 class rvector_slice;
00049 class rmatrix_slice;
00050
00051 #define addu addup
00052 #define addd adddown
00053 #define subu subup
00054 #define subd subdown
00055 #define mulu multup
00056 #define muld multdown
00057 #define divu divup
00058 #define divd divdown
00059
00060
00061
00062
00063
00064
00065
00067
00113 class real
00114 {
00115 private:
00116
00117 double w;
00118
00119 public:
00120
00122 real(void) throw () { }
00124 real(const float &a) throw () : w(a) { }
00126 real(const double &a) throw () : w(a) { }
00128 real(const int a) throw () : w(a) { }
00130 real(const long a) throw () : w(a) { }
00131
00132
00134 explicit real(const l_real &) throw();
00135
00136
00137 #if(CXSC_INDEX_CHECK)
00138
00139 explicit INLINE real(const rvector &) throw (ERROR_RVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_RVECTOR_USE_OF_UNINITIALIZED_OBJ);
00141 explicit INLINE real(const rvector_slice &) throw (ERROR_RVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_RVECTOR_USE_OF_UNINITIALIZED_OBJ);
00143 explicit INLINE real(const rmatrix &) throw (ERROR_RMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_RMATRIX_USE_OF_UNINITIALIZED_OBJ);
00145 explicit INLINE real(const rmatrix_slice &) throw (ERROR_RMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_RMATRIX_USE_OF_UNINITIALIZED_OBJ);
00146 #else
00147
00148 explicit INLINE real(const rvector &) throw ();
00150 explicit INLINE real(const rvector_slice &) throw ();
00152 explicit INLINE real(const rmatrix &) throw ();
00154 explicit INLINE real(const rmatrix_slice &) throw ();
00155 #endif
00156
00157
00158
00159
00160
00161
00163 friend inline double _double(const real &a) throw();
00165 friend inline real _real(const double &a) throw();
00166
00167 #if(CXSC_INDEX_CHECK)
00168
00169
00174 friend INLINE real _real(const rvector &) throw (ERROR_RVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_RVECTOR_USE_OF_UNINITIALIZED_OBJ);
00176
00181 friend INLINE real _real(const rvector_slice &) throw (ERROR_RVECTOR_TYPE_CAST_OF_THICK_OBJ,ERROR_RVECTOR_USE_OF_UNINITIALIZED_OBJ);
00183
00188 friend INLINE real _real(const rmatrix &) throw (ERROR_RMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_RMATRIX_USE_OF_UNINITIALIZED_OBJ);
00190
00195 friend INLINE real _real(const rmatrix_slice &) throw (ERROR_RMATRIX_TYPE_CAST_OF_THICK_OBJ,ERROR_RMATRIX_USE_OF_UNINITIALIZED_OBJ);
00196 #else
00197
00198
00203 friend INLINE real _real(const rvector &) throw ();
00205
00210 friend INLINE real _real(const rvector_slice &) throw ();
00212
00217 friend INLINE real _real(const rmatrix &) throw ();
00219
00224 friend INLINE real _real(const rmatrix_slice &) throw ();
00225 #endif
00226
00227
00228
00230 friend std::ostream & operator <<(std::ostream &,const real &) throw();
00232 friend std::istream & operator >>(std::istream &,real &) throw();
00234 friend std::string & operator <<(std::string &,const real &) throw();
00236 friend std::string & operator >>(std::string &,real &) throw();
00238 friend void operator >>(const char *,real &) throw();
00240 friend void operator >>(const std::string &,real &) throw();
00241
00242
00243
00244
00245
00247 friend inline real operator -(const real &) throw ();
00249 friend inline real operator +(const real &) throw ();
00250
00252 friend inline real operator +(const real &,const real &) throw();
00254 friend inline real operator -(const real &,const real &) throw();
00256 friend inline real operator *(const real &,const real &) throw();
00258 friend inline real operator /(const real &,const real &) throw();
00259
00261 friend inline real& operator +=(real &, const real &) throw();
00263 friend inline real& operator -=(real &, const real &) throw();
00265 friend inline real& operator *=(real &, const real &) throw();
00267 friend inline real& operator /=(real &, const real &) throw();
00268
00269
00270
00272 friend inline bool operator! (const real& a) throw();
00274 friend inline bool operator== (const real& a, const real& b) throw();
00276 friend inline bool operator!= (const real& a, const real& b) throw();
00278 friend inline bool operator< (const real& a, const real& b) throw();
00280 friend inline bool operator<= (const real& a, const real& b) throw();
00282 friend inline bool operator>= (const real& a, const real& b) throw();
00284 friend inline bool operator> (const real& a, const real& b) throw();
00285
00287 friend inline bool operator== (const real& a, const int & b) throw();
00289 friend inline bool operator!= (const real& a, const int & b) throw();
00291 friend inline bool operator== (const int & a, const real& b) throw();
00293 friend inline bool operator!= (const int & a, const real& b) throw();
00295 friend inline bool operator== (const real& a, const long & b) throw();
00297 friend inline bool operator!= (const real& a, const long & b) throw();
00299 friend inline bool operator== (const long & a, const real& b) throw();
00301 friend inline bool operator!= (const long & a, const real& b) throw();
00303 friend inline bool operator== (const real& a, const float & b) throw();
00305 friend inline bool operator!= (const real& a, const float & b) throw();
00307 friend inline bool operator== (const float & a, const real& b) throw();
00309 friend inline bool operator!= (const float & a, const real& b) throw();
00311 friend inline bool operator== (const real& a, const double & b) throw();
00313 friend inline bool operator!= (const real& a, const double & b) throw();
00315 friend inline bool operator== (const double & a, const real& b) throw();
00317 friend inline bool operator!= (const double & a, const real& b) throw();
00318
00319
00320
00322 friend inline real addup(const real &, const real &);
00324 friend inline real adddown(const real &, const real &);
00326 friend inline real subup(const real &, const real &);
00328 friend inline real subdown(const real &, const real &);
00330 friend inline real multup(const real &, const real &);
00332 friend inline real multdown(const real &, const real &);
00334 friend inline real divup(const real &, const real &);
00336 friend inline real divdown(const real &, const real &);
00337
00338
00339
00341 friend inline real abs(const real &a) throw();
00343 friend inline int sign(const real &) throw();
00344
00346 friend inline real pred(const real &) throw();
00348 friend inline real succ(const real &) throw();
00350 friend inline a_intg expo(const real &) throw();
00352 friend inline real comp(const real &,a_intg) throw();
00354 friend inline real mant(const real &) throw();
00355
00356 real & operator = (const lx_real&) throw();
00357 real & operator = (const l_real&) throw();
00358 };
00359
00360 inline real comp(const real &,a_intg) throw();
00361
00362
00363
00364
00365
00366
00367
00368 std::ostream & operator <<(std::ostream &,const real &) throw();
00369 std::istream & operator >>(std::istream &,real &) throw();
00370 std::string & operator <<(std::string &,const real &) throw();
00371 std::string & operator >>(std::string &,real &) throw();
00372 void operator >>(const char *,real &) throw();
00373 void operator >>(const std::string &,real &) throw();
00374
00375
00376
00377
00378
00379
00380
00382 inline real max(const real & a, const real & b);
00384 inline real min(const real & a, const real & b);
00386 inline real Max(const real & a, const real & b);
00387
00388
00389
00390
00391
00393 const real& MakeHexReal (
00394 int sign, unsigned int expo, a_btyp manthigh, a_btyp mantlow);
00395
00397 inline bool IsInfinity(const real &a);
00399 inline bool IsQuietNaN(const real &a);
00401 inline bool IsSignalingNaN(const real &a);
00402
00403
00404
00406 inline void times2pown(real& r,const int n);
00407
00409 inline real pow2n(const int n) throw();
00410
00412 string realToHex(const real& a);
00413
00414
00415
00416
00417
00418
00419
00420
00422 extern const real MinReal;
00424 extern const real minreal;
00426 extern const real MaxReal;
00428 extern const real Infinity;
00430 extern const real SignalingNaN;
00432 extern const real QuietNaN;
00434 extern const real Epsilon;
00435 extern const real Factor;
00436
00438 extern const real Pi_real;
00440 extern const real Pi2_real;
00442 extern const real Pi3_real;
00444 extern const real Pid2_real;
00446 extern const real Pid3_real;
00448 extern const real Pid4_real;
00450 extern const real Pir_real;
00452 extern const real Pi2r_real;
00454 extern const real Pip2_real;
00456 extern const real SqrtPi_real;
00458 extern const real Sqrt2Pi_real;
00460 extern const real SqrtPir_real;
00462 extern const real Sqrt2Pir_real;
00464 extern const real Sqrt2_real;
00466 extern const real Sqrt5_real;
00468 extern const real Sqrt7_real;
00470 extern const real Sqrt2r_real;
00472 extern const real Sqrt3_real;
00474 extern const real Sqrt3d2_real;
00476 extern const real Sqrt3r_real;
00478 extern const real Ln2_real;
00480 extern const real Ln2r_real;
00482 extern const real Ln10_real;
00484 extern const real Ln10r_real;
00486 extern const real LnPi_real;
00488 extern const real Ln2Pi_real;
00490 extern const real E_real;
00492 extern const real Er_real;
00494 extern const real Ep2_real;
00496 extern const real Ep2r_real;
00498 extern const real EpPi_real;
00500 extern const real Ep2Pi_real;
00502 extern const real EpPid2_real;
00504 extern const real EpPid4_real;
00505
00506 }
00507
00508 #include "real.inl"
00509 #include "rmath.hpp"
00510
00511 #endif // _CXSC_REAL_HPP_INCLUDED
00512