fastNumber.h

Go to the documentation of this file.
00001 #ifndef improved_zahl
00002 #define improved_zahl
00003 
00004 
00005 
00006 #include "CompileFunctions.h"
00007 #include <math.h>
00008 #define STR(X) #X
00009 #define SW_STATUS(v1)  STR(v1)
00010 
00033 using namespace std;
00034 
00035 
00036 
00058 template <int CHAR, typename TScalar, typename TScalarPair>
00059 struct number_eps1
00060 {
00061  public:
00062 
00063                 typedef         TScalar scalarType;     
00064 
00067                 TScalarPair     epsx; 
00068 
00072                 static  const number_eps1       Zero;//=number_eps1(0);
00073                 static  const number_eps1       One;//=number_eps1(1);
00074         
00075                 enum { bitsize          = needbits<CHAR>::value         }; 
00076                 enum { fullbitsize      = needbits<CHAR>::doubledvalue  }; 
00077         
00078                 enum { maskx    = pow2<needbits<CHAR>::value>::valueMinusOne    }; 
00079                 
00081                 enum { maskeps  = pow2<needbits<CHAR>::doubledvalue>::valueMinusOne - ( pow2<needbits<CHAR>::value>::valueMinusOne)     };
00087 
00088                 static inline bool memsetClearAllowed() {       return true; }
00089                 
00090                 static inline bool wellDefined(unsigned int characteristic);
00091                 
00093                 static inline bool wellDefined();
00099                 inline number_eps1();
00100         
00106                 inline number_eps1(int epsPrec, string dummy) ;
00107         
00109                 inline number_eps1 (scalarType x);
00110                 
00112                 inline number_eps1 (const  number_eps1 & z_x) ;
00113                 
00115                 inline number_eps1 (scalarType x, scalarType eps);
00120                 inline unsigned short   getEpsPrecision() const         {       return 1;       }; 
00121 
00122                 inline void     setEpsPrecision(int epsPrecision) const         {       assert( epsPrecision==1);       }; 
00123 
00125                 inline  short   getEpsDegree() const;
00126                 
00132                 inline scalarType       getX() const ;  
00133                 inline scalarType       getEps() const; 
00134         
00135                 inline void             setX(scalarType x)  ;
00136                 inline void             setEps(scalarType eps) ;
00137                 inline void             setValue( unsigned short _epsPrecision, scalarType val);
00138 
00139                 inline int              getValue( unsigned short _epsPrecision) 
00140                 {       
00141                         if(_epsPrecision==0)            return getX(); 
00142                         else if (_epsPrecision==1)      return getEps();
00143                         else    return 0;
00144                  };
00150                 inline  bool    isZero() const  ;
00151                 inline  bool    isNotZero() const       ;
00152 
00154                 inline bool     nearlyEqual(const number_eps1 & z) const;
00155 
00156                 inline int      operator==(const  number_eps1<CHAR, TScalar, TScalarPair> & z) const;
00157                 inline int      operator!=(const  number_eps1<CHAR, TScalar, TScalarPair> & z) const;
00164                 static 
00165                 inline size_t   getSingleIndex     (   const number_eps1<CHAR, TScalar,TScalarPair>  b,
00166                                                                          const TScalar                          characteristic ) ;
00167                 
00169                 static 
00170                 inline size_t   getSingleIndexByRef(    const number_eps1<CHAR, TScalar,TScalarPair> & b,
00171                                                                          const TScalar & characteristic ) ;
00172 
00174                 static 
00175                 inline size_t   getPairIndex     (      const number_eps1<CHAR, TScalar,TScalarPair> a, 
00176                                                                         const number_eps1<CHAR, TScalar,TScalarPair> b, 
00177                                                                         const TScalar characteristic) ;
00178         
00180                 static 
00181                 inline size_t   getPairIndexByRef(      const number_eps1<CHAR, TScalar,TScalarPair>& a, 
00182                                                                         const number_eps1<CHAR, TScalar,TScalarPair>& b,
00183                                                                         const TScalar & characteristic) ;
00184         
00185                 
00186                 static inline size_t    getMaxSingleIndex(const TScalar characteristic) ;
00187                 static inline size_t    getMaxPairIndex  (const TScalar characteristic) ;
00193                 static inline size_t    getSingleIndex          ( const number_eps1<CHAR, TScalar,TScalarPair> b ) ;
00194                 
00196                 static inline size_t    getSingleIndexByRef     ( const number_eps1<CHAR, TScalar,TScalarPair>& b ) ;
00197 
00199                 static inline size_t    getPairIndex     (      const number_eps1<CHAR, TScalar,TScalarPair> a,
00200                                                                                 const number_eps1<CHAR, TScalar,TScalarPair> b) ;
00201         
00203                 static inline size_t    getPairIndexByRef(      const number_eps1<CHAR, TScalar,TScalarPair>& a, 
00204                                                                                 const number_eps1<CHAR, TScalar,TScalarPair>& b) ;
00205         
00207 };
00208 
00209 
00210 
00211 
00212 
00243 template <int CHAR, class TScalar> 
00244 struct number_eps0
00245 {
00246  public:
00247         
00248         //operator int() {return x;}
00249 
00250         TScalar x; 
00251 
00252         typedef TScalar scalarType;     
00253 
00254         static  const number_eps0       Zero;
00255         static  const number_eps0       One;
00256 
00258         enum{  bitsize = needbits<CHAR>::value }; 
00259 
00260 
00263                 inline number_eps0() ; 
00264 
00265                 inline number_eps0 (TScalar _x) ;
00266                 
00267                 inline number_eps0 (TScalar _x, TScalar eps) ;
00268          
00269                 inline number_eps0(int epsPrec, std::string dummy);
00270 
00275 
00276                 static inline bool memsetClearAllowed() {       return true; }
00277 
00278                 static inline bool wellDefined();
00279 
00280                 static inline bool wellDefined(unsigned int characteristic)
00281                 {
00282                         return wellDefined();
00283                 }
00290                 inline unsigned short   getEpsPrecision() const {       return 0;       };
00291 
00293                 inline  short           getEpsDegree()  const;
00294 
00297         /*inline explicit operator int ()       {       return x;       } *///...
00298         
00301 
00302                  static inline  size_t  getPairIndex     (      const number_eps0<CHAR, TScalar>  a,
00303                                                                                 const number_eps0<CHAR, TScalar> b, 
00304                                                                                 const TScalar characteristic) ;
00305 
00307                  static inline size_t   getPairIndexByRef(const number_eps0<CHAR, TScalar> & a,
00308                                                                         const number_eps0<CHAR, TScalar> & b,
00309                                                                         const TScalar &  characteristic) ;
00310         
00312                  static inline size_t   getSingleIndex          (const number_eps0<CHAR, TScalar>  b,
00313                                                                                 const TScalar characteristic)  ;
00315                  static inline size_t   getSingleIndexByRef     (const number_eps0<CHAR, TScalar> & b,
00316                                                                                 const TScalar &  characteristic)  ;
00317 
00318                 static inline size_t   getMaxSingleIndex(const TScalar characteristic);
00319                 static inline size_t   getMaxPairIndex  (const TScalar characteristic);
00325 
00326                  static inline  size_t  getPairIndex     (      const number_eps0<CHAR, TScalar>  a,
00327                                                                                 const number_eps0<CHAR, TScalar> b) ;
00328 
00330                  static inline size_t   getPairIndexByRef(      const number_eps0<CHAR, TScalar> & a,
00331                                                                                 const number_eps0<CHAR, TScalar> & b) ;
00332         
00334                  static inline size_t   getSingleIndex          (const number_eps0<CHAR, TScalar>  b)  ;
00335 
00337                  static inline size_t   getSingleIndexByRef     (const number_eps0<CHAR, TScalar> & b)  ;
00338 
00343                 inline TScalar  getX()                          const  ;
00344                 inline void     setX(const TScalar _x) ;
00345 
00346                 inline TScalar  getEps()                                const ;
00347 
00348                 inline void     setEps(const TScalar eps)       const ;
00349 
00351                 inline void     setValue( unsigned short _epsExp, 
00352                                                         TScalar           coeff    );
00353 
00354                 inline int              getValue( unsigned short _epsExp) const;
00360                  inline  bool   isZero()    const        ;
00361                  inline  bool   isNotZero() const  ;
00362 
00364                 inline bool nearlyEqual(const number_eps0 z)    const  ;
00365 
00366                 inline int      operator==(const  number_eps0 & z)      const    ;
00367                 inline int      operator!=(const  number_eps0 & z)      const    ;
00368         
00370 };
00371 
00372 
00373         #include "fastNumber.cpp"
00374 
00375 
00376 #endif
Generated on Tue Nov 23 13:10:51 2010 for centerfocus by  doxygen 1.6.3