Browse Source

Math: remove pointless Emscripten restrictions in TypeTraits.

Size of long double is now tested in Corrade itself, so no need for any
of this.
pull/459/head
Vladimír Vondruš 6 years ago
parent
commit
70336a6a98
  1. 40
      src/Magnum/Math/Test/TypeTraitsTest.cpp
  2. 25
      src/Magnum/Math/TypeTraits.h

40
src/Magnum/Math/Test/TypeTraitsTest.cpp

@ -37,7 +37,6 @@ namespace Magnum { namespace Math { namespace Test { namespace {
struct TypeTraitsTest: Corrade::TestSuite::Tester { struct TypeTraitsTest: Corrade::TestSuite::Tester {
explicit TypeTraitsTest(); explicit TypeTraitsTest();
void sizeOfLongDouble();
void name(); void name();
void isScalar(); void isScalar();
@ -78,27 +77,25 @@ struct {
Float getStep(Float) const { return aStep; } Float getStep(Float) const { return aStep; }
Double get(Double) const { return b; } Double get(Double) const { return b; }
Double getStep(Double) const { return bStep; } Double getStep(Double) const { return bStep; }
#ifndef CORRADE_TARGET_EMSCRIPTEN
long double get(long double) const { return c; } long double get(long double) const { return c; }
long double getStep(long double) const { return cStep; } long double getStep(long double) const { return cStep; }
#endif
} EqualsZeroData[EqualsZeroDataCount] = { } EqualsZeroData[EqualsZeroDataCount] = {
{"", -3.141592653589793f, 5.0e-5f, -3.141592653589793, 5.0e-14, -3.141592653589793l, {"", -3.141592653589793f, 5.0e-5f, -3.141592653589793, 5.0e-14, -3.141592653589793l,
#if !defined(_MSC_VER) && (!defined(CORRADE_TARGET_ANDROID) || __LP64__) #ifndef CORRADE_LONG_DOUBLE_SAME_AS_DOUBLE
5.0e-17l 5.0e-17l
#else #else
5.0e-14 5.0e-14
#endif #endif
}, },
{"small", 1.0e-6f, 5.0e-6f, -1.0e-15, 5.0e-15, 1.0e-18l, {"small", 1.0e-6f, 5.0e-6f, -1.0e-15, 5.0e-15, 1.0e-18l,
#if !defined(_MSC_VER) && (!defined(CORRADE_TARGET_ANDROID) || __LP64__) #ifndef CORRADE_LONG_DOUBLE_SAME_AS_DOUBLE
5.0e-18l 5.0e-18l
#else #else
5.0e-15 5.0e-15
#endif #endif
}, },
{"large", 12345.0f, 0.2f, 12345678901234.0, 0.2, {"large", 12345.0f, 0.2f, 12345678901234.0, 0.2,
#if !defined(_MSC_VER) && (!defined(CORRADE_TARGET_ANDROID) || __LP64__) #ifndef CORRADE_LONG_DOUBLE_SAME_AS_DOUBLE
-12345678901234567.0l, -12345678901234567.0l,
#else #else
-12345678901234.0, -12345678901234.0,
@ -107,8 +104,7 @@ struct {
}; };
TypeTraitsTest::TypeTraitsTest() { TypeTraitsTest::TypeTraitsTest() {
addTests({&TypeTraitsTest::sizeOfLongDouble, addTests({&TypeTraitsTest::name,
&TypeTraitsTest::name,
&TypeTraitsTest::isScalar, &TypeTraitsTest::isScalar,
&TypeTraitsTest::isVector, &TypeTraitsTest::isVector,
@ -128,10 +124,8 @@ TypeTraitsTest::TypeTraitsTest() {
&TypeTraitsTest::equalsIntegral<Short>, &TypeTraitsTest::equalsIntegral<Short>,
&TypeTraitsTest::equalsIntegral<UnsignedInt>, &TypeTraitsTest::equalsIntegral<UnsignedInt>,
&TypeTraitsTest::equalsIntegral<Int>, &TypeTraitsTest::equalsIntegral<Int>,
#ifndef CORRADE_TARGET_EMSCRIPTEN
&TypeTraitsTest::equalsIntegral<UnsignedLong>, &TypeTraitsTest::equalsIntegral<UnsignedLong>,
&TypeTraitsTest::equalsIntegral<Long>, &TypeTraitsTest::equalsIntegral<Long>,
#endif
&TypeTraitsTest::equalsHalf, &TypeTraitsTest::equalsHalf,
@ -155,37 +149,19 @@ TypeTraitsTest::TypeTraitsTest() {
&TypeTraitsTest::equalsZeroIntegral<Short>, &TypeTraitsTest::equalsZeroIntegral<Short>,
&TypeTraitsTest::equalsZeroIntegral<UnsignedInt>, &TypeTraitsTest::equalsZeroIntegral<UnsignedInt>,
&TypeTraitsTest::equalsZeroIntegral<Int>, &TypeTraitsTest::equalsZeroIntegral<Int>,
#ifndef CORRADE_TARGET_EMSCRIPTEN
&TypeTraitsTest::equalsZeroIntegral<UnsignedLong>, &TypeTraitsTest::equalsZeroIntegral<UnsignedLong>,
&TypeTraitsTest::equalsZeroIntegral<Long>, &TypeTraitsTest::equalsZeroIntegral<Long>,
#endif
}); });
addInstancedTests<TypeTraitsTest>({ addInstancedTests<TypeTraitsTest>({
&TypeTraitsTest::equalsZeroFloatingPoint<Float>, &TypeTraitsTest::equalsZeroFloatingPoint<Float>,
&TypeTraitsTest::equalsZeroFloatingPoint<Double>, &TypeTraitsTest::equalsZeroFloatingPoint<Double>,
#ifndef CORRADE_TARGET_EMSCRIPTEN &TypeTraitsTest::equalsZeroFloatingPoint<long double>},
&TypeTraitsTest::equalsZeroFloatingPoint<long double> EqualsZeroDataCount);
#endif
}, EqualsZeroDataCount);
addTests({&TypeTraitsTest::equal}); addTests({&TypeTraitsTest::equal});
} }
void TypeTraitsTest::sizeOfLongDouble() {
#ifdef CORRADE_TARGET_EMSCRIPTEN
CORRADE_SKIP("Not defined in Emscripten.");
#else
#if defined(_MSC_VER) || (defined(CORRADE_TARGET_ANDROID) && !__LP64__)
CORRADE_COMPARE(sizeof(long double), 8);
CORRADE_EXPECT_FAIL("long double is equivalent to double on MSVC and 32-bit Android.");
#endif
/* It's 80 bit, but has to be aligned somehow, so 128 bits / 16 bytes */
CORRADE_COMPARE(sizeof(long double), 16);
#endif
}
void TypeTraitsTest::name() { void TypeTraitsTest::name() {
CORRADE_COMPARE(TypeTraits<UnsignedShort>::name(), std::string{"UnsignedShort"}); CORRADE_COMPARE(TypeTraits<UnsignedShort>::name(), std::string{"UnsignedShort"});
CORRADE_COMPARE(TypeTraits<Float>::name(), std::string{"Float"}); CORRADE_COMPARE(TypeTraits<Float>::name(), std::string{"Float"});
@ -222,9 +198,7 @@ void TypeTraitsTest::isIntegral() {
CORRADE_VERIFY(IsIntegral<Int>::value); CORRADE_VERIFY(IsIntegral<Int>::value);
CORRADE_VERIFY((IsIntegral<Vector<7, UnsignedInt>>::value)); CORRADE_VERIFY((IsIntegral<Vector<7, UnsignedInt>>::value));
#ifndef CORRADE_TARGET_EMSCRIPTEN
CORRADE_VERIFY(IsIntegral<Vector2<Long>>::value); CORRADE_VERIFY(IsIntegral<Vector2<Long>>::value);
#endif
CORRADE_VERIFY(!IsIntegral<Half>::value); CORRADE_VERIFY(!IsIntegral<Half>::value);
CORRADE_VERIFY(!IsIntegral<Deg<Float>>::value); CORRADE_VERIFY(!IsIntegral<Deg<Float>>::value);
CORRADE_VERIFY(!IsIntegral<char*>::value); CORRADE_VERIFY(!IsIntegral<char*>::value);
@ -236,9 +210,7 @@ void TypeTraitsTest::isFloatingPoint() {
CORRADE_VERIFY(!(IsFloatingPoint<Vector<7, UnsignedInt>>::value)); CORRADE_VERIFY(!(IsFloatingPoint<Vector<7, UnsignedInt>>::value));
CORRADE_VERIFY(IsFloatingPoint<Double>::value); CORRADE_VERIFY(IsFloatingPoint<Double>::value);
CORRADE_VERIFY((IsFloatingPoint<Vector<2, Float>>::value)); CORRADE_VERIFY((IsFloatingPoint<Vector<2, Float>>::value));
#ifndef CORRADE_TARGET_EMSCRIPTEN
CORRADE_VERIFY(IsFloatingPoint<Vector2<long double>>::value); CORRADE_VERIFY(IsFloatingPoint<Vector2<long double>>::value);
#endif
CORRADE_VERIFY(IsFloatingPoint<Deg<Float>>::value); CORRADE_VERIFY(IsFloatingPoint<Deg<Float>>::value);
CORRADE_VERIFY(IsFloatingPoint<Color4<Half>>::value); CORRADE_VERIFY(IsFloatingPoint<Color4<Half>>::value);
CORRADE_VERIFY((IsFloatingPoint<Unit<Rad, Float>>::value)); CORRADE_VERIFY((IsFloatingPoint<Unit<Rad, Float>>::value));

25
src/Magnum/Math/TypeTraits.h

@ -66,25 +66,17 @@ for more headroom.
CORRADE_DEPRECATED_MACRO(DOUBLE_EQUALITY_PRECISION, "use Math::TypeTraits instead") 1.0e-14 CORRADE_DEPRECATED_MACRO(DOUBLE_EQUALITY_PRECISION, "use Math::TypeTraits instead") 1.0e-14
#endif #endif
#ifndef CORRADE_TARGET_EMSCRIPTEN
/** /**
@brief Precision when testing long doubles for equality @brief Precision when testing long doubles for equality
@m_deprecated_since{2020,06} Use @ref Magnum::Math::TypeTraits::epsilon() @m_deprecated_since{2020,06} Use @ref Magnum::Math::TypeTraits::epsilon()
instead. instead.
They have "at least" 18 significant digits of precision, taking one digit less They have "at least" 18 significant digits of precision on platforms where it
for more headroom. is 80-bit, and 15 on platforms @ref CORRADE_LONG_DOUBLE_SAME_AS_DOUBLE "where it is 64-bit",
taking one digit less for more headroom.
@attention On MSVC the precision is the same as for doubles, because they are
internally the same type (source: https://msdn.microsoft.com/en-us/library/9cx8xs15.aspx).
The same is apparently for 32-bit @ref CORRADE_TARGET_ANDROID "Android"
(64-bit works as expected), but I couldn't find any source for that. This
macro (and everything else related to @cpp long double @ce types is not
available on @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten" as the max
supported floating-point precision there is 64 bits.
*/ */
#ifndef LONG_DOUBLE_EQUALITY_PRECISION #ifndef LONG_DOUBLE_EQUALITY_PRECISION
#if !defined(_MSC_VER) && (!defined(CORRADE_TARGET_ANDROID) || __LP64__) #ifndef CORRADE_LONG_DOUBLE_SAME_AS_DOUBLE
#define LONG_DOUBLE_EQUALITY_PRECISION \ #define LONG_DOUBLE_EQUALITY_PRECISION \
CORRADE_DEPRECATED_MACRO(LONG_DOUBLE_EQUALITY_PRECISION, "use Math::TypeTraits instead") 1.0e-17l CORRADE_DEPRECATED_MACRO(LONG_DOUBLE_EQUALITY_PRECISION, "use Math::TypeTraits instead") 1.0e-17l
#else #else
@ -93,7 +85,6 @@ for more headroom.
#endif #endif
#endif #endif
#endif #endif
#endif
namespace Magnum { namespace Math { namespace Magnum { namespace Math {
@ -135,9 +126,7 @@ template<> struct IsScalar<unsigned long long>: std::true_type {};
template<> struct IsScalar<float>: std::true_type {}; template<> struct IsScalar<float>: std::true_type {};
template<> struct IsScalar<Half>: std::true_type {}; template<> struct IsScalar<Half>: std::true_type {};
template<> struct IsScalar<double>: std::true_type {}; template<> struct IsScalar<double>: std::true_type {};
#ifndef CORRADE_TARGET_EMSCRIPTEN
template<> struct IsScalar<long double>: std::true_type {}; template<> struct IsScalar<long double>: std::true_type {};
#endif
template<template<class> class Derived, class T> struct IsScalar<Unit<Derived, T>>: std::true_type {}; template<template<class> class Derived, class T> struct IsScalar<Unit<Derived, T>>: std::true_type {};
template<class T> struct IsScalar<Deg<T>>: std::true_type {}; template<class T> struct IsScalar<Deg<T>>: std::true_type {};
template<class T> struct IsScalar<Rad<T>>: std::true_type {}; template<class T> struct IsScalar<Rad<T>>: std::true_type {};
@ -227,9 +216,7 @@ template<class T> struct IsFloatingPoint
template<> struct IsFloatingPoint<Float>: std::true_type {}; template<> struct IsFloatingPoint<Float>: std::true_type {};
template<> struct IsFloatingPoint<Half>: std::true_type {}; template<> struct IsFloatingPoint<Half>: std::true_type {};
template<> struct IsFloatingPoint<Double>: std::true_type {}; template<> struct IsFloatingPoint<Double>: std::true_type {};
#ifndef CORRADE_TARGET_EMSCRIPTEN
template<> struct IsFloatingPoint<long double>: std::true_type {}; template<> struct IsFloatingPoint<long double>: std::true_type {};
#endif
template<std::size_t size, class T> struct IsFloatingPoint<Vector<size, T>>: IsFloatingPoint<T> {}; template<std::size_t size, class T> struct IsFloatingPoint<Vector<size, T>>: IsFloatingPoint<T> {};
template<class T> struct IsFloatingPoint<Vector2<T>>: IsFloatingPoint<T> {}; template<class T> struct IsFloatingPoint<Vector2<T>>: IsFloatingPoint<T> {};
template<class T> struct IsFloatingPoint<Vector3<T>>: IsFloatingPoint<T> {}; template<class T> struct IsFloatingPoint<Vector3<T>>: IsFloatingPoint<T> {};
@ -434,10 +421,8 @@ namespace Implementation {
_c(Short) _c(Short)
_c(UnsignedInt) _c(UnsignedInt)
_c(Int) _c(Int)
#ifndef CORRADE_TARGET_EMSCRIPTEN
_c(UnsignedLong) _c(UnsignedLong)
_c(Long) _c(Long)
#endif
_c(Float) _c(Float)
_c(Half) _c(Half)
_c(Double) _c(Double)
@ -469,14 +454,12 @@ template<> struct TypeTraits<UnsignedInt>: Implementation::TypeTraitsIntegral<Un
template<> struct TypeTraits<Int>: Implementation::TypeTraitsIntegral<Int> { template<> struct TypeTraits<Int>: Implementation::TypeTraitsIntegral<Int> {
typedef Double FloatingPointType; typedef Double FloatingPointType;
}; };
#ifndef CORRADE_TARGET_EMSCRIPTEN
template<> struct TypeTraits<UnsignedLong>: Implementation::TypeTraitsIntegral<UnsignedLong> { template<> struct TypeTraits<UnsignedLong>: Implementation::TypeTraitsIntegral<UnsignedLong> {
typedef long double FloatingPointType; typedef long double FloatingPointType;
}; };
template<> struct TypeTraits<Long>: Implementation::TypeTraitsIntegral<Long> { template<> struct TypeTraits<Long>: Implementation::TypeTraitsIntegral<Long> {
typedef long double FloatingPointType; typedef long double FloatingPointType;
}; };
#endif
/* Floating-point scalar types */ /* Floating-point scalar types */
namespace Implementation { namespace Implementation {

Loading…
Cancel
Save