00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _double_h
00018 #define _double_h
00019
00020 #include <spl/Numeric.h>
00021 #include <spl/String.h>
00022
00029 #define DOUBLE_MAJIC 0x0014 //< Majic number for ASSERT's in Compare and Convert
00030 #define FLOAT_MAJIC 0x1000 //< Majic number for ASSERT's in Compare and Convert
00031
00035 class Double : public Numeric
00036 {
00037 private:
00038 double m_val;
00039
00040 public:
00041 Double();
00042 Double(const double d);
00043 Double(const Double& d);
00044 virtual ~Double();
00045
00046 virtual int32 HashCode() const;
00047
00048 virtual bool Equals(const IComparable *a) const;
00049 virtual int Compare(const IComparable *a) const;
00050 virtual bool Equals( const IComparable& a ) const;
00051 virtual int Compare( const IComparable& a ) const;
00052 virtual int32 MajicNumber() const;
00053
00054 virtual int ToInt() const;
00055 virtual double ToDouble() const;
00056 virtual StringPtr ToString() const;
00057
00058 inline operator double()
00059 {
00060 return m_val;
00061 }
00062
00063 #ifdef DEBUG
00064 virtual void ValidateMem() const;
00065 virtual void CheckMem() const;
00066 #endif
00067
00076 static float64 Parse(const char *cp, const int cplen);
00077
00085 inline static float64 Parse(const String& str) { return Parse(str.GetChars(), str.Length()); }
00086
00094 inline static float64 Parse(const String *str) { return Parse(str->GetChars(), str->Length()); }
00095
00103 static bool IsDouble(const char *cp, const int cplen);
00104
00111 inline static bool IsDouble(const String& str) { return IsDouble(str.GetChars(), str.Length()); }
00112
00119 inline static bool IsDouble(const String *str) { return IsDouble(str->GetChars(), str->Length()); }
00120
00128 inline static bool IsFloat(const char *cp, const int cplen) { return IsDouble(cp, cplen); }
00129
00136 inline static bool IsFloat(const String& str) { return IsDouble(str.GetChars(), str.Length()); }
00137
00144 inline static bool IsFloat(const String *str) { return IsDouble(str->GetChars(), str->Length()); }
00145
00152 static StringPtr ToString(float64 i);
00153
00160 inline static StringPtr ToString(float32 i) { return ToString((float64)i); }
00161
00168 static bool IsNaN(double d);
00169
00176 static bool IsPositiveZero(double d);
00177
00184 static bool IsNegativeZero(double d);
00185
00192 static double PositiveInfinity();
00193
00200 static double NegativeInfinity();
00201
00208 inline static bool IsPositiveInfinity(double d)
00209 {
00210 return d == PositiveInfinity();
00211 }
00212
00219 inline static bool IsNegativeInfinity(double d)
00220 {
00221 return d == NegativeInfinity();
00222 }
00223 };
00224
00225 REGISTER_TYPEOF( 562, Double );
00226
00229 #endif