limits.hh

Go to the documentation of this file.
00001 // limits.hh: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2001, 2002, 2003, 2004, 2005 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00016 //
00017 #ifndef VCSN_MISC_LIMITS_HH
00018 # define VCSN_MISC_LIMITS_HH
00019 
00030 # include <vaucanson/config/math.hh>
00031 
00032 # ifdef USE_C_LIMITS
00033 #  include <climits>
00034 # else
00035 #  include <limits>
00036 # endif
00037 
00038 namespace utility
00039 {
00040   template<typename T>
00041   struct limits
00042 # ifndef USE_C_LIMITS
00043     : std::numeric_limits<T>
00044   { };
00045 # else
00046   {
00047     static const bool is_specialized = false;
00048   };
00049 
00050   template<>
00051   struct limits<bool>
00052   {
00053     static const int digits = sizeof(bool)*8;
00054     static const int digits10 = 1;
00055     static const bool is_specialized = true;
00056     static bool min() throw() { return false; }
00057     static bool max() throw() { return false; }
00058     static const bool has_infinity = false;
00059     static bool infinity() throw() { return false; }
00060     static const bool has_quiet_NaN = false;
00061     static bool quiet_NaN() throw()
00062     { return static_cast<bool>(0); }
00063     static const bool is_signed = false;
00064     static const bool is_integer = true;
00065     static const bool is_exact = true;
00066     static const int radix = 2;
00067     static const bool is_iec559 = true;
00068     static const bool is_bounded = true;
00069     static const bool is_modulo = true;
00070   };
00071 
00072   template<>
00073   struct limits<signed char>
00074   {
00075     static const int digits = sizeof(signed char)*8 - 1;
00076     static const int digits10 = 3;
00077     static const bool is_specialized = true;
00078     static signed char min() throw()   { return SCHAR_MIN; }
00079     static signed char max() throw() { return SCHAR_MAX; }
00080     static const bool is_signed = true;
00081     static const bool is_integer = true;
00082     static const bool is_exact = true;
00083     static const int radix = 2;
00084     static const bool has_infinity = false;
00085     static signed char infinity() throw()
00086     { return static_cast<signed char>(0); }
00087     static const bool has_quiet_NaN = false;
00088     static signed char quiet_NaN() throw()
00089     { return static_cast<signed char>(0); }
00090     static const bool is_iec559 = false;
00091     static const bool is_bounded = true;
00092     static const bool is_modulo = false;
00093   };
00094 
00095   template<>
00096   struct limits<unsigned char>
00097   {
00098     static const int digits = sizeof(unsigned char)*8;
00099     static const int digits10 = 3;
00100     static const bool is_specialized = true;
00101     static unsigned char min() throw()   { return 0; }
00102     static unsigned char max() throw() { return UCHAR_MAX; }
00103     static const bool is_signed = false;
00104     static const bool is_integer = true;
00105     static const bool is_exact = true;
00106     static const int radix = 2;
00107     static const bool has_infinity = false;
00108     static unsigned char infinity() throw()
00109     { return static_cast<unsigned char>(0); }
00110     static const bool has_quiet_NaN = false;
00111     static unsigned char quiet_NaN() throw()
00112     { return static_cast<unsigned char>(0); }
00113     static const bool is_iec559 = false;
00114     static const bool is_bounded = true;
00115     static const bool is_modulo = true;
00116   };
00117 
00118   template<>
00119   struct limits<int>
00120   {
00121     static const int digits = sizeof(int)*8 - 1;
00122     static const int digits10 = 19;
00123     static const bool is_specialized = true;
00124     static int min() throw()   { return INT_MIN; }
00125     static int max() throw() { return INT_MAX; }
00126     static const bool is_signed = true;
00127     static const bool is_integer = true;
00128     static const bool is_exact = true;
00129     static const int radix = 2;
00130     static const bool has_infinity = false;
00131     static int infinity() throw()
00132     { return static_cast<int>(0); }
00133     static const bool has_quiet_NaN = false;
00134     static int quiet_NaN() throw()
00135     { return static_cast<int>(0); }
00136     static const bool is_iec559 = true;
00137     static const bool is_bounded = true;
00138     static const bool is_modulo = false;
00139   };
00140 
00141   template<>
00142   struct limits<unsigned int>
00143   {
00144     static const int digits = sizeof(unsigned int)*8;
00145     static const int digits10 = 19;
00146     static const bool is_specialized = true;
00147     static unsigned int min() throw()   { return 0; }
00148     static unsigned int max() throw() { return UINT_MAX; }
00149     static const bool is_signed = false;
00150     static const bool is_integer = true;
00151     static const bool is_exact = true;
00152     static const int radix = 2;
00153     static const bool has_infinity = false;
00154     static unsigned int infinity() throw()
00155     { return static_cast<unsigned int>(0); }
00156     static const bool has_quiet_NaN = false;
00157     static unsigned int quiet_NaN() throw()
00158     { return static_cast<unsigned int>(0); }
00159     static const bool is_iec559 = true;
00160     static const bool is_bounded = true;
00161     static const bool is_modulo = true;
00162   };
00163 
00164   template<>
00165   struct limits<float>
00166   {
00167     static const int digits = sizeof(float)*8;
00168     static const int digits10 = 33;
00169     static const bool is_specialized = true;
00170     static float min() throw()   { return -HUGE_VAL; }
00171     static float max() throw() { return HUGE_VAL; }
00172     static const bool is_signed = true;
00173     static const bool is_integer = false;
00174     static const bool is_exact = false;
00175     static const int radix = 2;
00176     static const bool has_infinity = true;
00177     static float infinity() throw()
00178     { return HUGE_VAL; }
00179     static const bool has_quiet_NaN = true;
00180     static float quiet_NaN() throw()
00181     { return NAN; }
00182     static const bool is_iec559 = false;
00183     static const bool is_bounded = false;
00184     static const bool is_modulo = false;
00185   };
00186 
00187   template<>
00188   struct limits<double>
00189   {
00190     static const int digits = sizeof(float)*8;
00191     static const int digits10 = 33;
00192     static const bool is_specialized = true;
00193     static float min() throw()   { return -HUGE_VAL; }
00194     static float max() throw() { return HUGE_VAL; }
00195     static const bool is_signed = true;
00196     static const bool is_integer = false;
00197     static const bool is_exact = false;
00198     static const int radix = 2;
00199     static const bool has_infinity = true;
00200     static float infinity() throw()
00201     { return HUGE_VAL; }
00202     static const bool has_quiet_NaN = true;
00203     static float quiet_NaN() throw()
00204     { return NAN; }
00205     static const bool is_iec559 = false;
00206     static const bool is_bounded = false;
00207     static const bool is_modulo = false;
00208   };
00209 
00210 # endif
00211 
00212 }
00213 
00214 
00215 #endif // ! VCSN_MISC_LIMITS_HH

Generated on Fri Jul 28 12:18:48 2006 for Vaucanson by  doxygen 1.4.6