• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/Double.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
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