- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# 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, 2006 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 vcsn
    00039 {
    00040   namespace misc
    00041   {
    00042     template<typename T>
    00043     struct limits
    00044 # ifndef USE_C_LIMITS
    00045       : std::numeric_limits<T>
    00046     { };
    00047 # else
    00048     {
    00049       static const bool is_specialized = false;
    00050     };
    00051
    00052     template<>
    00053     struct limits<bool>
    00054     {
    00055         static const int digits = sizeof (bool)*8;
    00056         static const int digits10 = 1;
    00057         static const bool is_specialized = true;
    00058         static bool min () throw () { return false; }
    00059         static bool max () throw () { return false; }
    00060         static const bool has_infinity = false;
    00061         static bool infinity () throw () { return false; }
    00062         static const bool has_quiet_NaN = false;
    00063         static bool quiet_NaN () throw ()
    00064         { return static_cast<bool> (0); }
    00065         static const bool is_signed = false;
    00066         static const bool is_integer = true;
    00067         static const bool is_exact = true;
    00068         static const int radix = 2;
    00069         static const bool is_iec559 = true;
    00070         static const bool is_bounded = true;
    00071         static const bool is_modulo = true;
    00072     };
    00073
    00074     template<>
    00075     struct limits<signed char>
    00076     {
    00077         static const int digits = sizeof (signed char)*8 - 1;
    00078         static const int digits10 = 3;
    00079         static const bool is_specialized = true;
    00080         static signed char min () throw ()   { return SCHAR_MIN; }
    00081         static signed char max () throw () { return SCHAR_MAX; }
    00082         static const bool is_signed = true;
    00083         static const bool is_integer = true;
    00084         static const bool is_exact = true;
    00085         static const int radix = 2;
    00086         static const bool has_infinity = false;
    00087         static signed char infinity () throw ()
    00088         { return static_cast<signed char> (0); }
    00089         static const bool has_quiet_NaN = false;
    00090         static signed char quiet_NaN () throw ()
    00091         { return static_cast<signed char> (0); }
    00092         static const bool is_iec559 = false;
    00093         static const bool is_bounded = true;
    00094         static const bool is_modulo = false;
    00095     };
    00096
    00097     template<>
    00098     struct limits<unsigned char>
    00099     {
    00100         static const int digits = sizeof (unsigned char)*8;
    00101         static const int digits10 = 3;
    00102         static const bool is_specialized = true;
    00103         static unsigned char min () throw ()   { return 0; }
    00104         static unsigned char max () throw () { return UCHAR_MAX; }
    00105         static const bool is_signed = false;
    00106         static const bool is_integer = true;
    00107         static const bool is_exact = true;
    00108         static const int radix = 2;
    00109         static const bool has_infinity = false;
    00110         static unsigned char infinity () throw ()
    00111         { return static_cast<unsigned char> (0); }
    00112         static const bool has_quiet_NaN = false;
    00113         static unsigned char quiet_NaN () throw ()
    00114         { return static_cast<unsigned char> (0); }
    00115         static const bool is_iec559 = false;
    00116         static const bool is_bounded = true;
    00117         static const bool is_modulo = true;
    00118     };
    00119
    00120     template<>
    00121     struct limits<int>
    00122     {
    00123         static const int digits = sizeof (int)*8 - 1;
    00124         static const int digits10 = 19;
    00125         static const bool is_specialized = true;
    00126         static int min () throw ()   { return INT_MIN; }
    00127         static int max () throw () { return INT_MAX; }
    00128         static const bool is_signed = true;
    00129         static const bool is_integer = true;
    00130         static const bool is_exact = true;
    00131         static const int radix = 2;
    00132         static const bool has_infinity = false;
    00133         static int infinity () throw ()
    00134         { return static_cast<int> (0); }
    00135         static const bool has_quiet_NaN = false;
    00136         static int quiet_NaN () throw ()
    00137         { return static_cast<int> (0); }
    00138         static const bool is_iec559 = true;
    00139         static const bool is_bounded = true;
    00140         static const bool is_modulo = false;
    00141     };
    00142
    00143     template<>
    00144     struct limits<unsigned int>
    00145     {
    00146         static const int digits = sizeof (unsigned int)*8;
    00147         static const int digits10 = 19;
    00148         static const bool is_specialized = true;
    00149         static unsigned int min () throw ()   { return 0; }
    00150         static unsigned int max () throw () { return UINT_MAX; }
    00151         static const bool is_signed = false;
    00152         static const bool is_integer = true;
    00153         static const bool is_exact = true;
    00154         static const int radix = 2;
    00155         static const bool has_infinity = false;
    00156         static unsigned int infinity () throw ()
    00157         { return static_cast<unsigned int> (0); }
    00158         static const bool has_quiet_NaN = false;
    00159         static unsigned int quiet_NaN () throw ()
    00160         { return static_cast<unsigned int> (0); }
    00161         static const bool is_iec559 = true;
    00162         static const bool is_bounded = true;
    00163         static const bool is_modulo = true;
    00164     };
    00165
    00166     template<>
    00167     struct limits<float>
    00168     {
    00169         static const int digits = sizeof (float)*8;
    00170         static const int digits10 = 33;
    00171         static const bool is_specialized = true;
    00172         static float min () throw ()   { return -HUGE_VAL; }
    00173         static float max () throw () { return HUGE_VAL; }
    00174         static const bool is_signed = true;
    00175         static const bool is_integer = false;
    00176         static const bool is_exact = false;
    00177         static const int radix = 2;
    00178         static const bool has_infinity = true;
    00179         static float infinity () throw ()
    00180         { return HUGE_VAL; }
    00181         static const bool has_quiet_NaN = true;
    00182         static float quiet_NaN () throw ()
    00183         { return NAN; }
    00184         static const bool is_iec559 = false;
    00185         static const bool is_bounded = false;
    00186         static const bool is_modulo = false;
    00187     };
    00188
    00189     template<>
    00190     struct limits<double>
    00191     {
    00192         static const int digits = sizeof (float)*8;
    00193         static const int digits10 = 33;
    00194         static const bool is_specialized = true;
    00195         static float min () throw ()   { return -HUGE_VAL; }
    00196         static float max () throw () { return HUGE_VAL; }
    00197         static const bool is_signed = true;
    00198         static const bool is_integer = false;
    00199         static const bool is_exact = false;
    00200         static const int radix = 2;
    00201         static const bool has_infinity = true;
    00202         static float infinity () throw ()
    00203         { return HUGE_VAL; }
    00204         static const bool has_quiet_NaN = true;
    00205         static float quiet_NaN () throw ()
    00206         { return NAN; }
    00207         static const bool is_iec559 = false;
    00208         static const bool is_bounded = false;
    00209         static const bool is_modulo = false;
    00210     };
    00211
    00212 # endif
    00213
    00214   } // end of namespace misc.
    00215 } // end of namespace vcsn.
    00216
    00217
    00218 #endif // ! VCSN_MISC_LIMITS_HH