00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _DECAF_LANG_FLOAT_H_
00019 #define _DECAF_LANG_FLOAT_H_
00020
00021 #include <decaf/util/Config.h>
00022 #include <decaf/lang/Number.h>
00023 #include <decaf/lang/Comparable.h>
00024 #include <decaf/lang/exceptions/NumberFormatException.h>
00025 #include <string>
00026
00027 namespace decaf{
00028 namespace lang{
00029
00030 class DECAF_API Float : public Number,
00031 public Comparable<Float>,
00032 public Comparable<float> {
00033 private:
00034
00035 float value;
00036
00037 public:
00038
00040 static const int SIZE;
00041
00043 static const float MAX_VALUE;
00044
00046 static const float MIN_VALUE;
00047
00049 static const float NaN;
00050
00052 static const float POSITIVE_INFINITY;
00053
00055 static const float NEGATIVE_INFINITY;
00056
00057 public:
00058
00062 Float( float value );
00063
00067 Float( double value );
00068
00072 Float( const std::string& value );
00073
00074 virtual ~Float() {}
00075
00084 virtual int compareTo( const Float& f ) const;
00085
00090 bool equals( const Float& f ) const {
00091 return this->value == f.value;
00092 }
00093
00099 virtual bool operator==( const Float& f ) const {
00100 return this->value == f.value;
00101 }
00102
00109 virtual bool operator<( const Float& f ) const {
00110 return this->value < f.value;
00111 }
00112
00121 virtual int compareTo( const float& f ) const;
00122
00127 bool equals( const float& f ) const {
00128 return this->value == f;
00129 }
00130
00136 virtual bool operator==( const float& f ) const {
00137 return this->value == f;
00138 }
00139
00146 virtual bool operator<( const float& f ) const {
00147 return this->value < f;
00148 }
00149
00153 std::string toString() const;
00154
00159 virtual double doubleValue() const {
00160 return (double)this->value;
00161 }
00162
00167 virtual float floatValue() const {
00168 return this->value;
00169 }
00170
00175 virtual unsigned char byteValue() const {
00176 return (unsigned char)this->value;
00177 }
00178
00183 virtual short shortValue() const {
00184 return (short)this->value;
00185 }
00186
00191 virtual int intValue() const {
00192 return (int)this->value;
00193 }
00194
00199 virtual long long longValue() const {
00200 return (long long)this->value;
00201 }
00202
00206 bool isInfinite() const;
00207
00211 bool isNaN() const;
00212
00213 public:
00214
00225 static int compare( float f1, float f2 );
00226
00248 static int floatToIntBits( float value );
00249
00275 static int floatToRawIntBits( float value );
00276
00294 static float intBitsToFloat( int bits );
00295
00300 static bool isInfinite( float value );
00301
00306 static bool isNaN( float value );
00307
00315 static float parseFloat( const std::string& value );
00316
00351 static std::string toHexString( float value );
00352
00384 static std::string toString( float value );
00385
00391 static Float valueOf( float value );
00392
00401 static Float valueOf( const std::string& value );
00402
00403 private:
00404
00405 static const unsigned int SINGLE_EXPONENT_MASK = 0x7F800000;
00406 static const unsigned int SINGLE_MANTISSA_MASK = 0x007FFFFF;
00407 static const unsigned int SINGLE_NAN_BITS = (SINGLE_EXPONENT_MASK | 0x00400000);
00408
00409 };
00410
00411 }}
00412
00413 #endif