_limits.h
来自「stl的源码」· C头文件 代码 · 共 520 行 · 第 1/2 页
H
520 行
/* * Copyright (c) 1997 * Silicon Graphics Computer Systems, Inc. * * Copyright (c) 1999 * Boris Fomitchev * * This material is provided "as is", with absolutely no warranty expressed * or implied. Any use is at your own risk. * * Permission to use or copy this software for any purpose is hereby granted * without fee, provided the above notices are retained on all copies. * Permission to modify the code and to distribute modified code is granted, * provided the above notices are retained, and a notice that the code was * modified is included with the above copyright notice. * *//* NOTE: This may be not portable code. Parts of numeric_limits<> are * inherently machine-dependent. At present this file is suitable * for the MIPS, SPARC, Alpha and ia32 architectures. */#ifndef _STLP_INTERNAL_LIMITS#define _STLP_INTERNAL_LIMITS#ifndef _STLP_CLIMITS# include <climits>#endif#ifndef _STLP_CFLOAT# include <cfloat>#endif#if defined (_STLP_HAS_WCHAR_T) && !defined (_STLP_INTERNAL_CWCHAR)# include <stl/_cwchar.h>#endif_STLP_BEGIN_NAMESPACEenum float_round_style { round_indeterminate = -1, round_toward_zero = 0, round_to_nearest = 1, round_toward_infinity = 2, round_toward_neg_infinity = 3};enum float_denorm_style { denorm_indeterminate = -1, denorm_absent = 0, denorm_present = 1};_STLP_MOVE_TO_PRIV_NAMESPACE// Base class for all specializations of numeric_limits.template <class __number>class _Numeric_limits_base {public: static __number (_STLP_CALL min)() _STLP_NOTHROW { return __number(); } static __number (_STLP_CALL max)() _STLP_NOTHROW { return __number(); } _STLP_STATIC_CONSTANT(int, digits = 0); _STLP_STATIC_CONSTANT(int, digits10 = 0); _STLP_STATIC_CONSTANT(int, radix = 0); _STLP_STATIC_CONSTANT(int, min_exponent = 0); _STLP_STATIC_CONSTANT(int, min_exponent10 = 0); _STLP_STATIC_CONSTANT(int, max_exponent = 0); _STLP_STATIC_CONSTANT(int, max_exponent10 = 0); _STLP_STATIC_CONSTANT(float_denorm_style, has_denorm = denorm_absent); _STLP_STATIC_CONSTANT(float_round_style, round_style = round_toward_zero); _STLP_STATIC_CONSTANT(bool, is_specialized = false); _STLP_STATIC_CONSTANT(bool, is_signed = false); _STLP_STATIC_CONSTANT(bool, is_integer = false); _STLP_STATIC_CONSTANT(bool, is_exact = false); _STLP_STATIC_CONSTANT(bool, has_infinity = false); _STLP_STATIC_CONSTANT(bool, has_quiet_NaN = false); _STLP_STATIC_CONSTANT(bool, has_signaling_NaN = false); _STLP_STATIC_CONSTANT(bool, has_denorm_loss = false); _STLP_STATIC_CONSTANT(bool, is_iec559 = false); _STLP_STATIC_CONSTANT(bool, is_bounded = false); _STLP_STATIC_CONSTANT(bool, is_modulo = false); _STLP_STATIC_CONSTANT(bool, traps = false); _STLP_STATIC_CONSTANT(bool, tinyness_before = false); static __number _STLP_CALL epsilon() _STLP_NOTHROW { return __number(); } static __number _STLP_CALL round_error() _STLP_NOTHROW { return __number(); } static __number _STLP_CALL infinity() _STLP_NOTHROW { return __number(); } static __number _STLP_CALL quiet_NaN() _STLP_NOTHROW { return __number(); } static __number _STLP_CALL signaling_NaN() _STLP_NOTHROW { return __number(); } static __number _STLP_CALL denorm_min() _STLP_NOTHROW { return __number(); }};// Base class for integers.#ifdef _STLP_LIMITED_DEFAULT_TEMPLATES# ifdef _STLP_LONG_LONG# define _STLP_LIMITS_MIN_TYPE _STLP_LONG_LONG# define _STLP_LIMITS_MAX_TYPE unsigned _STLP_LONG_LONG# else# define _STLP_LIMITS_MIN_TYPE long# define _STLP_LIMITS_MAX_TYPE unsigned long# endif#else# define _STLP_LIMITS_MIN_TYPE _Int# define _STLP_LIMITS_MAX_TYPE _Int#endif /* _STLP_LIMITED_DEFAULT_TEMPLATES */template <class _Int, _STLP_LIMITS_MIN_TYPE __imin, _STLP_LIMITS_MAX_TYPE __imax, int __idigits, bool __ismod>class _Integer_limits : public _Numeric_limits_base<_Int> {public: static _Int (_STLP_CALL min) () _STLP_NOTHROW { return (_Int)__imin; } static _Int (_STLP_CALL max) () _STLP_NOTHROW { return (_Int)__imax; } _STLP_STATIC_CONSTANT(int, digits = (__idigits < 0) ? ((int)((sizeof(_Int) * (CHAR_BIT))) - ((__imin == 0) ? 0 : 1)) : (__idigits)); _STLP_STATIC_CONSTANT(int, digits10 = (digits * 301UL) / 1000); _STLP_STATIC_CONSTANT(int, radix = 2); _STLP_STATIC_CONSTANT(bool, is_specialized = true); _STLP_STATIC_CONSTANT(bool, is_signed = (__imin != 0)); _STLP_STATIC_CONSTANT(bool, is_integer = true); _STLP_STATIC_CONSTANT(bool, is_exact = true); _STLP_STATIC_CONSTANT(bool, is_bounded = true); _STLP_STATIC_CONSTANT(bool, is_modulo = __ismod);};// Base class for floating-point numbers.template <class __number, int __Digits, int __Digits10, int __MinExp, int __MaxExp, int __MinExp10, int __MaxExp10, bool __IsIEC559, float_denorm_style __DenormStyle, float_round_style __RoundStyle>class _Floating_limits : public _Numeric_limits_base<__number> {public: _STLP_STATIC_CONSTANT(int, digits = __Digits); _STLP_STATIC_CONSTANT(int, digits10 = __Digits10); _STLP_STATIC_CONSTANT(int, radix = FLT_RADIX); _STLP_STATIC_CONSTANT(int, min_exponent = __MinExp); _STLP_STATIC_CONSTANT(int, max_exponent = __MaxExp); _STLP_STATIC_CONSTANT(int, min_exponent10 = __MinExp10); _STLP_STATIC_CONSTANT(int, max_exponent10 = __MaxExp10); _STLP_STATIC_CONSTANT(float_denorm_style, has_denorm = __DenormStyle); _STLP_STATIC_CONSTANT(float_round_style, round_style = __RoundStyle); _STLP_STATIC_CONSTANT(bool, is_specialized = true); _STLP_STATIC_CONSTANT(bool, is_signed = true); _STLP_STATIC_CONSTANT(bool, has_infinity = true);#if (!defined (_STLP_MSVC) || (_STLP_MSVC > 1300)) && \ (!defined (__BORLANDC__) || (__BORLANDC__ >= 0x590)) && \ (!defined (_CRAY) || defined (_CRAYIEEE)) _STLP_STATIC_CONSTANT(bool, has_quiet_NaN = true); _STLP_STATIC_CONSTANT(bool, has_signaling_NaN = true);#else _STLP_STATIC_CONSTANT(bool, has_quiet_NaN = false); _STLP_STATIC_CONSTANT(bool, has_signaling_NaN = false);#endif _STLP_STATIC_CONSTANT(bool, is_iec559 = __IsIEC559 && has_infinity && has_quiet_NaN && has_signaling_NaN && (has_denorm == denorm_present)); _STLP_STATIC_CONSTANT(bool, has_denorm_loss = false); _STLP_STATIC_CONSTANT(bool, is_bounded = true); _STLP_STATIC_CONSTANT(bool, traps = true); _STLP_STATIC_CONSTANT(bool, tinyness_before = false);};_STLP_MOVE_TO_STD_NAMESPACE// Class numeric_limits// The unspecialized class.template<class _Tp>class numeric_limits : public _STLP_PRIV _Numeric_limits_base<_Tp> {};// Specializations for all built-in integral types.#if !defined (_STLP_NO_BOOL)_STLP_TEMPLATE_NULLclass numeric_limits<bool> : public _STLP_PRIV _Integer_limits<bool, false, true, 1, false>{};#endif /* _STLP_NO_BOOL */_STLP_TEMPLATE_NULLclass numeric_limits<char> : public _STLP_PRIV _Integer_limits<char, CHAR_MIN, CHAR_MAX, -1, true>{};#if !defined (_STLP_NO_SIGNED_BUILTINS)_STLP_TEMPLATE_NULLclass numeric_limits<signed char> : public _STLP_PRIV _Integer_limits<signed char, SCHAR_MIN, SCHAR_MAX, -1, true>{};#endif_STLP_TEMPLATE_NULLclass numeric_limits<unsigned char> : public _STLP_PRIV _Integer_limits<unsigned char, 0, UCHAR_MAX, -1, true>{};#if !(defined (_STLP_NO_WCHAR_T) || defined (_STLP_WCHAR_T_IS_USHORT))_STLP_TEMPLATE_NULLclass numeric_limits<wchar_t> : public _STLP_PRIV _Integer_limits<wchar_t, WCHAR_MIN, WCHAR_MAX, -1, true>{};#endif_STLP_TEMPLATE_NULLclass numeric_limits<short> : public _STLP_PRIV _Integer_limits<short, SHRT_MIN, SHRT_MAX, -1, true>{};_STLP_TEMPLATE_NULLclass numeric_limits<unsigned short> : public _STLP_PRIV _Integer_limits<unsigned short, 0, USHRT_MAX, -1, true>{};#if defined (__xlC__) && (__xlC__ == 0x500)# undef INT_MIN# define INT_MIN -2147483648#endif_STLP_TEMPLATE_NULLclass numeric_limits<int> : public _STLP_PRIV _Integer_limits<int, INT_MIN, INT_MAX, -1, true>{};_STLP_TEMPLATE_NULLclass numeric_limits<unsigned int> : public _STLP_PRIV _Integer_limits<unsigned int, 0, UINT_MAX, -1, true>{};_STLP_TEMPLATE_NULLclass numeric_limits<long> : public _STLP_PRIV _Integer_limits<long, LONG_MIN, LONG_MAX, -1, true>{};_STLP_TEMPLATE_NULLclass numeric_limits<unsigned long> : public _STLP_PRIV _Integer_limits<unsigned long, 0, ULONG_MAX, -1, true>{};#if defined (_STLP_LONG_LONG)# if defined (_STLP_MSVC) || defined (__BORLANDC__)# define LONGLONG_MAX 0x7fffffffffffffffi64
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?