31#if defined(NumberTraits_RECURSES)
32#error Recursive header files inclusion detected in NumberTraits.h
35#define NumberTraits_RECURSES
37#if !defined NumberTraits_h
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);
154 static inline constexpr
166 return static_cast<double>(aT);
199 template <
bool Value>
212 template <
typename T>
216 using NL = std::numeric_limits<T>;
231 using ParamType =
typename boost::call_traits<T>::param_type;
234 static constexpr T
ZERO = T(0);
237 static constexpr T
ONE = T(1);
240 static inline constexpr
247 static inline constexpr
254 static inline constexpr
261 static inline constexpr
268 static inline constexpr
271 return static_cast<unsigned int>(NL::digits);
278 static inline constexpr
288 static inline constexpr
298 static inline constexpr
308 static inline constexpr
318 static inline constexpr
321 return static_cast<double>(aT);
329 static inline constexpr
340 static inline constexpr
355 template <
typename T>
371 static inline constexpr
372 bool even(
typename NTIF::ParamType aT )
noexcept
374 return ( aT & NTIF::ONE ) == NTIF::ZERO;
382 static inline constexpr
383 bool odd(
typename NTIF::ParamType aT )
noexcept
385 return ( aT & NTIF::ONE ) != NTIF::ZERO;
391 template <
typename T>
399#ifdef WITH_BIGINTEGER
406 template <
typename Enable>
422 typedef typename boost::call_traits<BigInteger>::param_type
ParamType;
448 FATAL_ERROR_MSG(
false,
"UnBounded interger type does not support min() function");
456 FATAL_ERROR_MSG(
false,
"UnBounded interger type does not support max() function");
464 FATAL_ERROR_MSG(
false,
"UnBounded interger type does not support digits() function");
527 return mpz_even_p( aT.get_mpz_t() );
538 return mpz_odd_p( aT.get_mpz_t() );
561 template <
typename T>
569 template<
class A,
class B>
585#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::uint64_t uint64_t
unsigned 64-bit integer.
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 DGtal::uint64_t castToUInt64_t(const DGtal::BigInteger &aT) noexcept
Cast method to DGtal::uint64_t (for I/O or board export uses only).
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.
static constexpr DGtal::uint64_t castToUInt64_t(const T &aT) noexcept
Cast method to DGtal::uint64_t (for I/O or board export uses only).
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.
static constexpr DGtal::uint64_t castToUInt64_t(const T &aT) noexcept
Cast method to DGtal::uint64_t (for I/O or board export uses only).
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.