31 #if defined(NumberTraits_RECURSES)
32 #error Recursive header files inclusion detected in NumberTraits.h
33 #else // defined(NumberTraits_RECURSES)
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>
552 #endif // !defined NumberTraits_h
554 #undef NumberTraits_RECURSES
555 #endif // else defined(NumberTraits_RECURSES)
mpz_class BigInteger
Multi-precision integer with GMP implementation.
typename BoolToTag< NL::is_integer >::type IsIntegral
Is the number of integral type.
static constexpr ReturnType zero() noexcept
Return the zero of this integer.
static constexpr ReturnType one() noexcept
Return the one of this integer.
static SignEnum isSigned()
Return the sign type of the number.
DGtal::BigInteger UnsignedVersion
Alias to the unsigned version of a BigInteger (aka a BigInteger).
static BoundEnum isBounded() noexcept
Return the bounding type of the number.
T SignedVersion
Alias to the signed version of the number type.
Aim: The traits class for all models of Cinteger.
static SignEnum isSigned() noexcept
Return the sign type of the number.
static const DGtal::BigInteger ZERO
Constant Zero.
static double castToDouble(const DGtal::BigInteger &aT) noexcept
Cast method to double (for I/O or board export uses only).
T SignedVersion
Alias to the signed version of a floating-point type (aka itself).
boost::int32_t int32_t
signed 32-bit integer.
static const T ZERO
Constant Zero.
static constexpr double castToDouble(const T &aT) noexcept
Cast method to double (for I/O or board export uses only).
static bool odd(ParamType aT)
Check the parity of a number.
static constexpr T ZERO
Constant Zero.
TagUnknown IsUnsigned
Is the number unsigned.
T ReturnType
Alias to the type that should be used as return type.
TagUnknown IsSigned
Is the number signed.
static constexpr bool even(typename NTIF::ParamType aT) noexcept
Check the parity of a number.
SignEnum
Sign type 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.
T ReturnType
Alias to the type that should be used as return type.
static BoundEnum isBounded()
Return the bounding type of the number.
static ReturnType zero() noexcept
Return the zero of this integer.
typename BoolToTag< NL::is_signed >::type IsSigned
Is the number signed.
typename BoolToTag< NL::is_bounded >::type IsBounded
Is the number bounded.
BoundEnum
Bounding type of a number.
static constexpr unsigned int digits() noexcept
Return the number of significant binary digits for this type of number.
static bool odd(ParamType aT) noexcept
Check the parity of a number.
NumberTraits common part for fundamental integer and floating-point types.
typename details::NumberTraitsImplFundamental< T > NTIF
Internal type alias to avoid repetitions.
TagTrue IsUnsigned
A BigInteger can be signed and unsigned.
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::BigInteger ReturnType
Alias to the type that should be used as return type.
static ReturnType one()
Return the one of this integer.
Aim: The traits class for all models of Cinteger (implementation)
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 SignEnum isSigned() noexcept
Return the sign type of the number.
static constexpr bool even(ParamType aT) noexcept
Check the parity of a number.
static DGtal::int64_t castToInt64_t(const T &aT)
Cast method to DGtal::int64_t (for I/O or board export uses only).
TagTrue IsSpecialized
Is that a number type with specific traits.
TagTrue IsIntegral
A BigInteger is of integral type.
static ReturnType min() noexcept
Return the minimum possible value (trigger an error since BitInteger is unbounded).
typename std::make_unsigned< T >::type UnsignedVersion
Alias to the unsigned version of the number type.
static constexpr bool odd(ParamType aT) noexcept
Check the parity of a number.
static ReturnType max()
Return the maximum possible value for this type of integer or ZERO if not bounded or unknown.
TagUnknown IsIntegral
Is the number of integral type.
T UnsignedVersion
Alias to the unsigned version of the number type.
std::numeric_limits< T > NL
Type alias to std::numeric_limits.
static unsigned int digits()
Return the number of significant binary digits for this integer type, or 0 if unbounded or unknown.
static constexpr bool odd(typename NTIF::ParamType aT) noexcept
Check the parity of a number.
typename BoolToTag<!NL::is_signed >::type IsUnsigned
Is the number unsigned.
static double castToDouble(const T &aT)
Cast method to double (for I/O or board export uses only).
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).
TagFalse IsBounded
A BigInteger is not bounded.
static ReturnType one() noexcept
Return the one of this integer.
static bool even(ParamType aT) noexcept
Check the parity of a number.
static constexpr ReturnType min() noexcept
Return the minimum possible value for this type of number.
T UnsignedVersion
Alias to the unsigned version of a floating-point type (aka itself).
static ReturnType min()
Return the minimum possible value for this type of integer or ONE if not bounded or unknown.
DGtal::BigInteger SignedVersion
Alias to the signed version of a BigInteger (aka a BigInteger).
static constexpr T ONE
Constant One.
boost::int64_t int64_t
signed 94-bit integer.
TagFalse IsSpecialized
Is that a number type with specific traits.
static const DGtal::BigInteger ONE
Constant One.
static ReturnType max() noexcept
Return the maximum possible value (trigger an error since BitInteger is unbounded).
static constexpr ReturnType max() noexcept
Return the maximum possible value for this type of number.
static unsigned int digits() noexcept
Return the number of significant binary digits (trigger an error since BitInteger is unbounded).
static const T ONE
Constant One.
TagTrue IsSigned
a BigInteger can be signed and unsigned.
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.
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 bool even(ParamType aT)
Check the parity of a number.
Convert a boolean to the corresponding DGtal tag (TagTrue or TagFalse).
TagUnknown IsBounded
Is the number bounded.
static constexpr BoundEnum isBounded() noexcept
Return the bounding type of the number.
typename std::make_signed< T >::type SignedVersion
Alias to the signed version of the number type.