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

C:/temp/src/j2k/Beta/Math/Float.hpp

Go to the documentation of this file.
00001 #ifndef __J2K__Float_HPP__
00002 #define __J2K__Float_HPP__
00003 
00004 #include <j2k/Fred/Number/MathStat.hpp>
00005 #include <j2k/Fred/Number/MCNumber.hpp>
00006 #include <stdlib.h>
00007 
00008 // Double definition
00009 
00010 class Float {
00011 //: public Object {
00012   public:
00013     inline Float() : value(0), status( Valid ) {
00014        verify();
00015     }
00016 
00017     inline Float(float v) : value(v), status( Valid ) { 
00018        verify();
00019     }
00020 
00021     inline Float(float v, enum MathState s) : value(v), status( s ) {
00022        verify();
00023     }
00024 
00025     inline Float(const char *s) {
00026       status = getState( s );
00027       value  = atof( s );
00028 
00029       if ( (int)status < 3 ) { // Change state, only if not Invalid
00030         verify();       
00031       }
00032     }
00033 
00034     Float(const Float& F)
00035       : value( F.value ), status( F.status ) { }
00036 
00037     inline virtual ~Float() { }
00038 
00039     friend ostream& operator<<(ostream& os, Float& F) {
00040       unsigned int state = (unsigned int)(F.status);
00041       if ( state < 3 ) {
00042         return os << F.value;
00043       } else if ( state < J2K_MAX_MathState ) {
00044         return os << MathStateTxt[ state ];
00045       }
00046 
00047       // Something weird occured, if this get executed !
00048       abort();  
00049       return os << "";
00050 
00051     }
00052 
00053     // operator overloads
00054 
00055     inline operator Float() const {
00056        return (Float)value;
00057     }
00058 
00059     friend Float operator<<(const Float& l, const Float& r);
00060     friend Float operator>>(const Float& l, const Float& r);
00061     friend Float operator|( const Float& l, const Float& r);
00062     friend Float operator&( const Float& l, const Float& r);
00063     friend Float operator^( const Float& l, const Float& r);
00064 
00065     inline Float operator~() {
00066       return Float( ~value );
00067     }
00068 
00069     // Use macro to define all possible choice
00070     // for arithmetic and compare functions
00071 
00072     MC_Number_Verify( Float, 0.0 )
00073     MC_Number_Operators1( Float, float )
00074     MC_Number_Operators2( Float, float, long   )
00075     MC_Number_Operators2( Float, float, float  )
00076     MC_Number_Operators2( Float, float, double )
00077     
00078 /*
00079     // Object methods
00080     Object *Copy() const;
00081 
00082     void Serialize(Serializer &) const;
00083     void Deserialize(Deserializer &);
00084 
00085     unsigned int hash() const;
00086     String toString() const;
00087 
00088     declareSerializable(Float);
00089   protected:
00090     bool Equals(const Object &o) const;
00091     bool lessThan(const Object &o) const;
00092     bool lessThanEquals(const Object &o) const;
00093 */
00094 
00095   private:
00096     Float value;
00097     enum MathState status;
00098 };
00099 
00100 inline Float operator<<(const Float& l,const Float& r) {
00101     return Float(l.value<<r.value);
00102 }
00103 
00104 inline Float operator>>(const Float& l,const Float& r) {
00105     return Float(l.value>>r.value);
00106 }
00107 
00108 inline Float operator|(const Float& l,const Float& r) {
00109     return Float(l.value|r.value);
00110 }
00111 
00112 inline Float operator&(const Float& l,const Float& r) {
00113     return Float(l.value&r.value);
00114 }
00115 
00116 inline Float operator^(const Float& l,const Float& r) {
00117     return Float(l.value^r.value);
00118 }
00119 
00120 #endif

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