Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Beta/Math/Number/NbOperator1.hpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////
00002 //  How to use this file:                                             //
00003 //  =====================                                             //
00004 //  #define NUMBER  Double  /* The name of the class */               //
00005 //  #define TYPE    double  /* The storage data type */               //
00006 //  #define ZERO    0.0     /* The value zero in that data type */    //
00007 //                                                                    //
00008 //  class Double {                                                    //
00009 //      // ...                                                        //
00010 //      #include <j2k/Fred/Math/Number/NbVerify.hpp>                  //
00011 //      #include <j2k/Fred/Math/Number/NbOperator1.hpp>               //
00012 //                                                                    //
00013 //      /* Operator right handside */                                 //
00014 //      /* Might consider automatic type upgrading for simplicity...  //
00015 //      #define  TYPE2   double                                       //
00016 //      #include <j2k/Fred/Math/Number/NbOperator2.hpp>               //
00017 //                                                                    //
00018 //      #define  TYPE2   float                                        //
00019 //      #include <j2k/Fred/Math/Number/NbOperator2.hpp>               //
00020 //                                                                    //
00021 //      #define  TYPE2   signed long                                  //
00022 //      #include <j2k/Fred/Math/Number/NbOperator2.hpp>               //
00023 //      #define  TYPE2   unsigned long                                //
00024 //      #include <j2k/Fred/Math/Number/NbOperator2.hpp>               //
00025 //                                                                    //
00026 //      #define  TYPE2   signed short                                 //
00027 //      #include <j2k/Fred/Math/Number/NbOperator2.hpp>               //
00028 //      #define  TYPE2   unsigned short                               //
00029 //      #include <j2k/Fred/Math/Number/NbOperator2.hpp>               //
00030 //                                                                    //
00031 //      #define  TYPE2   signed char                                  //
00032 //      #include <j2k/Fred/Math/Number/NbOperator2.hpp>               //
00033 //      #define  TYPE2   unsigned char                                //
00034 //      #include <j2k/Fred/Math/Number/NbOperator2.hpp>               //
00035 //                                                                    //
00036 //      #define  TYPE2   signed int                                   //
00037 //      #include <j2k/Fred/Math/Number/NbOperator2.hpp>               //
00038 //      #define  TYPE2   unsigned int                                 //
00039 //      #include <j2k/Fred/Math/Number/NbOperator2.hpp>               //
00040 //  };                                                                //
00041 //  #undef  TYPE                                                      //
00042 //  #undef  ZERO                                                      //
00043 //  #undef  NUMBER                                                    //
00044 ////////////////////////////////////////////////////////////////////////
00045 
00046 #ifndef TYPE
00047  #error "TYPE is not defined !"
00048 #endif
00049 
00050 #ifndef NUMBER
00051  #error "NUMBER is not defined !"
00052 #endif
00053 
00054   // Compare Operators: Part 1                                        
00055   friend BOOL isEqualTo( const NUMBER& l, const NUMBER& r ) {         
00056     int temp = MathStateEqualTo[ (int)l.state ][ (int)r.state ];      
00057     if ( temp < 2 ) return (BOOL)temp;                                
00058     return ( l.value == r.value );                                    
00059   }                                                                   
00060                                                                       
00061   friend BOOL isLessThan( const NUMBER& l, const NUMBER& r ) {        
00062     int temp = MathStateLessThan[ (int)l.state ][ (int)r.state ];     
00063     if ( temp < 2 ) return (BOOL)temp;                                
00064     return (l.value <  r.value);                                      
00065   }                                                                   
00066                                                                       
00067   friend BOOL isBiggerThan( const NUMBER& l, const NUMBER& r ) {      
00068     int temp = MathStateBiggerThan[ (int)l.state ][ (int)r.state ];   
00069     if ( temp < 2 ) return (BOOL)temp;                                
00070     return (l.value >  r.value);                                      
00071   }                                                                   
00072                                                                       
00073   inline friend BOOL operator==( const NUMBER& l, const NUMBER& r ) { 
00074     return   isEqualTo( l, r );                                       
00075   }                                                                   
00076                                                                       
00077   inline friend BOOL operator!=( const NUMBER& l, const NUMBER& r ) { 
00078     return  !isEqualTo( l, r );                                       
00079   }                                                                   
00080                                                                       
00081   inline friend BOOL operator<(  const NUMBER& l, const NUMBER& r ) { 
00082     return  isLessThan( l, r );                                       
00083   }                                                                   
00084                                                                       
00085   inline friend BOOL operator<=( const NUMBER& l, const NUMBER& r ) { 
00086     return  ( isLessThan( l, r ) || isEqualTo( l, r ) );              
00087   }                                                                   
00088                                                                       
00089   inline friend BOOL operator>(  const NUMBER& l, const NUMBER& r ) { 
00090     return  isBiggerThan( l, r );                                     
00091   }                                                                   
00092                                                                       
00093   inline friend BOOL operator>=( const NUMBER& l, const NUMBER& r ) { 
00094     return  ( isBiggerThan( l, r ) || isEqualTo( l, r ) );            
00095   }                                                                   
00096                                                                       
00097   // Arithmetic Operators: Part 1                                     
00098   friend NUMBER add( const NUMBER& l, const NUMBER& r ) {             
00099     MathState s = MathStateAdd[ (int)l.state ][ (int)r.state ];       
00100     return NUMBER( l.value + r.value, s );                            
00101   }                                                                   
00102                                                                       
00103   friend NUMBER sub( const NUMBER& l, const NUMBER& r ) {             
00104     MathState s = MathStateSub[ (int)l.state ][ (int)r.state ];       
00105     return NUMBER( l.value - r.value, s );                            
00106   }                                                                   
00107                                                                       
00108   friend NUMBER mult( const NUMBER& l, const NUMBER& r ) {            
00109     MathState s = MathStateMult[ (int)l.state ][ (int)r.state ];      
00110     return NUMBER( l.value * r.value, s );                            
00111   }                                                                   
00112                                                                       
00113   friend NUMBER div( const NUMBER& l, const NUMBER& r ) {             
00114     MathState s = MathStateDiv[ (int)l.state ][ (int)r.state ];       
00115     if ( s != Valid ) return NUMBER( l.value, s );                    
00116     return NUMBER( l.value / r.value, s );                            
00117   }                                                                   
00118                                                                       
00119   inline friend NUMBER operator+( const NUMBER& l, const NUMBER& r ) {
00120     return add( l, r );                                               
00121   }                                                                   
00122                                                                       
00123   inline friend NUMBER operator-( const NUMBER& l, const NUMBER& r ) {
00124     return sub( l, r );                                               
00125   }                                                                   
00126                                                                       
00127   inline friend NUMBER operator*( const NUMBER& l, const NUMBER& r ) {
00128     return mult( l, r );                                              
00129   }                                                                   
00130                                                                       
00131   inline friend NUMBER operator/( const NUMBER& l, const NUMBER& r ) {
00132     return div( l, r );                                               
00133   }                                                                   
00134                                                                       
00135   // Other Operators: Part 1                                          
00136   inline const NUMBER& operator=(const NUMBER& N ) {                  
00137     value = N.value;                                                 
00138     state = N.state;                                                
00139     return *this;                                                     
00140   }                                                                   
00141                                                                       
00142   inline NUMBER operator!() {                                         
00143     return NUMBER( (TYPE)!value, state );                                  
00144   }                                                                   
00145                                                                       
00146   inline NUMBER operator-() {                                         
00147     if ( (int)state < 4 ) return NUMBER( (TYPE)( -1 * value ), Valid );      
00148     return NUMBER( (TYPE)( -1 * value ), state );                            
00149   }                                                                   
00150                                                                       
00151   // (int) means post-increment/decrement                             
00152   inline NUMBER operator--() {                                        
00153     --value;                                                          
00154     return *this;                                                     
00155   }                                                                   
00156                                                                       
00157   inline NUMBER operator--( int ) {                                   
00158     value--;                                                          
00159     return *this;                                                     
00160   }                                                                   
00161                                                                       
00162   inline NUMBER operator++() {                                        
00163     ++value;                                                          
00164     return *this;                                                     
00165   }                                                                   
00166                                                                       
00167   inline NUMBER operator++( int ) {                                   
00168     value++;                                                          
00169     return *this;                                                     
00170   }                                                                   

Generated on Sun Oct 14 18:46:14 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001