📄 limits
字号:
// -*- C++ -*-
/***************************************************************************
*
* limits - Declarations for the C++ Standard Library class numeric_limits
*
* $Id: limits,v 1.6.2.2 2004/10/18 13:30:37 sdouglas Exp $
*
***************************************************************************
*
* Copyright (c) 1994-2001 Rogue Wave Software, Inc. All Rights Reserved.
*
* This computer software is owned by Rogue Wave Software, Inc. and is
* protected by U.S. copyright laws and other laws and by international
* treaties. This computer software is furnished by Rogue Wave Software,
* Inc. pursuant to a written license agreement and may be used, copied,
* transmitted, and stored only in accordance with the terms of such
* license and with the inclusion of the above copyright notice. This
* computer software or any other copies thereof may not be provided or
* otherwise made available to any other person.
*
* U.S. Government Restricted Rights. This computer software is provided
* with Restricted Rights. Use, duplication, or disclosure by the
* Government is subject to restrictions as set forth in subparagraph (c)
* (1) (ii) of The Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
* Commercial Computer Software--Restricted Rights at 48 CFR 52.227-19,
* as applicable. Manufacturer is Rogue Wave Software, Inc., 5500
* Flatiron Parkway, Boulder, Colorado 80301 USA.
*
**************************************************************************/
#ifndef _RWSTD_LIMITS_INCLUDED
#define _RWSTD_LIMITS_INCLUDED
#include <rw/_defs.h>
#include <rw/_math.h>
#include _RWSTD_CFLOAT
#include _RWSTD_CLIMITS
#include _RWSTD_IEEEFP
/**************************************************************************
*
* Assumptions made in this implementation:
*
* 1) numeric_limits<T>::digits is 1 for bool and is computed as
* (CHAR_BIT * sizeof (T) - numeric_limits<T>::is_signed for
* all native integral T
*
* 2) numeric_limits<T>::radix is the same (2 by default) for all
* specializations of native integral T
*
* 3) numeric_limits<T>::is_modulo is true if numeric_limits<T>::max()
* + 1 == numeric_limits<T>::min for all specializations
* of native integral T
*
* 4) numeric_limts<T>::traps == false for all native integral T
*
* 5) OEM vendors are expected to provide correct values where supplied
* values (VENDOR) differ from those defined by the implementation
*
**************************************************************************/
#define _RWSTD_HAS_INFINITY true // VENDOR
#define _RWSTD_HAS_QUIET_NAN true // VENDOR
#ifdef __FP_IEEE
#define _RWSTD_IS_IEC559 true // VENDOR
#define _RWSTD_HAS_DENORM_LOSS true // VENDOR
#define _RWSTD_HAS_DENORM denorm_present // VENDOR
#define _RWSTD_FLT_DENORM_MIN 1.4012984643248171e-45F // VENDOR
#define _RWSTD_DBL_DENORM_MIN 4.9406564584124654e-324 // VENDOR
#define _RWSTD_LDBL_DENORM_MIN 4.9406564584124654e-324L // VENDOR
#else
#define _RWSTD_IS_IEC559 false // VENDOR
#define _RWSTD_HAS_DENORM_LOSS false // VENDOR
#define _RWSTD_HAS_DENORM denorm_absent // VENDOR
#define _RWSTD_FLT_DENORM_MIN FLT_MIN // VENDOR
#define _RWSTD_DBL_DENORM_MIN DBL_MIN // VENDOR
#define _RWSTD_LDBL_DENORM_MIN LDBL_MIN // VENDOR
#endif
#ifdef __FP_FENV_ROUNDING
/* We only include the relevant parts of fenv.h to avoid polluting the user's
* namespace.
#include <fenv.h>
*/
extern "C" unsigned __ieee_status(unsigned, unsigned);
#define __FE_IEEE_ROUND_MASK (0x00C00000)
#define __FE_IEEE_ROUND_TONEAREST (0x00000000)
/* end of <fenv.h> */
// rounding can be changed at runtime
#define _RWSTD_ROUND_TONEAREST ((__ieee_status(0,0) & __FE_IEEE_ROUND_MASK) == __FE_IEEE_ROUND_TONEAREST)
#define _RWSTD_FLT_ROUND_ERROR (_RWSTD_ROUND_TONEAREST ? 0.5F : 1.0F)
#define _RWSTD_DBL_ROUND_ERROR (_RWSTD_ROUND_TONEAREST ? 0.5 : 1.0)
#define _RWSTD_LDBL_ROUND_ERROR (_RWSTD_ROUND_TONEAREST ? 0.5L : 1.0L)
#else
// rounding is fixed to round to nearest
#define _RWSTD_FLT_ROUND_ERROR 0.5F
#define _RWSTD_DBL_ROUND_ERROR 0.5
#define _RWSTD_LDBL_ROUND_ERROR 0.5L
#endif
// signalling NAN
#define _RWSTD_HAS_SIG_NAN true // VENDOR
#undef _RWSTD_STATIC_INIT
#undef _RWSTD_STATIC_DEF
#ifndef _RWSTD_NO_STATIC_CONST_MEMBER_INIT
# ifndef _RWSTD_DEFINE_EXPORTS
# define _RWSTD_STATIC_INIT(name, value) name = (value)
# else
# define _RWSTD_STATIC_INIT(name, value) name
# endif
#else
# ifndef _RWSTD_DEFINE_EXPORTS
# define _RWSTD_STATIC_INIT(name, value) name
# else
# define _RWSTD_STATIC_INIT(name, value) name = (value)
# endif
#endif // _RWSTD_NO_STATIC_CONST_MEMBER_INIT
#undef _RWSTD_CLASS_BEGIN
#undef _RWSTD_CLASS_END
#undef _RWSTD_TYPEDEF
#undef _RWSTD_STATIC
#undef _RWSTD_STATIC_ROUNDS
#undef _RWSTD_STATIC_FUN
#ifndef _RWSTD_DEFINE_EXPORTS
// declarations - expanded in every translation unit
// that #includes <limits>
# define _RWSTD_CLASS_BEGIN(name) name { public:
# define _RWSTD_CLASS_END };
# define _RWSTD_TYPEDEF(def) typedef def;
# define _RWSTD_STATIC(ignore, type, name, value) \
static const type \
_RWSTD_STATIC_INIT (name, value)
# ifndef _RWSTD_NO_CONST_FLT_ROUNDS
# define _RWSTD_STATIC_ROUNDS(ignore, type, name, value) \
_RWSTD_STATIC (ignore, type, name, \
_RWSTD_STATIC_CAST (float_round_style, value))
# else
# define _RWSTD_STATIC_ROUNDS(ign1, type, name, ign2) \
static const type _RWSTD_EXPORT name
# endif // _RWSTD_NO_CONST_FLT_ROUNDS
# define _RWSTD_STATIC_FUN(type, name, value) \
static type name () _THROWS (()) { return value; }
#else // defined (_RWSTD_DEFINE_EXPORTS)
// definitions - expanded in a single translation unit that defines
// static const data members outside of each numeric_limits<> specialization
# define _RWSTD_CLASS_BEGIN(ignore)
# define _RWSTD_CLASS_END
# define _RWSTD_TYPEDEF(ignore)
# define _RWSTD_STATIC(limtype, type, name, value) \
const type _RWSTD_STATIC_INIT (numeric_limits<limtype>::name, value)
# ifndef _RWSTD_NO_CONST_FLT_ROUNDS
# define _RWSTD_STATIC_ROUNDS(limtype, type, name, value) \
_RWSTD_STATIC (limtype, type, name, \
_RWSTD_STATIC_CAST (float_round_style, value))
# else
# define _RWSTD_STATIC_ROUNDS(limtype, type, name, value) \
const type numeric_limits<limtype>::name = \
_RWSTD_STATIC_CAST (float_round_style, value)
# endif // _RWSTD_NO_CONST_FLT_ROUNDS
# define _RWSTD_STATIC_FUN(ign1, ign2, ign3)
# define _RWSTD_STATIC_FUN_HEXFLOAT(ign1, ign2, ign3)
# define _RWSTD_STATIC_FUN_HEXDOUBLE(ign1, ign2, ign3, ign4)
#endif // _RWSTD_DEFINE_EXPORTS
// 18.2.1.2, p6 - 7
#define _RWSTD_DIGITS(type, min, max) \
(1 == (max) ? 1 : (CHAR_BIT * sizeof (type) - ((min) != 0)))
// 18.2.1.2, p9
#define _RWSTD_DIGITS10(digits) (((digits) * 301) / 1000)
#undef max
#undef min
#undef _RWSTD_LIMITS_BODY
#define _RWSTD_LIMITS_BODY(type, conv_type, cpfx) \
_RWSTD_STATIC (type, bool, is_specialized, true); \
\
_RWSTD_STATIC_FUN (type, min, cpfx##_MIN) \
_RWSTD_STATIC_FUN (type, max, cpfx##_MAX) \
\
_RWSTD_STATIC (type, bool, is_signed, cpfx##_MIN != 0); \
_RWSTD_STATIC (type, bool, is_integer, true); \
_RWSTD_STATIC (type, bool, is_exact, true); \
\
_RWSTD_STATIC (type, int, digits, \
_RWSTD_DIGITS (type, cpfx##_MIN, cpfx##_MAX)); \
\
/* spelled out to work around a bug in IBM xlC 5.0 */ \
_RWSTD_STATIC (type, int, digits10, \
_RWSTD_DIGITS10 (_RWSTD_DIGITS (type, cpfx##_MIN, \
cpfx##_MAX))); \
\
_RWSTD_STATIC (type, int, radix, 2); /* VENDOR */ \
\
_RWSTD_STATIC_FUN (type, epsilon, 0) \
_RWSTD_STATIC_FUN (type, round_error, 0) \
\
_RWSTD_STATIC (type, int, min_exponent, 0); \
_RWSTD_STATIC (type, int, min_exponent10, 0); \
_RWSTD_STATIC (type, int, max_exponent, 0); \
_RWSTD_STATIC (type, int, max_exponent10, 0); \
\
_RWSTD_STATIC (type, bool, has_infinity, false); \
_RWSTD_STATIC (type, bool, has_quiet_NaN, false); \
_RWSTD_STATIC (type, bool, has_signaling_NaN, false); \
_RWSTD_STATIC (type, float_denorm_style, has_denorm, denorm_absent); \
_RWSTD_STATIC (type, bool, has_denorm_loss, false); \
\
_RWSTD_STATIC_FUN (type, infinity, 0) \
_RWSTD_STATIC_FUN (type, quiet_NaN, 0) \
_RWSTD_STATIC_FUN (type, signaling_NaN, 0) \
_RWSTD_STATIC_FUN (type, denorm_min, 0) \
\
_RWSTD_STATIC (type, bool, is_iec559, false); \
_RWSTD_STATIC (type, bool, is_bounded, true); \
_RWSTD_STATIC (type, bool, is_modulo, 1 != cpfx##_MAX); \
\
_RWSTD_STATIC (type, bool, traps, false); \
_RWSTD_STATIC (type, bool, tinyness_before, false); \
_RWSTD_STATIC (type, float_round_style, round_style, round_toward_zero);\
\
/* extension: type converts to without loss of data */ \
_RWSTD_TYPEDEF (conv_type _C_convertible)
#undef _RWSTD_SPECIALIZE_LIMITS
#define _RWSTD_SPECIALIZE_LIMITS(type, conv_type, cpfx) \
_RWSTD_CLASS_BEGIN (_RWSTD_SPECIALIZED_CLASS \
class _RWSTD_EXPORT numeric_limits<type>) \
_RWSTD_LIMITS_BODY (type, conv_type, cpfx) \
_RWSTD_CLASS_END
#ifndef _RWSTD_LIMITS_TEMPLATE_DEFINED
#define _RWSTD_LIMITS_TEMPLATE_DEFINED
_RWSTD_NAMESPACE_BEGIN (std)
enum 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
};
template <class _TypeT>
class numeric_limits
{
public:
// static consts below must be initialized in class so that
// they can be used where const expressions are required (such
// as in template parameters)
_RWSTD_STATIC_CONST (bool, is_specialized = false);
static _TypeT min () _THROWS (()) { return 0; }
static _TypeT max () _THROWS (()) { return 0; }
_RWSTD_STATIC_CONST (int, digits = 0);
_RWSTD_STATIC_CONST (int, digits10 = 0);
_RWSTD_STATIC_CONST (bool, is_signed = false);
_RWSTD_STATIC_CONST (bool, is_integer = false);
_RWSTD_STATIC_CONST (bool, is_exact = false);
_RWSTD_STATIC_CONST (int, radix = 0);
static _TypeT epsilon () _THROWS (()) { return 0; }
static _TypeT round_error () _THROWS (()) { return 0; }
_RWSTD_STATIC_CONST (int, min_exponent = 0);
_RWSTD_STATIC_CONST (int, min_exponent10 = 0);
_RWSTD_STATIC_CONST (int, max_exponent = 0);
_RWSTD_STATIC_CONST (int, max_exponent10 = 0);
_RWSTD_STATIC_CONST (bool, has_infinity = false);
_RWSTD_STATIC_CONST (bool, has_quiet_NaN = false);
_RWSTD_STATIC_CONST (bool, has_signaling_NaN = false);
_RWSTD_STATIC_CONST (float_denorm_style, has_denorm = denorm_absent);
_RWSTD_STATIC_CONST (bool, has_denorm_loss = false);
static _TypeT infinity () _THROWS (()) { return 0; }
static _TypeT quiet_NaN () _THROWS (()) { return 0; }
static _TypeT signaling_NaN () _THROWS (()) { return 0; }
static _TypeT denorm_min () _THROWS (()) { return 0; }
_RWSTD_STATIC_CONST (bool, is_iec559 = false);
_RWSTD_STATIC_CONST (bool, is_bounded = false);
_RWSTD_STATIC_CONST (bool, is_modulo = false);
_RWSTD_STATIC_CONST (bool, traps = false);
_RWSTD_STATIC_CONST (bool, tinyness_before = false);
_RWSTD_STATIC_CONST (float_round_style, round_style = round_toward_zero);
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -