source: XMLIO_V2/external/include/blitz/limits-hack.h @ 73

Last change on this file since 73 was 73, checked in by ymipsl, 14 years ago
  • Property svn:eol-style set to native
File size: 13.8 KB
Line 
1/*
2 * Copyright (c) 1997
3 * Silicon Graphics Computer Systems, Inc.
4 *
5 * Permission to use, copy, modify, distribute and sell this software
6 * and its documentation for any purpose is hereby granted without fee,
7 * provided that the above copyright notice appear in all copies and
8 * that both that copyright notice and this permission notice appear
9 * in supporting documentation.  Silicon Graphics makes no
10 * representations about the suitability of this software for any
11 * purpose.  It is provided "as is" without express or implied warranty.
12 */
13
14/* NOTE: This is not portable code.  Parts of numeric_limits<> are
15 * inherently machine-dependent, and this file is written for the MIPS
16 * architecture and the SGI MIPSpro C++ compiler.  Parts of it (in
17 * particular, some of the characteristics of floating-point types)
18 * are almost certainly incorrect for any other platform.
19 */
20
21#include <blitz/wrap-climits.h>
22#include <float.h>
23
24BZ_NAMESPACE(std)
25
26enum float_round_style {
27  round_indeterminate       = -1,
28  round_toward_zero         =  0,
29  round_to_nearest          =  1,
30  round_toward_infinity     =  2,
31  round_toward_neg_infinity =  3
32};
33
34enum float_denorm_style {
35  denorm_indeterminate = -1,
36  denorm_absent        =  0,
37  denorm_present       =  1
38};
39
40// Base class for all specializations of numeric_limits.
41
42template <typename __number>
43class _Numeric_limits_base {
44public:
45  static const bool is_specialized = false;
46
47  static __number min()  { return __number(); }
48  static __number max()  { return __number(); }
49
50  static const int digits   = 0;
51  static const int digits10 = 0;
52
53  static const bool is_signed  = false;
54  static const bool is_integer = false;
55  static const bool is_exact   = false;
56
57  static const int radix = 0;
58
59  static __number epsilon()      { return __number(); }
60  static __number round_error()  { return __number(); }
61
62  static const int min_exponent   = 0;
63  static const int min_exponent10 = 0;
64  static const int max_exponent   = 0;
65  static const int max_exponent10 = 0;
66
67  static const bool has_infinity      = false;
68  static const bool has_quiet_NaN     = false;
69  static const bool has_signaling_NaN = false;
70  static const float_denorm_style has_denorm = denorm_absent;
71  static const bool has_denorm_loss   = false;
72
73  static __number infinity()       { return __number(); }
74  static __number quiet_NaN()      { return __number(); }
75  static __number signaling_NaN()  { return __number(); }
76  static __number denorm_min()     { return __number(); }
77
78  static const bool is_iec559  = false;
79  static const bool is_bounded = false;
80  static const bool is_modulo  = false;
81
82  static const bool traps           = false;
83  static const bool tinyness_before = false;
84  static const float_round_style round_style = round_toward_zero;
85};
86
87#define __declare_numeric_base_member(__type, __mem) \
88template <typename __number> \
89  const __type _Numeric_limits_base<__number>:: __mem
90
91__declare_numeric_base_member(bool, is_specialized);
92__declare_numeric_base_member(int, digits);
93__declare_numeric_base_member(int, digits10);
94__declare_numeric_base_member(bool, is_signed);
95__declare_numeric_base_member(bool, is_integer);
96__declare_numeric_base_member(bool, is_exact);
97__declare_numeric_base_member(int, radix);
98__declare_numeric_base_member(int, min_exponent);
99__declare_numeric_base_member(int, max_exponent);
100__declare_numeric_base_member(int, min_exponent10);
101__declare_numeric_base_member(int, max_exponent10);
102__declare_numeric_base_member(bool, has_infinity);
103__declare_numeric_base_member(bool, has_quiet_NaN);
104__declare_numeric_base_member(bool, has_signaling_NaN);
105__declare_numeric_base_member(float_denorm_style, has_denorm);
106__declare_numeric_base_member(bool, has_denorm_loss);
107__declare_numeric_base_member(bool, is_iec559);
108__declare_numeric_base_member(bool, is_bounded);
109__declare_numeric_base_member(bool, is_modulo);
110__declare_numeric_base_member(bool, traps);
111__declare_numeric_base_member(bool, tinyness_before);
112__declare_numeric_base_member(float_round_style, round_style);
113
114#undef __declare_numeric_base_member
115
116// Base class for integers.
117
118template <typename _Int,
119          _Int __imin,
120          _Int __imax,
121          int __idigits = -1>
122class _Integer_limits : public _Numeric_limits_base<_Int> {
123public:
124  static const bool is_specialized = true;
125
126  static _Int min()  { return __imin; }
127  static _Int max()  { return __imax; }
128
129  static const int digits = 
130    (__idigits < 0) ? sizeof(_Int) * CHAR_BIT - (__imin == 0 ? 0 : 1) 
131                    : __idigits;
132  static const int digits10 = (digits * 301) / 1000; 
133                                // log 2 = 0.301029995664...
134
135  static const bool is_signed = __imin != 0;
136  static const bool is_integer = true;
137  static const bool is_exact = true;
138  static const int radix = 2;
139
140
141  static const bool is_bounded = true;
142  static const bool is_modulo = true;
143};
144
145#define __declare_integer_limits_member(__type, __mem) \
146template <typename _Int, _Int __imin, _Int __imax, int __idigits> \
147  const __type _Integer_limits<_Int, __imin, __imax, __idigits>:: __mem
148
149__declare_integer_limits_member(bool, is_specialized);
150__declare_integer_limits_member(int, digits);
151__declare_integer_limits_member(int, digits10);
152__declare_integer_limits_member(bool, is_signed);
153__declare_integer_limits_member(bool, is_integer);
154__declare_integer_limits_member(bool, is_exact);
155__declare_integer_limits_member(int, radix);
156__declare_integer_limits_member(bool, is_bounded);
157__declare_integer_limits_member(bool, is_modulo);
158
159#undef __declare_integer_limits_member
160
161// Base class for floating-point numbers.
162template <typename __number,
163         int __Digits, int __Digits10,
164         int __MinExp, int __MaxExp,
165         int __MinExp10, int __MaxExp10,
166         unsigned int __InfinityWord,
167         unsigned int __QNaNWord, unsigned int __SNaNWord,
168         bool __IsIEC559,
169         float_round_style __RoundStyle>
170class _Floating_limits : public _Numeric_limits_base<__number>
171{
172public:
173  static const bool is_specialized = true;
174
175  static const int digits   = __Digits;
176  static const int digits10 = __Digits10;
177
178  static const bool is_signed = true;
179
180  static const int radix = 2;
181
182  static const int min_exponent   = __MinExp;
183  static const int max_exponent   = __MaxExp;
184  static const int min_exponent10 = __MinExp10;
185  static const int max_exponent10 = __MaxExp10;
186
187  static const bool has_infinity      = true;
188  static const bool has_quiet_NaN     = true;
189  static const bool has_signaling_NaN = true;
190  static const float_denorm_style has_denorm = denorm_indeterminate;
191  static const bool has_denorm_loss   = false;
192
193  static __number infinity()  {
194    static unsigned int _S_inf[sizeof(__number) / sizeof(int)] = 
195      { __InfinityWord };
196    return *reinterpret_cast<__number*>(&_S_inf);
197  }
198  static __number quiet_NaN()  {
199    static unsigned int _S_nan[sizeof(__number) / sizeof(int)] = 
200      { __QNaNWord };
201    return *reinterpret_cast<__number*>(&_S_nan);
202  }
203  static __number signaling_NaN()  {
204    static unsigned int _S_nan[sizeof(__number) / sizeof(int)] = 
205      { __SNaNWord };
206    return *reinterpret_cast<__number*>(&_S_nan);
207  }
208
209  static const bool is_iec559       = __IsIEC559;
210  static const bool is_bounded      = true;
211  static const bool traps           = true;
212  static const bool tinyness_before = false;
213
214  static const float_round_style round_style = __RoundStyle;
215};
216
217#define __declare_float_limits_member(__type, __mem) \
218template <typename __Num, int __Dig, int __Dig10, \
219          int __MnX, int __MxX, int __MnX10, int __MxX10, \
220          unsigned int __Inf, unsigned int __QNaN, unsigned int __SNaN, \
221          bool __IsIEEE, float_round_style __Sty> \
222const __type _Floating_limits<__Num, __Dig, __Dig10, \
223                              __MnX, __MxX, __MnX10, __MxX10, \
224                              __Inf, __QNaN, __SNaN,__IsIEEE, __Sty>:: __mem
225
226__declare_float_limits_member(bool, is_specialized); 
227__declare_float_limits_member(int, digits); 
228__declare_float_limits_member(int, digits10); 
229__declare_float_limits_member(bool, is_signed); 
230__declare_float_limits_member(int, radix); 
231__declare_float_limits_member(int, min_exponent); 
232__declare_float_limits_member(int, max_exponent); 
233__declare_float_limits_member(int, min_exponent10); 
234__declare_float_limits_member(int, max_exponent10); 
235__declare_float_limits_member(bool, has_infinity);
236__declare_float_limits_member(bool, has_quiet_NaN);
237__declare_float_limits_member(bool, has_signaling_NaN);
238__declare_float_limits_member(float_denorm_style, has_denorm);
239__declare_float_limits_member(bool, has_denorm_loss);
240__declare_float_limits_member(bool, is_iec559);
241__declare_float_limits_member(bool, is_bounded);
242__declare_float_limits_member(bool, traps);
243__declare_float_limits_member(bool, tinyness_before);
244__declare_float_limits_member(float_round_style, round_style);
245
246#undef __declare_float_limits_member
247
248// Class numeric_limits
249
250// The unspecialized class.
251
252template<typename T> 
253class numeric_limits : public _Numeric_limits_base<T> {};
254
255// Specializations for all built-in integral types.
256
257#ifndef __STL_NO_BOOL
258
259template<>
260class numeric_limits<bool>
261  : public _Integer_limits<bool, false, true, 0> {};
262
263#endif /* __STL_NO_BOOL */
264
265template<>
266class numeric_limits<char>
267  : public _Integer_limits<char, CHAR_MIN, CHAR_MAX> {};
268
269template<>
270class numeric_limits<signed char>
271  : public _Integer_limits<signed char, SCHAR_MIN, SCHAR_MAX> {};
272
273template<>
274class numeric_limits<unsigned char>
275  : public _Integer_limits<unsigned char, 0, UCHAR_MAX> {};
276
277#ifdef __STL_HAS_WCHAR_T
278
279template<>
280class numeric_limits<wchar_t>
281  : public _Integer_limits<wchar_t, INT_MIN, INT_MAX> {};
282
283#endif
284
285template<>
286class numeric_limits<short>
287  : public _Integer_limits<short, SHRT_MIN, SHRT_MAX> {};
288
289template<>
290class numeric_limits<unsigned short>
291  : public _Integer_limits<unsigned short, 0, USHRT_MAX> {};
292
293template<>
294class numeric_limits<int>
295  : public _Integer_limits<int, INT_MIN, INT_MAX> {};
296
297template<>
298class numeric_limits<unsigned int>
299  : public _Integer_limits<unsigned int, 0, UINT_MAX> {};
300
301template<>
302class numeric_limits<long>
303  : public _Integer_limits<long, LONG_MIN, LONG_MAX> {};
304
305template<>
306class numeric_limits<unsigned long>
307  : public _Integer_limits<unsigned long, 0, ULONG_MAX> {};
308
309#ifdef __STL_LONG_LONG
310#ifdef LONG_LONG_MIN
311
312// CYGNUS LOCAL 9/4/1998
313// fixed LONGLONG to be LONG_LONG
314template<>
315class numeric_limits<long long>
316  : public _Integer_limits<long long, LONG_LONG_MIN, LONG_LONG_MAX> {};
317
318// CYGNUS LOCAL 9/4/1998
319// fixed LONGLONG to be LONG_LONG
320template<>
321class numeric_limits<unsigned long long>
322  : public _Integer_limits<unsigned long long, 0, ULONG_LONG_MAX> {};
323
324#endif
325#endif /* __STL_LONG_LONG */
326
327// Specializations for all built-in floating-point type.
328
329template<> class numeric_limits<float>
330  : public _Floating_limits<float, 
331                            FLT_MANT_DIG,   // Binary digits of precision
332                            FLT_DIG,        // Decimal digits of precision
333                            FLT_MIN_EXP,    // Minimum exponent
334                            FLT_MAX_EXP,    // Maximum exponent
335                            FLT_MIN_10_EXP, // Minimum base 10 exponent
336                            FLT_MAX_10_EXP, // Maximum base 10 exponent
337                            0x7f800000u,    // First word of +infinity
338                            0x7f810000u,    // First word of quiet NaN
339                            0x7fc10000u,    // First word of signaling NaN
340                            true,           // conforms to iec559
341                            round_to_nearest>
342{
343public:
344  static float min()  { return FLT_MIN; }
345  static float denorm_min()  { return FLT_MIN; }
346  static float max()  { return FLT_MAX; }
347  static float epsilon()  { return FLT_EPSILON; }
348  static float round_error()  { return 0.5f; } // Units: ulps.
349};
350
351template<> class numeric_limits<double>
352  : public _Floating_limits<double, 
353                            DBL_MANT_DIG,   // Binary digits of precision
354                            DBL_DIG,        // Decimal digits of precision
355                            DBL_MIN_EXP,    // Minimum exponent
356                            DBL_MAX_EXP,    // Maximum exponent
357                            DBL_MIN_10_EXP, // Minimum base 10 exponent
358                            DBL_MAX_10_EXP, // Maximum base 10 exponent
359                            0x7ff00000u,    // First word of +infinity
360                            0x7ff10000u,    // First word of quiet NaN
361                            0x7ff90000u,    // First word of signaling NaN
362                            true,           // conforms to iec559
363                            round_to_nearest>
364{
365public:
366  static double min()  { return DBL_MIN; }
367  static double denorm_min()  { return DBL_MIN; }
368  static double max()  { return DBL_MAX; }
369  static double epsilon()  { return DBL_EPSILON; }
370  static double round_error()  { return 0.5; } // Units: ulps.
371};
372
373template<> class numeric_limits<long double>
374  : public _Floating_limits<long double, 
375                            LDBL_MANT_DIG,  // Binary digits of precision
376                            LDBL_DIG,       // Decimal digits of precision
377                            LDBL_MIN_EXP,   // Minimum exponent
378                            LDBL_MAX_EXP,   // Maximum exponent
379                            LDBL_MIN_10_EXP,// Minimum base 10 exponent
380                            LDBL_MAX_10_EXP,// Maximum base 10 exponent
381                            0x7ff00000u,    // First word of +infinity
382                            0x7ff10000u,    // First word of quiet NaN
383                            0x7ff90000u,    // First word of signaling NaN
384                            false,          // Doesn't conform to iec559
385                            round_to_nearest>
386{
387public:
388  static long double min()  { return LDBL_MIN; }
389  static long double denorm_min()  { return LDBL_MIN; }
390  static long double max()  { return LDBL_MAX; }
391  static long double epsilon()  { return LDBL_EPSILON; }
392  static long double round_error()  { return 4; } // Units: ulps.
393};
394
395BZ_NAMESPACE_END
396
Note: See TracBrowser for help on using the repository browser.