std_limits.h revision 132720
174912Sjhb// The template and inlines for the -*- C++ -*- numeric_limits classes.
274912Sjhb
324269Speter// Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
424269Speter//
524269Speter// This file is part of the GNU ISO C++ Library.  This library is free
624269Speter// software; you can redistribute it and/or modify it under the
724269Speter// terms of the GNU General Public License as published by the
824269Speter// Free Software Foundation; either version 2, or (at your option)
924269Speter// any later version.
1024269Speter
1124269Speter// This library is distributed in the hope that it will be useful,
1274912Sjhb// but WITHOUT ANY WARRANTY; without even the implied warranty of
1374912Sjhb// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1474912Sjhb// GNU General Public License for more details.
1524269Speter
1674912Sjhb// You should have received a copy of the GNU General Public License along
1724269Speter// with this library; see the file COPYING.  If not, write to the Free
1824269Speter// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
1974912Sjhb// USA.
2024269Speter
2124269Speter// As a special exception, you may use this file as part of a free software
2224269Speter// library without restriction.  Specifically, if other files instantiate
2324269Speter// templates or use macros or inline functions from this file, or you compile
2424269Speter// this file and link it with other files to produce an executable, this
2524269Speter// file does not by itself cause the resulting executable to be covered by
2624269Speter// the GNU General Public License.  This exception does not however
2724269Speter// invalidate any other reasons why the executable file might be covered by
2874912Sjhb// the GNU General Public License.
2950477Speter
3024269Speter// Note: this is not a conforming implementation.
3124269Speter// Written by Gabriel Dos Reis <gdr@codesourcery.com>
3274912Sjhb
3374912Sjhb//
3424269Speter// ISO 14882:1998
3574912Sjhb// 18.2.1
3676166Smarkm//
3774912Sjhb
38178165Sattilio/** @file limits
39102506Sbde *  This is a Standard C++ Library header.  You should @c #include this header
40102506Sbde *  in your programs, rather than any of the "st[dl]_*.h" implementation files.
4124269Speter */
4274912Sjhb
4374912Sjhb#ifndef _GLIBCXX_NUMERIC_LIMITS
4424269Speter#define _GLIBCXX_NUMERIC_LIMITS 1
4574912Sjhb
4674912Sjhb#pragma GCC system_header
4774912Sjhb
4874912Sjhb#include <bits/c++config.h>
49167368Sjhb
50167368Sjhb//
51167368Sjhb// The numeric_limits<> traits document implementation-defined aspects
52167368Sjhb// of fundamental arithmetic data types (integers and floating points).
53167368Sjhb// From Standard C++ point of view, there are 13 such types:
54167368Sjhb//   * integers
55167368Sjhb//         bool						        (1)
5624269Speter//         char, signed char, unsigned char			(3)
5774912Sjhb//         short, unsigned short				(2)
5883045Sobrien//         int, unsigned					(2)
5974912Sjhb//         long, unsigned long					(2)
6074912Sjhb//
61173733Sattilio//   * floating points
62153395Sjhb//         float						(1)
63167368Sjhb//         double						(1)
64167368Sjhb//         long double						(1)
6574912Sjhb//
6674912Sjhb// GNU C++ undertstands (where supported by the host C-library)
6774912Sjhb//   * integer
6874912Sjhb//         long long, unsigned long long			(2)
6974912Sjhb//
7074912Sjhb// which brings us to 15 fundamental arithmetic data types in GNU C++.
7182244Sjhb//
7274912Sjhb//
7374912Sjhb// Since a numeric_limits<> is a bit tricky to get right, we rely on
7474912Sjhb// an interface composed of macros which should be defined in config/os
7574912Sjhb// or config/cpu when they differ from the generic (read arbitrary)
7674912Sjhb// definitions given here.
7774912Sjhb//
7874912Sjhb
7982244Sjhb// These values can be overridden in the target configuration file.
8093273Sjeff// The default values are appropriate for many 32-bit targets.
81153133Sjhb
82154077Sjhb// GCC only intrinsicly supports modulo integral types.  The only remaining
83164159Skmacy// integral exceptional values is division by zero.  Only targets that do not
8474912Sjhb// signal division by zero in some "hard to ignore" way should use false.
85154077Sjhb#ifndef __glibcxx_integral_traps
86154077Sjhb# define __glibcxx_integral_traps true
87154077Sjhb#endif
88154077Sjhb
89154077Sjhb// float
90154077Sjhb//
91154077Sjhb
92154077Sjhb// Default values.  Should be overriden in configuration files if necessary.
93154484Sjhb
94154077Sjhb#ifndef __glibcxx_float_has_denorm_loss
9524269Speter#  define __glibcxx_float_has_denorm_loss false
9674912Sjhb#endif
9774912Sjhb#ifndef __glibcxx_float_traps
9824269Speter#  define __glibcxx_float_traps false
99125160Sjhb#endif
10074912Sjhb#ifndef __glibcxx_float_tinyness_before
10174912Sjhb#  define __glibcxx_float_tinyness_before false
10276272Sjhb#endif
103145421Sjeff
10424269Speter// double
10578871Sjhb
106176249Sattilio// Default values.  Should be overriden in configuration files if necessary.
10778871Sjhb
10878871Sjhb#ifndef __glibcxx_double_has_denorm_loss
10978871Sjhb#  define __glibcxx_double_has_denorm_loss false
11078871Sjhb#endif
11178871Sjhb#ifndef __glibcxx_double_traps
11278871Sjhb#  define __glibcxx_double_traps false
11378871Sjhb#endif
11474912Sjhb#ifndef __glibcxx_double_tinyness_before
11524269Speter#  define __glibcxx_double_tinyness_before false
11685186Sjhb#endif
11785186Sjhb
11885186Sjhb// long double
11985186Sjhb
12085186Sjhb// Default values.  Should be overriden in configuration files if necessary.
12185186Sjhb
12285186Sjhb#ifndef __glibcxx_long_double_has_denorm_loss
12385186Sjhb#  define __glibcxx_long_double_has_denorm_loss false
124164159Skmacy#endif
12585186Sjhb#ifndef __glibcxx_long_double_traps
12685186Sjhb#  define __glibcxx_long_double_traps false
12785186Sjhb#endif
12885186Sjhb#ifndef __glibcxx_long_double_tinyness_before
12985186Sjhb#  define __glibcxx_long_double_tinyness_before false
13085186Sjhb#endif
13183593Sjhb
13283593Sjhb// You should not need to define any macros below this point.
13383593Sjhb
13485186Sjhb#define __glibcxx_signed(T)	((T)(-1) < 0)
13583593Sjhb
13683593Sjhb#define __glibcxx_min(T) \
13783593Sjhb  (__glibcxx_signed (T) ? (T)1 << __glibcxx_digits (T) : (T)0)
13883593Sjhb
13983593Sjhb#define __glibcxx_max(T) \
14083593Sjhb  (__glibcxx_signed (T) ? ((T)1 << __glibcxx_digits (T)) - 1 : ~(T)0)
14183593Sjhb
14283593Sjhb#define __glibcxx_digits(T) \
14374912Sjhb  (sizeof(T) * __CHAR_BIT__ - __glibcxx_signed (T))
14424269Speter
14574912Sjhb// The fraction 643/2136 approximates log10(2) to 7 significant digits.
14674912Sjhb#define __glibcxx_digits10(T) \
14774912Sjhb  (__glibcxx_digits (T) * 643 / 2136)
14874912Sjhb
14974912Sjhb
15074912Sjhbnamespace std
15174912Sjhb{
15224269Speter  /**
15374912Sjhb   *  @brief Describes the rounding style for floating-point types.
15474912Sjhb   *
15524269Speter   *  This is used in the std::numeric_limits class.
15674912Sjhb  */
15774912Sjhb  enum float_round_style
15874912Sjhb  {
159154077Sjhb    round_indeterminate       = -1,    ///< Self-explanatory.
16074912Sjhb    round_toward_zero         = 0,     ///< Self-explanatory.
16174912Sjhb    round_to_nearest          = 1,     ///< To the nearest representable value.
16274912Sjhb    round_toward_infinity     = 2,     ///< Self-explanatory.
16374912Sjhb    round_toward_neg_infinity = 3      ///< Self-explanatory.
16474912Sjhb  };
16574912Sjhb
166154077Sjhb  /**
16774912Sjhb   *  @brief Describes the denormalization for floating-point types.
16874912Sjhb   *
16974912Sjhb   *  These values represent the presence or absence of a variable number
17074912Sjhb   *  of exponent bits.  This type is used in the std::numeric_limits class.
17174912Sjhb  */
17288661Sjake  enum float_denorm_style
173154077Sjhb  {
17474912Sjhb    /// Indeterminate at compile time whether denormalized values are allowed.
17574912Sjhb    denorm_indeterminate = -1,
17674912Sjhb    /// The type does not allow denormalized values.
17774912Sjhb    denorm_absent        = 0,
178154484Sjhb    /// The type allows denormalized values.
179154484Sjhb    denorm_present       = 1
18024269Speter  };
18174912Sjhb
18274912Sjhb  /**
18324269Speter   *  @brief Part of std::numeric_limits.
18474912Sjhb   *
18574912Sjhb   *  The @c static @c const members are usable as integral constant
18674912Sjhb   *  expressions.
18774912Sjhb   *
18874912Sjhb   *  @note This is a seperate class for purposes of efficiency; you
18924269Speter   *        should only access these members as part of an instantiation
19074912Sjhb   *        of the std::numeric_limits class.
19174912Sjhb  */
19274912Sjhb  struct __numeric_limits_base
193154941Sjhb  {
194173444Sups    /** This will be true for all fundamental types (which have
195164246Skmacy        specializations), and false for everything else.  */
19670140Sjake    static const bool is_specialized = false;
197154077Sjhb
198154077Sjhb    /** The number of @c radix digits that be represented without change:  for
199166455Sbms        integer types, the number of non-sign bits in the mantissa; for
200166455Sbms        floating types, the number of @c radix digits in the mantissa.  */
201166455Sbms    static const int digits = 0;
202144637Sjhb    /** The number of base 10 digits that can be represented without change. */
203144637Sjhb    static const int digits10 = 0;
20474912Sjhb    /** True if the type is signed.  */
20574912Sjhb    static const bool is_signed = false;
206125160Sjhb    /** True if the type is integer.
207125160Sjhb     *  @if maint
20874912Sjhb     *  Is this supposed to be "if the type is integral"?
20982244Sjhb     *  @endif
21082244Sjhb    */
21174912Sjhb    static const bool is_integer = false;
21274912Sjhb    /** True if the type uses an exact representation.  "All integer types are
21374912Sjhb        exact, but not all exact types are integer.  For example, rational and
21475273Sjhb        fixed-exponent representations are exact but not integer."
215111881Sjhb        [18.2.1.2]/15  */
21678871Sjhb    static const bool is_exact = false;
217118271Sjhb    /** For integer types, specifies the base of the representation.  For
218102448Siedowse        floating types, specifies the base of the exponent representation.  */
219102448Siedowse    static const int radix = 0;
22024269Speter
22174912Sjhb    /** The minimum negative integer such that @c radix raised to the power of
222111881Sjhb        (one less than that integer) is a normalized floating point number.  */
223111881Sjhb    static const int min_exponent = 0;
224111881Sjhb    /** The minimum negative integer such that 10 raised to that power is in
225111881Sjhb        the range of normalized floating point numbers.  */
226111881Sjhb    static const int min_exponent10 = 0;
227111881Sjhb    /** The maximum positive integer such that @c radix raised to the power of
22874912Sjhb        (one less than that integer) is a representable finite floating point
22974912Sjhb	number.  */
23066615Sjasone    static const int max_exponent = 0;
23174912Sjhb    /** The maximum positive integer such that 10 raised to that power is in
23274912Sjhb        the range of representable finite floating point numbers.  */
23324269Speter    static const int max_exponent10 = 0;
234125160Sjhb
235125160Sjhb    /** True if the type has a representation for positive infinity.  */
236125160Sjhb    static const bool has_infinity = false;
237125160Sjhb    /** True if the type has a representation for a quiet (non-signaling)
238125160Sjhb        "Not a Number."  */
239125160Sjhb    static const bool has_quiet_NaN = false;
240125160Sjhb    /** True if the type has a representation for a signaling
24174912Sjhb        "Not a Number."  */
24274912Sjhb    static const bool has_signaling_NaN = false;
24374912Sjhb    /** See std::float_denorm_style for more information.  */
24482244Sjhb    static const float_denorm_style has_denorm = denorm_absent;
24582244Sjhb    /** "True if loss of accuracy is detected as a denormalization loss,
24682244Sjhb        rather than as an inexact result." [18.2.1.2]/42  */
24782244Sjhb    static const bool has_denorm_loss = false;
24882244Sjhb
24982244Sjhb    /** True if-and-only-if the type adheres to the IEC 559 standard, also
25074912Sjhb        known as IEEE 754.  (Only makes sense for floating point types.)  */
25174912Sjhb    static const bool is_iec559 = false;
25274912Sjhb    /** "True if the set of values representable by the type is finite.   All
253154934Sjhb        built-in types are bounded, this member would be false for arbitrary
254154934Sjhb	precision types." [18.2.1.2]/54  */
255154934Sjhb    static const bool is_bounded = false;
256111881Sjhb    /** True if the type is @e modulo, that is, if it is possible to add two
257111881Sjhb        positive numbers and have a result that wraps around to a third number
25874912Sjhb        that is less.  Typically false for floating types, true for unsigned
25974912Sjhb        integers, and true for signed integers.  */
26074912Sjhb    static const bool is_modulo = false;
26174912Sjhb
26274912Sjhb    /** True if trapping is implemented for this type.  */
26374912Sjhb    static const bool traps = false;
26474912Sjhb    /** True if tinyness is detected before rounding.  (see IEC 559)  */
26574912Sjhb    static const bool tinyness_before = false;
26674912Sjhb    /** See std::float_round_style for more information.  This is only
26774912Sjhb        meaningful for floating types; integer types will all be
26874912Sjhb	round_toward_zero.  */
269102448Siedowse    static const float_round_style round_style = round_toward_zero;
270102448Siedowse  };
271102448Siedowse
272102448Siedowse  /**
273102448Siedowse   *  @brief Properties of fundamental types.
274102448Siedowse   *
27574912Sjhb   *  This class allows a program to obtain information about the
276154484Sjhb   *  representation of a fundamental type on a given platform.  For
277154484Sjhb   *  non-fundamental types, the functions will return 0 and the data
278125160Sjhb   *  members will all be @c false.
279125160Sjhb   *
28074912Sjhb   *  @if maint
28182244Sjhb   *  _GLIBCXX_RESOLVE_LIB_DEFECTS:  DRs 201 and 184 (hi Gaby!) are
28282244Sjhb   *  noted, but not incorporated in this documented (yet).
28374912Sjhb   *  @endif
284154934Sjhb  */
285111881Sjhb  template<typename _Tp>
28674912Sjhb    struct numeric_limits : public __numeric_limits_base
28774912Sjhb    {
28874912Sjhb      /** The minimum finite value, or for floating types with
289102448Siedowse          denormalization, the minimum positive normalized value.  */
290102448Siedowse      static _Tp min() throw() { return static_cast<_Tp>(0); }
29174912Sjhb      /** The maximum finite value.  */
29274912Sjhb      static _Tp max() throw() { return static_cast<_Tp>(0); }
293125160Sjhb      /** The @e machine @e epsilon:  the difference between 1 and the least
294125160Sjhb          value greater than 1 that is representable.  */
295125160Sjhb      static _Tp epsilon() throw() { return static_cast<_Tp>(0); }
296125160Sjhb      /** The maximum rounding error measurement (see LIA-1).  */
297167788Sjhb      static _Tp round_error() throw() { return static_cast<_Tp>(0); }
298167788Sjhb      /** The representation of positive infinity, if @c has_infinity.  */
299125160Sjhb      static _Tp infinity() throw()  { return static_cast<_Tp>(0); }
300125160Sjhb      /** The representation of a quiet "Not a Number," if @c has_quiet_NaN. */
301167788Sjhb      static _Tp quiet_NaN() throw() { return static_cast<_Tp>(0); }
302167788Sjhb      /** The representation of a signaling "Not a Number," if
303125160Sjhb          @c has_signaling_NaN. */
30474912Sjhb      static _Tp signaling_NaN() throw() { return static_cast<_Tp>(0); }
30574912Sjhb      /** The minimum positive denormalized value.  For types where
306          @c has_denorm is false, this is the minimum positive normalized
307	  value.  */
308      static _Tp denorm_min() throw() { return static_cast<_Tp>(0); }
309    };
310
311  // Now there follow 15 explicit specializations.  Yes, 15.  Make sure
312  // you get the count right.
313  template<>
314    struct numeric_limits<bool>
315    {
316      static const bool is_specialized = true;
317
318      static bool min() throw()
319      { return false; }
320      static bool max() throw()
321      { return true; }
322
323      static const int digits = 1;
324      static const int digits10 = 0;
325      static const bool is_signed = false;
326      static const bool is_integer = true;
327      static const bool is_exact = true;
328      static const int radix = 2;
329      static bool epsilon() throw()
330      { return false; }
331      static bool round_error() throw()
332      { return false; }
333
334      static const int min_exponent = 0;
335      static const int min_exponent10 = 0;
336      static const int max_exponent = 0;
337      static const int max_exponent10 = 0;
338
339      static const bool has_infinity = false;
340      static const bool has_quiet_NaN = false;
341      static const bool has_signaling_NaN = false;
342      static const float_denorm_style has_denorm = denorm_absent;
343      static const bool has_denorm_loss = false;
344
345      static bool infinity() throw()
346      { return false; }
347      static bool quiet_NaN() throw()
348      { return false; }
349      static bool signaling_NaN() throw()
350      { return false; }
351      static bool denorm_min() throw()
352      { return false; }
353
354      static const bool is_iec559 = false;
355      static const bool is_bounded = true;
356      static const bool is_modulo = false;
357
358      // It is not clear what it means for a boolean type to trap.
359      // This is a DR on the LWG issue list.  Here, I use integer
360      // promotion semantics.
361      static const bool traps = __glibcxx_integral_traps;
362      static const bool tinyness_before = false;
363      static const float_round_style round_style = round_toward_zero;
364    };
365
366  template<>
367    struct numeric_limits<char>
368    {
369      static const bool is_specialized = true;
370
371      static char min() throw()
372      { return __glibcxx_min(char); }
373      static char max() throw()
374      { return __glibcxx_max(char); }
375
376      static const int digits = __glibcxx_digits (char);
377      static const int digits10 = __glibcxx_digits10 (char);
378      static const bool is_signed = __glibcxx_signed (char);
379      static const bool is_integer = true;
380      static const bool is_exact = true;
381      static const int radix = 2;
382      static char epsilon() throw()
383      { return 0; }
384      static char round_error() throw()
385      { return 0; }
386
387      static const int min_exponent = 0;
388      static const int min_exponent10 = 0;
389      static const int max_exponent = 0;
390      static const int max_exponent10 = 0;
391
392      static const bool has_infinity = false;
393      static const bool has_quiet_NaN = false;
394      static const bool has_signaling_NaN = false;
395      static const float_denorm_style has_denorm = denorm_absent;
396      static const bool has_denorm_loss = false;
397
398      static char infinity() throw()
399      { return char(); }
400      static char quiet_NaN() throw()
401      { return char(); }
402      static char signaling_NaN() throw()
403      { return char(); }
404      static char denorm_min() throw()
405      { return static_cast<char>(0); }
406
407      static const bool is_iec559 = false;
408      static const bool is_bounded = true;
409      static const bool is_modulo = true;
410
411      static const bool traps = __glibcxx_integral_traps;
412      static const bool tinyness_before = false;
413      static const float_round_style round_style = round_toward_zero;
414    };
415
416  template<>
417    struct numeric_limits<signed char>
418    {
419      static const bool is_specialized = true;
420
421      static signed char min() throw()
422      { return -__SCHAR_MAX__ - 1; }
423      static signed char max() throw()
424      { return __SCHAR_MAX__; }
425
426      static const int digits = __glibcxx_digits (signed char);
427      static const int digits10 = __glibcxx_digits10 (signed char);
428      static const bool is_signed = true;
429      static const bool is_integer = true;
430      static const bool is_exact = true;
431      static const int radix = 2;
432      static signed char epsilon() throw()
433      { return 0; }
434      static signed char round_error() throw()
435      { return 0; }
436
437      static const int min_exponent = 0;
438      static const int min_exponent10 = 0;
439      static const int max_exponent = 0;
440      static const int max_exponent10 = 0;
441
442      static const bool has_infinity = false;
443      static const bool has_quiet_NaN = false;
444      static const bool has_signaling_NaN = false;
445      static const float_denorm_style has_denorm = denorm_absent;
446      static const bool has_denorm_loss = false;
447
448      static signed char infinity() throw()
449      { return static_cast<signed char>(0); }
450      static signed char quiet_NaN() throw()
451      { return static_cast<signed char>(0); }
452      static signed char signaling_NaN() throw()
453      { return static_cast<signed char>(0); }
454      static signed char denorm_min() throw()
455      { return static_cast<signed char>(0); }
456
457      static const bool is_iec559 = false;
458      static const bool is_bounded = true;
459      static const bool is_modulo = true;
460
461      static const bool traps = __glibcxx_integral_traps;
462      static const bool tinyness_before = false;
463      static const float_round_style round_style = round_toward_zero;
464    };
465
466  template<>
467    struct numeric_limits<unsigned char>
468    {
469      static const bool is_specialized = true;
470
471      static unsigned char min() throw()
472      { return 0; }
473      static unsigned char max() throw()
474      { return __SCHAR_MAX__ * 2U + 1; }
475
476      static const int digits = __glibcxx_digits (unsigned char);
477      static const int digits10 = __glibcxx_digits10 (unsigned char);
478      static const bool is_signed = false;
479      static const bool is_integer = true;
480      static const bool is_exact = true;
481      static const int radix = 2;
482      static unsigned char epsilon() throw()
483      { return 0; }
484      static unsigned char round_error() throw()
485      { return 0; }
486
487      static const int min_exponent = 0;
488      static const int min_exponent10 = 0;
489      static const int max_exponent = 0;
490      static const int max_exponent10 = 0;
491
492      static const bool has_infinity = false;
493      static const bool has_quiet_NaN = false;
494      static const bool has_signaling_NaN = false;
495      static const float_denorm_style has_denorm = denorm_absent;
496      static const bool has_denorm_loss = false;
497
498      static unsigned char infinity() throw()
499      { return static_cast<unsigned char>(0); }
500      static unsigned char quiet_NaN() throw()
501      { return static_cast<unsigned char>(0); }
502      static unsigned char signaling_NaN() throw()
503      { return static_cast<unsigned char>(0); }
504      static unsigned char denorm_min() throw()
505      { return static_cast<unsigned char>(0); }
506
507      static const bool is_iec559 = false;
508      static const bool is_bounded = true;
509      static const bool is_modulo = true;
510
511      static const bool traps = __glibcxx_integral_traps;
512      static const bool tinyness_before = false;
513      static const float_round_style round_style = round_toward_zero;
514    };
515
516  template<>
517    struct numeric_limits<wchar_t>
518    {
519      static const bool is_specialized = true;
520
521      static wchar_t min() throw()
522      { return __glibcxx_min (wchar_t); }
523      static wchar_t max() throw()
524      { return __glibcxx_max (wchar_t); }
525
526      static const int digits = __glibcxx_digits (wchar_t);
527      static const int digits10 = __glibcxx_digits10 (wchar_t);
528      static const bool is_signed = __glibcxx_signed (wchar_t);
529      static const bool is_integer = true;
530      static const bool is_exact = true;
531      static const int radix = 2;
532      static wchar_t epsilon() throw()
533      { return 0; }
534      static wchar_t round_error() throw()
535      { return 0; }
536
537      static const int min_exponent = 0;
538      static const int min_exponent10 = 0;
539      static const int max_exponent = 0;
540      static const int max_exponent10 = 0;
541
542      static const bool has_infinity = false;
543      static const bool has_quiet_NaN = false;
544      static const bool has_signaling_NaN = false;
545      static const float_denorm_style has_denorm = denorm_absent;
546      static const bool has_denorm_loss = false;
547
548      static wchar_t infinity() throw()
549      { return wchar_t(); }
550      static wchar_t quiet_NaN() throw()
551      { return wchar_t(); }
552      static wchar_t signaling_NaN() throw()
553      { return wchar_t(); }
554      static wchar_t denorm_min() throw()
555      { return wchar_t(); }
556
557      static const bool is_iec559 = false;
558      static const bool is_bounded = true;
559      static const bool is_modulo = true;
560
561      static const bool traps = __glibcxx_integral_traps;
562      static const bool tinyness_before = false;
563      static const float_round_style round_style = round_toward_zero;
564    };
565
566  template<>
567    struct numeric_limits<short>
568    {
569      static const bool is_specialized = true;
570
571      static short min() throw()
572      { return -__SHRT_MAX__ - 1; }
573      static short max() throw()
574      { return __SHRT_MAX__; }
575
576      static const int digits = __glibcxx_digits (short);
577      static const int digits10 = __glibcxx_digits10 (short);
578      static const bool is_signed = true;
579      static const bool is_integer = true;
580      static const bool is_exact = true;
581      static const int radix = 2;
582      static short epsilon() throw()
583      { return 0; }
584      static short round_error() throw()
585      { return 0; }
586
587      static const int min_exponent = 0;
588      static const int min_exponent10 = 0;
589      static const int max_exponent = 0;
590      static const int max_exponent10 = 0;
591
592      static const bool has_infinity = false;
593      static const bool has_quiet_NaN = false;
594      static const bool has_signaling_NaN = false;
595      static const float_denorm_style has_denorm = denorm_absent;
596      static const bool has_denorm_loss = false;
597
598      static short infinity() throw()
599      { return short(); }
600      static short quiet_NaN() throw()
601      { return short(); }
602      static short signaling_NaN() throw()
603      { return short(); }
604      static short denorm_min() throw()
605      { return short(); }
606
607      static const bool is_iec559 = false;
608      static const bool is_bounded = true;
609      static const bool is_modulo = true;
610
611      static const bool traps = __glibcxx_integral_traps;
612      static const bool tinyness_before = false;
613      static const float_round_style round_style = round_toward_zero;
614    };
615
616  template<>
617    struct numeric_limits<unsigned short>
618    {
619      static const bool is_specialized = true;
620
621      static unsigned short min() throw()
622      { return 0; }
623      static unsigned short max() throw()
624      { return __SHRT_MAX__ * 2U + 1; }
625
626      static const int digits = __glibcxx_digits (unsigned short);
627      static const int digits10 = __glibcxx_digits10 (unsigned short);
628      static const bool is_signed = false;
629      static const bool is_integer = true;
630      static const bool is_exact = true;
631      static const int radix = 2;
632      static unsigned short epsilon() throw()
633      { return 0; }
634      static unsigned short round_error() throw()
635      { return 0; }
636
637      static const int min_exponent = 0;
638      static const int min_exponent10 = 0;
639      static const int max_exponent = 0;
640      static const int max_exponent10 = 0;
641
642      static const bool has_infinity = false;
643      static const bool has_quiet_NaN = false;
644      static const bool has_signaling_NaN = false;
645      static const float_denorm_style has_denorm = denorm_absent;
646      static const bool has_denorm_loss = false;
647
648      static unsigned short infinity() throw()
649      { return static_cast<unsigned short>(0); }
650      static unsigned short quiet_NaN() throw()
651      { return static_cast<unsigned short>(0); }
652      static unsigned short signaling_NaN() throw()
653      { return static_cast<unsigned short>(0); }
654      static unsigned short denorm_min() throw()
655      { return static_cast<unsigned short>(0); }
656
657      static const bool is_iec559 = false;
658      static const bool is_bounded = true;
659      static const bool is_modulo = true;
660
661      static const bool traps = __glibcxx_integral_traps;
662      static const bool tinyness_before = false;
663      static const float_round_style round_style = round_toward_zero;
664    };
665
666  template<>
667    struct numeric_limits<int>
668    {
669      static const bool is_specialized = true;
670
671      static int min() throw()
672      { return -__INT_MAX__ - 1; }
673      static int max() throw()
674      { return __INT_MAX__; }
675
676      static const int digits = __glibcxx_digits (int);
677      static const int digits10 = __glibcxx_digits10 (int);
678      static const bool is_signed = true;
679      static const bool is_integer = true;
680      static const bool is_exact = true;
681      static const int radix = 2;
682      static int epsilon() throw()
683      { return 0; }
684      static int round_error() throw()
685      { return 0; }
686
687      static const int min_exponent = 0;
688      static const int min_exponent10 = 0;
689      static const int max_exponent = 0;
690      static const int max_exponent10 = 0;
691
692      static const bool has_infinity = false;
693      static const bool has_quiet_NaN = false;
694      static const bool has_signaling_NaN = false;
695      static const float_denorm_style has_denorm = denorm_absent;
696      static const bool has_denorm_loss = false;
697
698      static int infinity() throw()
699      { return static_cast<int>(0); }
700      static int quiet_NaN() throw()
701      { return static_cast<int>(0); }
702      static int signaling_NaN() throw()
703      { return static_cast<int>(0); }
704      static int denorm_min() throw()
705      { return static_cast<int>(0); }
706
707      static const bool is_iec559 = false;
708      static const bool is_bounded = true;
709      static const bool is_modulo = true;
710
711      static const bool traps = __glibcxx_integral_traps;
712      static const bool tinyness_before = false;
713      static const float_round_style round_style = round_toward_zero;
714    };
715
716  template<>
717    struct numeric_limits<unsigned int>
718    {
719      static const bool is_specialized = true;
720
721      static unsigned int min() throw()
722      { return 0; }
723      static unsigned int max() throw()
724      { return __INT_MAX__ * 2U + 1; }
725
726      static const int digits = __glibcxx_digits (unsigned int);
727      static const int digits10 = __glibcxx_digits10 (unsigned int);
728      static const bool is_signed = false;
729      static const bool is_integer = true;
730      static const bool is_exact = true;
731      static const int radix = 2;
732      static unsigned int epsilon() throw()
733      { return 0; }
734      static unsigned int round_error() throw()
735      { return 0; }
736
737      static const int min_exponent = 0;
738      static const int min_exponent10 = 0;
739      static const int max_exponent = 0;
740      static const int max_exponent10 = 0;
741
742      static const bool has_infinity = false;
743      static const bool has_quiet_NaN = false;
744      static const bool has_signaling_NaN = false;
745      static const float_denorm_style has_denorm = denorm_absent;
746      static const bool has_denorm_loss = false;
747
748      static unsigned int infinity() throw()
749      { return static_cast<unsigned int>(0); }
750      static unsigned int quiet_NaN() throw()
751      { return static_cast<unsigned int>(0); }
752      static unsigned int signaling_NaN() throw()
753      { return static_cast<unsigned int>(0); }
754      static unsigned int denorm_min() throw()
755      { return static_cast<unsigned int>(0); }
756
757      static const bool is_iec559 = false;
758      static const bool is_bounded = true;
759      static const bool is_modulo = true;
760
761      static const bool traps = __glibcxx_integral_traps;
762      static const bool tinyness_before = false;
763      static const float_round_style round_style = round_toward_zero;
764    };
765
766  template<>
767    struct numeric_limits<long>
768    {
769      static const bool is_specialized = true;
770
771      static long min() throw()
772      { return -__LONG_MAX__ - 1; }
773      static long max() throw()
774      { return __LONG_MAX__; }
775
776      static const int digits = __glibcxx_digits (long);
777      static const int digits10 = __glibcxx_digits10 (long);
778      static const bool is_signed = true;
779      static const bool is_integer = true;
780      static const bool is_exact = true;
781      static const int radix = 2;
782      static long epsilon() throw()
783      { return 0; }
784      static long round_error() throw()
785      { return 0; }
786
787      static const int min_exponent = 0;
788      static const int min_exponent10 = 0;
789      static const int max_exponent = 0;
790      static const int max_exponent10 = 0;
791
792      static const bool has_infinity = false;
793      static const bool has_quiet_NaN = false;
794      static const bool has_signaling_NaN = false;
795      static const float_denorm_style has_denorm = denorm_absent;
796      static const bool has_denorm_loss = false;
797
798      static long infinity() throw()
799      { return static_cast<long>(0); }
800      static long quiet_NaN() throw()
801      { return static_cast<long>(0); }
802      static long signaling_NaN() throw()
803      { return static_cast<long>(0); }
804      static long denorm_min() throw()
805      { return static_cast<long>(0); }
806
807      static const bool is_iec559 = false;
808      static const bool is_bounded = true;
809      static const bool is_modulo = true;
810
811      static const bool traps = __glibcxx_integral_traps;
812      static const bool tinyness_before = false;
813      static const float_round_style round_style = round_toward_zero;
814    };
815
816  template<>
817    struct numeric_limits<unsigned long>
818    {
819      static const bool is_specialized = true;
820
821      static unsigned long min() throw()
822      { return 0; }
823      static unsigned long max() throw()
824      { return __LONG_MAX__ * 2UL + 1; }
825
826      static const int digits = __glibcxx_digits (unsigned long);
827      static const int digits10 = __glibcxx_digits10 (unsigned long);
828      static const bool is_signed = false;
829      static const bool is_integer = true;
830      static const bool is_exact = true;
831      static const int radix = 2;
832      static unsigned long epsilon() throw()
833      { return 0; }
834      static unsigned long round_error() throw()
835      { return 0; }
836
837      static const int min_exponent = 0;
838      static const int min_exponent10 = 0;
839      static const int max_exponent = 0;
840      static const int max_exponent10 = 0;
841
842      static const bool has_infinity = false;
843      static const bool has_quiet_NaN = false;
844      static const bool has_signaling_NaN = false;
845      static const float_denorm_style has_denorm = denorm_absent;
846      static const bool has_denorm_loss = false;
847
848      static unsigned long infinity() throw()
849      { return static_cast<unsigned long>(0); }
850      static unsigned long quiet_NaN() throw()
851      { return static_cast<unsigned long>(0); }
852      static unsigned long signaling_NaN() throw()
853      { return static_cast<unsigned long>(0); }
854      static unsigned long denorm_min() throw()
855      { return static_cast<unsigned long>(0); }
856
857      static const bool is_iec559 = false;
858      static const bool is_bounded = true;
859      static const bool is_modulo = true;
860
861      static const bool traps = __glibcxx_integral_traps;
862      static const bool tinyness_before = false;
863      static const float_round_style round_style = round_toward_zero;
864    };
865
866  template<>
867    struct numeric_limits<long long>
868    {
869      static const bool is_specialized = true;
870
871      static long long min() throw()
872      { return -__LONG_LONG_MAX__ - 1; }
873      static long long max() throw()
874      { return __LONG_LONG_MAX__; }
875
876      static const int digits = __glibcxx_digits (long long);
877      static const int digits10 = __glibcxx_digits10 (long long);
878      static const bool is_signed = true;
879      static const bool is_integer = true;
880      static const bool is_exact = true;
881      static const int radix = 2;
882      static long long epsilon() throw()
883      { return 0; }
884      static long long round_error() throw()
885      { return 0; }
886
887      static const int min_exponent = 0;
888      static const int min_exponent10 = 0;
889      static const int max_exponent = 0;
890      static const int max_exponent10 = 0;
891
892      static const bool has_infinity = false;
893      static const bool has_quiet_NaN = false;
894      static const bool has_signaling_NaN = false;
895      static const float_denorm_style has_denorm = denorm_absent;
896      static const bool has_denorm_loss = false;
897
898      static long long infinity() throw()
899      { return static_cast<long long>(0); }
900      static long long quiet_NaN() throw()
901      { return static_cast<long long>(0); }
902      static long long signaling_NaN() throw()
903      { return static_cast<long long>(0); }
904      static long long denorm_min() throw()
905      { return static_cast<long long>(0); }
906
907      static const bool is_iec559 = false;
908      static const bool is_bounded = true;
909      static const bool is_modulo = true;
910
911      static const bool traps = __glibcxx_integral_traps;
912      static const bool tinyness_before = false;
913      static const float_round_style round_style = round_toward_zero;
914    };
915
916  template<>
917    struct numeric_limits<unsigned long long>
918    {
919      static const bool is_specialized = true;
920
921      static unsigned long long min() throw()
922      { return 0; }
923      static unsigned long long max() throw()
924      { return __LONG_LONG_MAX__ * 2ULL + 1; }
925
926      static const int digits = __glibcxx_digits (unsigned long long);
927      static const int digits10 = __glibcxx_digits10 (unsigned long long);
928      static const bool is_signed = false;
929      static const bool is_integer = true;
930      static const bool is_exact = true;
931      static const int radix = 2;
932      static unsigned long long epsilon() throw()
933      { return 0; }
934      static unsigned long long round_error() throw()
935      { return 0; }
936
937      static const int min_exponent = 0;
938      static const int min_exponent10 = 0;
939      static const int max_exponent = 0;
940      static const int max_exponent10 = 0;
941
942      static const bool has_infinity = false;
943      static const bool has_quiet_NaN = false;
944      static const bool has_signaling_NaN = false;
945      static const float_denorm_style has_denorm = denorm_absent;
946      static const bool has_denorm_loss = false;
947
948      static unsigned long long infinity() throw()
949      { return static_cast<unsigned long long>(0); }
950      static unsigned long long quiet_NaN() throw()
951      { return static_cast<unsigned long long>(0); }
952      static unsigned long long signaling_NaN() throw()
953      { return static_cast<unsigned long long>(0); }
954      static unsigned long long denorm_min() throw()
955      { return static_cast<unsigned long long>(0); }
956
957      static const bool is_iec559 = false;
958      static const bool is_bounded = true;
959      static const bool is_modulo = true;
960
961      static const bool traps = __glibcxx_integral_traps;
962      static const bool tinyness_before = false;
963      static const float_round_style round_style = round_toward_zero;
964    };
965
966  template<>
967    struct numeric_limits<float>
968    {
969      static const bool is_specialized = true;
970
971      static float min() throw()
972      { return __FLT_MIN__; }
973      static float max() throw()
974      { return __FLT_MAX__; }
975
976      static const int digits = __FLT_MANT_DIG__;
977      static const int digits10 = __FLT_DIG__;
978      static const bool is_signed = true;
979      static const bool is_integer = false;
980      static const bool is_exact = false;
981      static const int radix = __FLT_RADIX__;
982      static float epsilon() throw()
983      { return __FLT_EPSILON__; }
984      static float round_error() throw()
985      { return 0.5F; }
986
987      static const int min_exponent = __FLT_MIN_EXP__;
988      static const int min_exponent10 = __FLT_MIN_10_EXP__;
989      static const int max_exponent = __FLT_MAX_EXP__;
990      static const int max_exponent10 = __FLT_MAX_10_EXP__;
991
992      static const bool has_infinity = __FLT_HAS_INFINITY__;
993      static const bool has_quiet_NaN = __FLT_HAS_QUIET_NAN__;
994      static const bool has_signaling_NaN = has_quiet_NaN;
995      static const float_denorm_style has_denorm
996	= __FLT_DENORM_MIN__ ? denorm_present : denorm_absent;
997      static const bool has_denorm_loss = __glibcxx_float_has_denorm_loss;
998
999      static float infinity() throw()
1000      { return __builtin_huge_valf (); }
1001      static float quiet_NaN() throw()
1002      { return __builtin_nanf (""); }
1003      static float signaling_NaN() throw()
1004      { return __builtin_nansf (""); }
1005      static float denorm_min() throw()
1006      { return __FLT_DENORM_MIN__; }
1007
1008      static const bool is_iec559
1009	= has_infinity && has_quiet_NaN && has_denorm == denorm_present;
1010      static const bool is_bounded = true;
1011      static const bool is_modulo = false;
1012
1013      static const bool traps = __glibcxx_float_traps;
1014      static const bool tinyness_before = __glibcxx_float_tinyness_before;
1015      static const float_round_style round_style = round_to_nearest;
1016    };
1017
1018#undef __glibcxx_float_has_denorm_loss
1019#undef __glibcxx_float_traps
1020#undef __glibcxx_float_tinyness_before
1021
1022  template<>
1023    struct numeric_limits<double>
1024    {
1025      static const bool is_specialized = true;
1026
1027      static double min() throw()
1028      { return __DBL_MIN__; }
1029      static double max() throw()
1030      { return __DBL_MAX__; }
1031
1032      static const int digits = __DBL_MANT_DIG__;
1033      static const int digits10 = __DBL_DIG__;
1034      static const bool is_signed = true;
1035      static const bool is_integer = false;
1036      static const bool is_exact = false;
1037      static const int radix = __FLT_RADIX__;
1038      static double epsilon() throw()
1039      { return __DBL_EPSILON__; }
1040      static double round_error() throw()
1041      { return 0.5; }
1042
1043      static const int min_exponent = __DBL_MIN_EXP__;
1044      static const int min_exponent10 = __DBL_MIN_10_EXP__;
1045      static const int max_exponent = __DBL_MAX_EXP__;
1046      static const int max_exponent10 = __DBL_MAX_10_EXP__;
1047
1048      static const bool has_infinity = __DBL_HAS_INFINITY__;
1049      static const bool has_quiet_NaN = __DBL_HAS_QUIET_NAN__;
1050      static const bool has_signaling_NaN = has_quiet_NaN;
1051      static const float_denorm_style has_denorm
1052	= __DBL_DENORM_MIN__ ? denorm_present : denorm_absent;
1053      static const bool has_denorm_loss = __glibcxx_double_has_denorm_loss;
1054
1055      static double infinity() throw()
1056      { return __builtin_huge_val(); }
1057      static double quiet_NaN() throw()
1058      { return __builtin_nan (""); }
1059      static double signaling_NaN() throw()
1060      { return __builtin_nans (""); }
1061      static double denorm_min() throw()
1062      { return __DBL_DENORM_MIN__; }
1063
1064      static const bool is_iec559
1065	= has_infinity && has_quiet_NaN && has_denorm == denorm_present;
1066      static const bool is_bounded = true;
1067      static const bool is_modulo = false;
1068
1069      static const bool traps = __glibcxx_double_traps;
1070      static const bool tinyness_before = __glibcxx_double_tinyness_before;
1071      static const float_round_style round_style = round_to_nearest;
1072    };
1073
1074#undef __glibcxx_double_has_denorm_loss
1075#undef __glibcxx_double_traps
1076#undef __glibcxx_double_tinyness_before
1077
1078  template<>
1079    struct numeric_limits<long double>
1080    {
1081      static const bool is_specialized = true;
1082
1083      static long double min() throw()
1084      { return __LDBL_MIN__; }
1085      static long double max() throw()
1086      { return __LDBL_MAX__; }
1087
1088      static const int digits = __LDBL_MANT_DIG__;
1089      static const int digits10 = __LDBL_DIG__;
1090      static const bool is_signed = true;
1091      static const bool is_integer = false;
1092      static const bool is_exact = false;
1093      static const int radix = __FLT_RADIX__;
1094      static long double epsilon() throw()
1095      { return __LDBL_EPSILON__; }
1096      static long double round_error() throw()
1097      { return 0.5L; }
1098
1099      static const int min_exponent = __LDBL_MIN_EXP__;
1100      static const int min_exponent10 = __LDBL_MIN_10_EXP__;
1101      static const int max_exponent = __LDBL_MAX_EXP__;
1102      static const int max_exponent10 = __LDBL_MAX_10_EXP__;
1103
1104      static const bool has_infinity = __LDBL_HAS_INFINITY__;
1105      static const bool has_quiet_NaN = __LDBL_HAS_QUIET_NAN__;
1106      static const bool has_signaling_NaN = has_quiet_NaN;
1107      static const float_denorm_style has_denorm
1108	= __LDBL_DENORM_MIN__ ? denorm_present : denorm_absent;
1109      static const bool has_denorm_loss
1110	= __glibcxx_long_double_has_denorm_loss;
1111
1112      static long double infinity() throw()
1113      { return __builtin_huge_vall (); }
1114      static long double quiet_NaN() throw()
1115      { return __builtin_nanl (""); }
1116      static long double signaling_NaN() throw()
1117      { return __builtin_nansl (""); }
1118      static long double denorm_min() throw()
1119      { return __LDBL_DENORM_MIN__; }
1120
1121      static const bool is_iec559
1122	= has_infinity && has_quiet_NaN && has_denorm == denorm_present;
1123      static const bool is_bounded = true;
1124      static const bool is_modulo = false;
1125
1126      static const bool traps = __glibcxx_long_double_traps;
1127      static const bool tinyness_before = __glibcxx_long_double_tinyness_before;
1128      static const float_round_style round_style = round_to_nearest;
1129    };
1130
1131#undef __glibcxx_long_double_has_denorm_loss
1132#undef __glibcxx_long_double_traps
1133#undef __glibcxx_long_double_tinyness_before
1134
1135} // namespace std
1136
1137#undef __glibcxx_signed
1138#undef __glibcxx_min
1139#undef __glibcxx_max
1140#undef __glibcxx_digits
1141#undef __glibcxx_digits10
1142
1143#endif // _GLIBCXX_NUMERIC_LIMITS
1144