Vaucanson  1.4.1
limits.hh
Go to the documentation of this file.
1 // limits.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_MISC_LIMITS_HH
18 # define VCSN_MISC_LIMITS_HH
19 
30 # include <vaucanson/config/math.hh>
31 
32 # ifdef USE_C_LIMITS
33 # include <climits>
34 # else
35 # include <limits>
36 # endif
37 
38 namespace vcsn
39 {
40  namespace misc
41  {
42  template<typename T>
43  struct limits
44 # ifndef USE_C_LIMITS
45  : std::numeric_limits<T>
46  { };
47 # else
48  {
49  static const bool is_specialized = false;
50  };
51 
52  template<>
53  struct limits<bool>
54  {
55  static const int digits = sizeof (bool)*8;
56  static const int digits10 = 1;
57  static const bool is_specialized = true;
58  static bool min () throw () { return false; }
59  static bool max () throw () { return false; }
60  static const bool has_infinity = false;
61  static bool infinity () throw () { return false; }
62  static const bool has_quiet_NaN = false;
63  static bool quiet_NaN () throw ()
64  { return static_cast<bool> (0); }
65  static const bool is_signed = false;
66  static const bool is_integer = true;
67  static const bool is_exact = true;
68  static const int radix = 2;
69  static const bool is_iec559 = true;
70  static const bool is_bounded = true;
71  static const bool is_modulo = true;
72  };
73 
74  template<>
75  struct limits<signed char>
76  {
77  static const int digits = sizeof (signed char)*8 - 1;
78  static const int digits10 = 3;
79  static const bool is_specialized = true;
80  static signed char min () throw () { return SCHAR_MIN; }
81  static signed char max () throw () { return SCHAR_MAX; }
82  static const bool is_signed = true;
83  static const bool is_integer = true;
84  static const bool is_exact = true;
85  static const int radix = 2;
86  static const bool has_infinity = false;
87  static signed char infinity () throw ()
88  { return static_cast<signed char> (0); }
89  static const bool has_quiet_NaN = false;
90  static signed char quiet_NaN () throw ()
91  { return static_cast<signed char> (0); }
92  static const bool is_iec559 = false;
93  static const bool is_bounded = true;
94  static const bool is_modulo = false;
95  };
96 
97  template<>
98  struct limits<unsigned char>
99  {
100  static const int digits = sizeof (unsigned char)*8;
101  static const int digits10 = 3;
102  static const bool is_specialized = true;
103  static unsigned char min () throw () { return 0; }
104  static unsigned char max () throw () { return UCHAR_MAX; }
105  static const bool is_signed = false;
106  static const bool is_integer = true;
107  static const bool is_exact = true;
108  static const int radix = 2;
109  static const bool has_infinity = false;
110  static unsigned char infinity () throw ()
111  { return static_cast<unsigned char> (0); }
112  static const bool has_quiet_NaN = false;
113  static unsigned char quiet_NaN () throw ()
114  { return static_cast<unsigned char> (0); }
115  static const bool is_iec559 = false;
116  static const bool is_bounded = true;
117  static const bool is_modulo = true;
118  };
119 
120  template<>
121  struct limits<int>
122  {
123  static const int digits = sizeof (int)*8 - 1;
124  static const int digits10 = 19;
125  static const bool is_specialized = true;
126  static int min () throw () { return INT_MIN; }
127  static int max () throw () { return INT_MAX; }
128  static const bool is_signed = true;
129  static const bool is_integer = true;
130  static const bool is_exact = true;
131  static const int radix = 2;
132  static const bool has_infinity = false;
133  static int infinity () throw ()
134  { return static_cast<int> (0); }
135  static const bool has_quiet_NaN = false;
136  static int quiet_NaN () throw ()
137  { return static_cast<int> (0); }
138  static const bool is_iec559 = true;
139  static const bool is_bounded = true;
140  static const bool is_modulo = false;
141  };
142 
143  template<>
144  struct limits<unsigned int>
145  {
146  static const int digits = sizeof (unsigned int)*8;
147  static const int digits10 = 19;
148  static const bool is_specialized = true;
149  static unsigned int min () throw () { return 0; }
150  static unsigned int max () throw () { return UINT_MAX; }
151  static const bool is_signed = false;
152  static const bool is_integer = true;
153  static const bool is_exact = true;
154  static const int radix = 2;
155  static const bool has_infinity = false;
156  static unsigned int infinity () throw ()
157  { return static_cast<unsigned int> (0); }
158  static const bool has_quiet_NaN = false;
159  static unsigned int quiet_NaN () throw ()
160  { return static_cast<unsigned int> (0); }
161  static const bool is_iec559 = true;
162  static const bool is_bounded = true;
163  static const bool is_modulo = true;
164  };
165 
166  template<>
167  struct limits<float>
168  {
169  static const int digits = sizeof (float)*8;
170  static const int digits10 = 33;
171  static const bool is_specialized = true;
172  static float min () throw () { return -HUGE_VAL; }
173  static float max () throw () { return HUGE_VAL; }
174  static const bool is_signed = true;
175  static const bool is_integer = false;
176  static const bool is_exact = false;
177  static const int radix = 2;
178  static const bool has_infinity = true;
179  static float infinity () throw ()
180  { return HUGE_VAL; }
181  static const bool has_quiet_NaN = true;
182  static float quiet_NaN () throw ()
183  { return NAN; }
184  static const bool is_iec559 = false;
185  static const bool is_bounded = false;
186  static const bool is_modulo = false;
187  };
188 
189  template<>
190  struct limits<double>
191  {
192  static const int digits = sizeof (float)*8;
193  static const int digits10 = 33;
194  static const bool is_specialized = true;
195  static float min () throw () { return -HUGE_VAL; }
196  static float max () throw () { return HUGE_VAL; }
197  static const bool is_signed = true;
198  static const bool is_integer = false;
199  static const bool is_exact = false;
200  static const int radix = 2;
201  static const bool has_infinity = true;
202  static float infinity () throw ()
203  { return HUGE_VAL; }
204  static const bool has_quiet_NaN = true;
205  static float quiet_NaN () throw ()
206  { return NAN; }
207  static const bool is_iec559 = false;
208  static const bool is_bounded = false;
209  static const bool is_modulo = false;
210  };
211 
212 # endif
213 
214  } // end of namespace misc.
215 } // end of namespace vcsn.
216 
217 
218 #endif // ! VCSN_MISC_LIMITS_HH