template<class T>
TypeTraits struct
Traits class for numeric types.
Contents
- Reference
Traits classes are usable for detecting type features at compile time without the need for repeated code such as method overloading or template specialization for given types.
Public types
- using FloatingPointType = U
- Corresponding floating-point type for normalization.
Public static functions
- static auto name() -> const char* constexpr
- Type name.
- static auto epsilon() -> T constexpr
- Epsilon value for fuzzy compare.
- static auto equals(T a, T b) -> bool
- Fuzzy compare.
- static auto equalsZero(T a, T magnitude) -> bool
- Fuzzy compare to zero with magnitude.
Typedef documentation
template<class T>
typedef U Magnum:: Math:: TypeTraits<T>:: FloatingPointType
Corresponding floating-point type for normalization.
If the type is not already floating-point, defines smallest larger floating-point type.
Function documentation
template<class T>
static const char* Magnum:: Math:: TypeTraits<T>:: name() constexpr
Type name.
Returns a string representation of type name, such as "UnsignedInt"
for UnsignedInt.
template<class T>
static T Magnum:: Math:: TypeTraits<T>:: epsilon() constexpr
Epsilon value for fuzzy compare.
Returns minimal difference between numbers to be considered inequal. Returns 1 for integer types and reasonably small value for floating-point types. Not implemented for arbitrary types.
template<class T>
static bool Magnum:: Math:: TypeTraits<T>:: equalsZero(T a,
T magnitude)
Fuzzy compare to zero with magnitude.
Uses fuzzy compare for floating-point types (using epsilon() value), pure equality comparison everywhere else. Use this function when comparing e.g. a calculated nearly-zero difference with zero, knowing the magnitude of original values so the epsilon can be properly scaled. In other words, the following lines are equivalent:
Float a, b; Math::TypeTraits<Float>::equals(a, b); Math::TypeTraits<Float>::equalsZero(a - b, Math::max(Math::abs(a), Math::abs(b)));