diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index 4330491e5..5f4bb5cdb 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -51,6 +51,22 @@ support given feature, thus forcing the compilation stop with an error. */ template struct MathTypeTraits { #ifdef DOXYGEN_GENERATING_OUTPUT + /** + * @brief Corresponding numeric type large at least as `int` + * + * Usable e.g. to prevent conversion of `char` to characters when printing + * numeric types to output. + */ + typedef U NumericType; + + /** + * @brief Corresponding floating-point type for normalization + * + * If the type is not already floating-point, defines smallest larger + * floating-point type. + */ + typedef U FloatingPointType; + /** * @brief Epsilon value for fuzzy compare * @@ -95,29 +111,70 @@ template struct MathTypeTraitsFloatingPoint { } }; +template struct MathTypeTraitsLong {}; + +template<> struct MathTypeTraitsLong<8> { + typedef unsigned int UnsignedType; + typedef int Type; +}; + +template<> struct MathTypeTraitsLong<16> { + typedef unsigned long long UnsignedType; + typedef long long Type; +}; + } -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral {}; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral {}; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef unsigned int NumericType; + typedef float FloatingPointType; +}; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef int NumericType; + typedef float FloatingPointType; +}; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral {}; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral {}; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef unsigned int NumericType; + typedef float FloatingPointType; +}; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef int NumericType; + typedef float FloatingPointType; +}; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral {}; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral {}; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef unsigned int NumericType; + typedef double FloatingPointType; +}; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef int NumericType; + typedef double FloatingPointType; +}; -/* long is 32 bits somewhere and 64 bits elsewhere, so it cannot be mapped to - any of them */ -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral {}; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral {}; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef unsigned long long NumericType; + typedef long double FloatingPointType; +}; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef long long NumericType; + typedef long double FloatingPointType; +}; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral {}; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral {}; +/* long is 32 bits somewhere and 64 bits elsewhere */ +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral::Type> {}; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral::Type> {}; template<> struct MathTypeTraits: public Implementation::MathTypeTraitsFloatingPoint { + typedef float NumericType; + typedef float FloatingPointType; + inline constexpr static float epsilon() { return FLOAT_EQUALITY_PRECISION; } }; template<> struct MathTypeTraits: public Implementation::MathTypeTraitsFloatingPoint { + typedef float NumericType; + typedef double FloatingPointType; + inline constexpr static double epsilon() { return DOUBLE_EQUALITY_PRECISION; } }; #endif diff --git a/src/Math/Matrix.h b/src/Math/Matrix.h index 540f46d7b..a3e2609fe 100644 --- a/src/Math/Matrix.h +++ b/src/Math/Matrix.h @@ -260,7 +260,7 @@ template Corrade::Utility::Debug operator<<(Corrade::Utili if(row != 0) debug << ",\n "; for(size_t col = 0; col != size; ++col) { if(col != 0) debug << ", "; - debug << value[col][row]; + debug << typename MathTypeTraits::NumericType(value[col][row]); } } debug << ')'; diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 96b0fe502..bfdb1681f 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -324,7 +324,7 @@ template Corrade::Utility::Debug operator<<(Corrade::Utili debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false); for(size_t i = 0; i != size; ++i) { if(i != 0) debug << ", "; - debug << value[i]; + debug << typename MathTypeTraits::NumericType(value[i]); } debug << ')'; debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, true);