3
* Silicon Graphics Computer Systems, Inc.
8
* This material is provided "as is", with absolutely no warranty expressed
9
* or implied. Any use is at your own risk.
11
* Permission to use or copy this software for any purpose is hereby granted
12
* without fee, provided the above notices are retained on all copies.
13
* Permission to modify the code and to distribute modified code is granted,
14
* provided the above notices are retained, and a notice that the code was
15
* modified is included with the above copyright notice.
19
/* NOTE: This may be not portable code. Parts of numeric_limits<> are
20
* inherently machine-dependent. At present this file is suitable
21
* for the MIPS, SPARC, Alpha and ia32 architectures.
24
#ifndef _STLP_INTERNAL_LIMITS_H
25
# define _STLP_INTERNAL_LIMITS_H
35
#if !defined (_STLP_NO_WCHAR_T) && !defined (_STLP_CWCHAR_H)
36
# include <stl/_cwchar.h>
41
enum float_round_style {
42
round_indeterminate = -1,
43
round_toward_zero = 0,
45
round_toward_infinity = 2,
46
round_toward_neg_infinity = 3
49
enum float_denorm_style {
50
denorm_indeterminate = -1,
55
// Base class for all specializations of numeric_limits.
57
template <class __number>
58
class _Numeric_limits_base {
61
static __number (_STLP_CALL min)() _STLP_NOTHROW { return __number(); }
62
static __number (_STLP_CALL max)() _STLP_NOTHROW { return __number(); }
64
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
78
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
80
has_denorm = denorm_absent,
81
round_style = round_toward_zero,
84
static const float_denorm_style has_denorm = denorm_absent;
85
static const float_round_style round_style = round_toward_zero;
89
is_specialized = false,
94
has_quiet_NaN = false,
95
has_signaling_NaN = false,
96
has_denorm_loss = false,
101
tinyness_before = false
102
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
107
static __number _STLP_CALL epsilon() _STLP_NOTHROW { return __number(); }
108
static __number _STLP_CALL round_error() _STLP_NOTHROW { return __number(); }
110
static __number _STLP_CALL infinity() _STLP_NOTHROW { return __number(); }
111
static __number _STLP_CALL quiet_NaN() _STLP_NOTHROW { return __number(); }
112
static __number _STLP_CALL signaling_NaN() _STLP_NOTHROW { return __number(); }
113
static __number _STLP_CALL denorm_min() _STLP_NOTHROW { return __number(); }
118
// Base class for integers.
120
# ifdef _STLP_LIMITED_DEFAULT_TEMPLATES
121
# ifdef _STLP_LONG_LONG
122
# define _STLP_LIMITS_MIN_TYPE _STLP_LONG_LONG
123
# define _STLP_LIMITS_MAX_TYPE unsigned _STLP_LONG_LONG
125
# define _STLP_LIMITS_MIN_TYPE long
126
# define _STLP_LIMITS_MAX_TYPE unsigned long
129
# define _STLP_LIMITS_MIN_TYPE _Int
130
# define _STLP_LIMITS_MAX_TYPE _Int
131
# endif /* _STLP_LIMITED_DEFAULT_TEMPLATES */
133
template <class _Int,
134
_STLP_LIMITS_MIN_TYPE __imin,
135
_STLP_LIMITS_MAX_TYPE __imax,
136
int __idigits, bool __ismod>
137
class _Integer_limits : public _Numeric_limits_base<_Int>
141
static _Int (_STLP_CALL min) () _STLP_NOTHROW { return (_Int)__imin; }
142
static _Int (_STLP_CALL max) () _STLP_NOTHROW { return (_Int)__imax; }
144
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
149
digits = (__idigits < 0) ?
150
((int)((sizeof(_Int) * (CHAR_BIT))) - ((__imin == 0) ? 0 : 1))
152
digits10 = (digits * 301UL) / 1000,
154
# if ! defined ( _STLP_STATIC_CONST_INIT_BUG)
160
is_specialized = true,
161
is_signed = (__imin != 0),
166
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
172
// Base class for floating-point numbers.
173
template <class __number,
174
int __Digits, int __Digits10,
175
int __MinExp, int __MaxExp,
176
int __MinExp10, int __MaxExp10,
178
float_round_style __RoundStyle>
179
class _Floating_limits : public _Numeric_limits_base<__number>
183
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
190
digits10 = __Digits10,
192
radix = ( FLT_RADIX /* 2 */ ),
193
min_exponent = __MinExp,
194
max_exponent = __MaxExp,
195
min_exponent10 = __MinExp10,
196
max_exponent10 = __MaxExp10
198
# if defined (_STLP_STATIC_CONST_INIT_BUG)
200
has_denorm = denorm_indeterminate,
201
round_style = __RoundStyle,
204
static const float_denorm_style has_denorm = denorm_indeterminate;
205
static const float_round_style round_style = __RoundStyle;
209
is_specialized = true,
212
#if (!defined(_CRAY) || !defined(_CRAYIEEE))
214
has_quiet_NaN = true,
215
has_signaling_NaN= true,
217
has_infinity = false,
218
has_quiet_NaN = false,
219
has_signaling_NaN= false,
222
has_denorm_loss = false,
223
is_iec559 = __IsIEC559,
226
tinyness_before= false
228
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
235
// Class numeric_limits
237
// The unspecialized class.
240
class numeric_limits : public _Numeric_limits_base<_Tp> {};
242
// Specializations for all built-in integral types.
244
#ifndef _STLP_NO_BOOL
247
class numeric_limits<bool>
248
: public _Integer_limits<bool, false, true, 1, false>
251
#endif /* _STLP_NO_BOOL */
254
class numeric_limits<char>
255
: public _Integer_limits<char, CHAR_MIN, CHAR_MAX, -1, true>
258
# ifndef _STLP_NO_SIGNED_BUILTINS
260
class numeric_limits<signed char>
261
: public _Integer_limits<signed char, SCHAR_MIN, SCHAR_MAX, -1, true>
266
class numeric_limits<unsigned char>
267
: public _Integer_limits<unsigned char, 0, UCHAR_MAX, -1, true>
270
#if !(defined ( _STLP_NO_WCHAR_T ) || defined (_STLP_WCHAR_T_IS_USHORT))
273
class numeric_limits<wchar_t>
274
: public _Integer_limits<wchar_t, WCHAR_MIN, WCHAR_MAX, -1, true>
280
class numeric_limits<short>
281
: public _Integer_limits<short, SHRT_MIN, SHRT_MAX, -1, true>
285
class numeric_limits<unsigned short>
286
: public _Integer_limits<unsigned short, 0, USHRT_MAX, -1, true>
289
# if defined (__xlC__) && (__xlC__ == 0x500)
291
# define INT_MIN -2147483648
296
class numeric_limits<int>
297
: public _Integer_limits<int, INT_MIN, INT_MAX, -1, true>
301
class numeric_limits<unsigned int>
302
: public _Integer_limits<unsigned int, 0, UINT_MAX, -1, true>
306
class numeric_limits<long>
307
: public _Integer_limits<long, LONG_MIN, LONG_MAX, -1, true>
311
class numeric_limits<unsigned long>
312
: public _Integer_limits<unsigned long, 0, ULONG_MAX, -1, true>
315
#ifdef _STLP_LONG_LONG
317
# if defined (_STLP_MSVC) || defined (__BORLANDC__)
319
# define LONGLONG_MAX 0x7fffffffffffffffi64
320
# define LONGLONG_MIN (-LONGLONG_MAX-1i64)
321
# define ULONGLONG_MAX 0xffffffffffffffffUi64
325
# ifndef LONGLONG_MAX
326
# define LONGLONG_MAX 0x7fffffffffffffffLL
328
# ifndef LONGLONG_MIN
329
# define LONGLONG_MIN (-LONGLONG_MAX-1LL)
331
# ifndef ULONGLONG_MAX
332
# define ULONGLONG_MAX 0xffffffffffffffffULL
337
#if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ <= 96)
340
class numeric_limits<_STLP_LONG_LONG>
341
: public _Integer_limits<_STLP_LONG_LONG, LONGLONG_MIN, LONGLONG_MAX, -1, true>
345
class numeric_limits<unsigned _STLP_LONG_LONG>
346
: public _Integer_limits<unsigned _STLP_LONG_LONG, 0, ULONGLONG_MAX, -1, true>
348
#else /* gcc 2.97 (after 2000-11-01), 2.98, 3.0 */
350
newest gcc has new mangling scheme, that has problem
351
with generating name [instantiated] of template specialization like
352
_Integer_limits<_STLP_LONG_LONG, LONGLONG_MIN, LONGLONG_MAX, -1, true>
353
~~~~~~~~~~~~ ~~~~~~~~~~~~
354
Below is code that solve this problem.
358
class numeric_limits<_STLP_LONG_LONG>
359
: public _Numeric_limits_base<_STLP_LONG_LONG>
363
static _STLP_LONG_LONG (_STLP_CALL min) () _STLP_NOTHROW { return LONGLONG_MIN; }
364
static _STLP_LONG_LONG (_STLP_CALL max) () _STLP_NOTHROW { return LONGLONG_MAX; }
366
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
371
digits = ((int)((sizeof(_STLP_LONG_LONG) * (CHAR_BIT))) - 1),
372
digits10 = (digits * 301UL) / 1000,
374
# if ! defined ( _STLP_STATIC_CONST_INIT_BUG)
380
is_specialized = true,
386
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
393
class numeric_limits<unsigned _STLP_LONG_LONG>
394
: public _Numeric_limits_base<unsigned _STLP_LONG_LONG>
398
static unsigned _STLP_LONG_LONG (_STLP_CALL min) () _STLP_NOTHROW { return 0ULL; }
399
static unsigned _STLP_LONG_LONG (_STLP_CALL max) () _STLP_NOTHROW { return ULONGLONG_MAX; }
401
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
406
digits = ((int)((sizeof(unsigned _STLP_LONG_LONG) * (CHAR_BIT)))),
407
digits10 = (digits * 301UL) / 1000,
409
# if ! defined ( _STLP_STATIC_CONST_INIT_BUG)
415
is_specialized = true,
421
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
427
# endif /* __GNUC__ > 2000-11-01 */
429
#endif /* _STLP_LONG_LONG */
431
// Specializations for all built-in floating-point types.
435
unsigned short rep[2];
440
unsigned short rep[4];
444
# ifndef _STLP_NO_LONG_DOUBLE
447
unsigned short rep[8];
452
template <class __dummy>
456
static const _F_rep _F_inf;
457
static const _F_rep _F_qNaN;
458
static const _F_rep _F_sNaN;
459
static const _D_rep _D_inf;
460
static const _D_rep _D_qNaN;
461
static const _D_rep _D_sNaN;
463
# ifndef _STLP_NO_LONG_DOUBLE
464
static const _L_rep _L_inf;
465
static const _L_rep _L_qNaN;
466
static const _L_rep _L_sNaN;
470
# if defined (_STLP_USE_TEMPLATE_EXPORT)
471
_STLP_EXPORT_TEMPLATE_CLASS _LimG<bool>;
474
_STLP_TEMPLATE_NULL class numeric_limits<float>
475
: public _Floating_limits<float,
476
FLT_MANT_DIG, // Binary digits of precision
477
FLT_DIG, // Decimal digits of precision
478
FLT_MIN_EXP, // Minimum exponent
479
FLT_MAX_EXP, // Maximum exponent
480
FLT_MIN_10_EXP, // Minimum base 10 exponent
481
FLT_MAX_10_EXP, // Maximum base 10 exponent
482
true, // conforms to iec559
486
static float (_STLP_CALL min) () _STLP_NOTHROW { return FLT_MIN; }
487
static float _STLP_CALL denorm_min() _STLP_NOTHROW { return FLT_MIN; }
488
static float (_STLP_CALL max) () _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return FLT_MAX; }
489
static float _STLP_CALL epsilon() _STLP_NOTHROW { return FLT_EPSILON; }
490
static float _STLP_CALL round_error() _STLP_NOTHROW { return 0.5f; } // Units: ulps.
491
static float _STLP_CALL infinity() { return _LimG<bool>::_F_inf.val; }
492
static float _STLP_CALL quiet_NaN() { return _LimG<bool>::_F_qNaN.val; }
493
static float _STLP_CALL signaling_NaN() { return _LimG<bool>::_F_sNaN.val; }
496
_STLP_TEMPLATE_NULL class numeric_limits<double>
497
: public _Floating_limits<double,
498
DBL_MANT_DIG, // Binary digits of precision
499
DBL_DIG, // Decimal digits of precision
500
DBL_MIN_EXP, // Minimum exponent
501
DBL_MAX_EXP, // Maximum exponent
502
DBL_MIN_10_EXP, // Minimum base 10 exponent
503
DBL_MAX_10_EXP, // Maximum base 10 exponent
504
true, // conforms to iec559
508
static double (_STLP_CALL min)() _STLP_NOTHROW { return DBL_MIN; }
509
static double _STLP_CALL denorm_min() _STLP_NOTHROW { return DBL_MIN; }
510
static double (_STLP_CALL max)() _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return DBL_MAX; }
511
static double _STLP_CALL epsilon() _STLP_NOTHROW { return DBL_EPSILON; }
512
static double _STLP_CALL round_error() _STLP_NOTHROW { return 0.5; } // Units: ulps.
513
static double _STLP_CALL infinity() { return _LimG<bool>::_D_inf.val; }
514
static double _STLP_CALL quiet_NaN(){ return _LimG<bool>::_D_qNaN.val; }
515
static double _STLP_CALL signaling_NaN() { return _LimG<bool>::_D_sNaN.val; }
518
# ifndef _STLP_NO_LONG_DOUBLE
521
class numeric_limits<long double>
522
: public _Floating_limits<long double,
523
LDBL_MANT_DIG, // Binary digits of precision
524
LDBL_DIG, // Decimal digits of precision
525
LDBL_MIN_EXP, // Minimum exponent
526
LDBL_MAX_EXP, // Maximum exponent
527
LDBL_MIN_10_EXP,// Minimum base 10 exponent
528
LDBL_MAX_10_EXP,// Maximum base 10 exponent
529
false, // Doesn't conform to iec559
533
static long double (_STLP_CALL min) () _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return LDBL_MIN; }
534
static long double _STLP_CALL denorm_min() _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return LDBL_MIN; }
535
static long double (_STLP_CALL max) () _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return LDBL_MAX; }
536
static long double _STLP_CALL epsilon() _STLP_NOTHROW { return LDBL_EPSILON; }
537
static long double _STLP_CALL round_error() _STLP_NOTHROW { return 4; } // Units: ulps.
538
static long double _STLP_CALL infinity() { return _LimG<bool>::_L_inf.val; }
539
static long double _STLP_CALL quiet_NaN() { return _LimG<bool>::_L_qNaN.val; }
540
static long double _STLP_CALL signaling_NaN() { return _LimG<bool>::_L_sNaN.val; }
545
// We write special values (Inf and NaN) as bit patterns and
546
// cast the the appropriate floating-point types.
549
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
550
# include <stl/_limits.c>