31 #if defined(NumberTraits_RECURSES)
32 #error Recursive header files inclusion detected in NumberTraits.h
35 #define NumberTraits_RECURSES
37 #if !defined NumberTraits_h
39 #define NumberTraits_h
43 #include <type_traits>
46 #include <boost/call_traits.hpp>
48 #include "DGtal/base/Common.h"
80 template <
typename T,
typename Enable =
void>
96 typedef typename boost::call_traits<T>::param_type
ParamType;
103 static const T
ONE = T(1);
156 return static_cast<double>(aT);
189 template <
bool Value>
202 template <
typename T>
206 using NL = std::numeric_limits<T>;
221 using ParamType =
typename boost::call_traits<T>::param_type;
224 static constexpr T
ZERO = T(0);
227 static constexpr T
ONE = T(1);
230 static inline constexpr
237 static inline constexpr
244 static inline constexpr
251 static inline constexpr
258 static inline constexpr
261 return static_cast<unsigned int>(NL::digits);
268 static inline constexpr
278 static inline constexpr
288 static inline constexpr
298 static inline constexpr
301 return static_cast<double>(aT);
309 static inline constexpr
320 static inline constexpr
335 template <
typename T>
351 static inline constexpr
352 bool even(
typename NTIF::ParamType aT ) noexcept
354 return ( aT & NTIF::ONE ) == NTIF::ZERO;
362 static inline constexpr
363 bool odd(
typename NTIF::ParamType aT ) noexcept
365 return ( aT & NTIF::ONE ) != NTIF::ZERO;
371 template <
typename T>
372 struct NumberTraitsImpl<T, typename std::enable_if<std::is_floating_point<T>::value>::type>
379 #ifdef WITH_BIGINTEGER
386 template <
typename Enable>
402 typedef typename boost::call_traits<BigInteger>::param_type
ParamType;
428 FATAL_ERROR_MSG(
false,
"UnBounded interger type does not support min() function");
436 FATAL_ERROR_MSG(
false,
"UnBounded interger type does not support max() function");
444 FATAL_ERROR_MSG(
false,
"UnBounded interger type does not support digits() function");
496 return mpz_even_p( aT.get_mpz_t() );
507 return mpz_odd_p( aT.get_mpz_t() );
530 template <
typename T>
538 template<
class A,
class B>
554 #undef NumberTraits_RECURSES
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
BoundEnum
Bounding type of a number.
SignEnum
Sign type of a number.
boost::int32_t int32_t
signed 32-bit integer.
mpz_class BigInteger
Multi-precision integer with GMP implementation.
static bool odd(ParamType aT) noexcept
Check the parity of a number.
boost::call_traits< BigInteger >::param_type ParamType
Defines a type that represents the "best" way to pass a parameter of type T to a function.
static ReturnType max() noexcept
Return the maximum possible value (trigger an error since BitInteger is unbounded).
TagFalse IsBounded
A BigInteger is not bounded.
static unsigned int digits() noexcept
Return the number of significant binary digits (trigger an error since BitInteger is unbounded).
TagTrue IsSpecialized
Is that a number type with specific traits.
static bool even(ParamType aT) noexcept
Check the parity of a number.
TagTrue IsUnsigned
A BigInteger can be signed and unsigned.
TagTrue IsSigned
a BigInteger can be signed and unsigned.
static ReturnType min() noexcept
Return the minimum possible value (trigger an error since BitInteger is unbounded).
static SignEnum isSigned() noexcept
Return the sign type of the number.
TagTrue IsIntegral
A BigInteger is of integral type.
DGtal::BigInteger UnsignedVersion
Alias to the unsigned version of a BigInteger (aka a BigInteger).
static ReturnType zero() noexcept
Return the zero of this integer.
DGtal::BigInteger ReturnType
Alias to the type that should be used as return type.
static DGtal::int64_t castToInt64_t(const DGtal::BigInteger &aT) noexcept
Cast method to DGtal::int64_t (for I/O or board export uses only).
static double castToDouble(const DGtal::BigInteger &aT) noexcept
Cast method to double (for I/O or board export uses only).
static const DGtal::BigInteger ONE
Constant One.
static BoundEnum isBounded() noexcept
Return the bounding type of the number.
static const DGtal::BigInteger ZERO
Constant Zero.
static ReturnType one() noexcept
Return the one of this integer.
DGtal::BigInteger SignedVersion
Alias to the signed version of a BigInteger (aka a BigInteger).
T UnsignedVersion
Alias to the unsigned version of a floating-point type (aka itself).
T SignedVersion
Alias to the signed version of a floating-point type (aka itself).
typename std::make_signed< T >::type SignedVersion
Alias to the signed version of the number type.
static constexpr bool even(typename NTIF::ParamType aT) noexcept
Check the parity of a number.
static constexpr bool odd(typename NTIF::ParamType aT) noexcept
Check the parity of a number.
typename details::NumberTraitsImplFundamental< T > NTIF
Internal type alias to avoid repetitions.
typename std::make_unsigned< T >::type UnsignedVersion
Alias to the unsigned version of the number type.
Aim: The traits class for all models of Cinteger (implementation)
T UnsignedVersion
Alias to the unsigned version of the number type.
static DGtal::int64_t castToInt64_t(const T &aT)
Cast method to DGtal::int64_t (for I/O or board export uses only).
static ReturnType min()
Return the minimum possible value for this type of integer or ONE if not bounded or unknown.
static const T ONE
Constant One.
TagUnknown IsBounded
Is the number bounded.
static ReturnType max()
Return the maximum possible value for this type of integer or ZERO if not bounded or unknown.
static bool even(ParamType aT)
Check the parity of a number.
static const T ZERO
Constant Zero.
static ReturnType one()
Return the one of this integer.
T SignedVersion
Alias to the signed version of the number type.
TagUnknown IsUnsigned
Is the number unsigned.
static BoundEnum isBounded()
Return the bounding type of the number.
TagUnknown IsSigned
Is the number signed.
static unsigned int digits()
Return the number of significant binary digits for this integer type, or 0 if unbounded or unknown.
static SignEnum isSigned()
Return the sign type of the number.
static ReturnType zero()
Return the zero of this integer.
boost::call_traits< T >::param_type ParamType
Defines a type that represents the "best" way to pass a parameter of type T to a function.
TagFalse IsSpecialized
Is that a number type with specific traits.
TagUnknown IsIntegral
Is the number of integral type.
static bool odd(ParamType aT)
Check the parity of a number.
T ReturnType
Alias to the type that should be used as return type.
static double castToDouble(const T &aT)
Cast method to double (for I/O or board export uses only).
Aim: The traits class for all models of Cinteger.
Convert a boolean to the corresponding DGtal tag (TagTrue or TagFalse).
NumberTraits common part for fundamental integer and floating-point types.
static constexpr ReturnType zero() noexcept
Return the zero of this integer.
typename BoolToTag< NL::is_signed >::type IsSigned
Is the number signed.
typename boost::call_traits< T >::param_type ParamType
Defines a type that represents the "best" way to pass a parameter of type T to a function.
static constexpr T ZERO
Constant Zero.
static constexpr T ONE
Constant One.
static constexpr ReturnType min() noexcept
Return the minimum possible value for this type of number.
static constexpr BoundEnum isBounded() noexcept
Return the bounding type of the number.
static constexpr double castToDouble(const T &aT) noexcept
Cast method to double (for I/O or board export uses only).
static constexpr ReturnType max() noexcept
Return the maximum possible value for this type of number.
static constexpr SignEnum isSigned() noexcept
Return the sign type of the number.
std::numeric_limits< T > NL
Type alias to std::numeric_limits.
typename BoolToTag<!NL::is_signed >::type IsUnsigned
Is the number unsigned.
static constexpr ReturnType one() noexcept
Return the one of this integer.
static constexpr unsigned int digits() noexcept
Return the number of significant binary digits for this type of number.
T ReturnType
Alias to the type that should be used as return type.
static constexpr bool even(ParamType aT) noexcept
Check the parity of a number.
static constexpr bool odd(ParamType aT) noexcept
Check the parity of a number.
static constexpr DGtal::int64_t castToInt64_t(const T &aT) noexcept
Cast method to DGtal::int64_t (for I/O or board export uses only).
typename BoolToTag< NL::is_integer >::type IsIntegral
Is the number of integral type.
typename BoolToTag< NL::is_bounded >::type IsBounded
Is the number bounded.