From 70336a6a9844e9aed77aab93ea28f7391c9f3fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 9 Aug 2020 14:52:42 +0200 Subject: [PATCH] Math: remove pointless Emscripten restrictions in TypeTraits. Size of long double is now tested in Corrade itself, so no need for any of this. --- src/Magnum/Math/Test/TypeTraitsTest.cpp | 40 ++++--------------------- src/Magnum/Math/TypeTraits.h | 25 +++------------- 2 files changed, 10 insertions(+), 55 deletions(-) diff --git a/src/Magnum/Math/Test/TypeTraitsTest.cpp b/src/Magnum/Math/Test/TypeTraitsTest.cpp index 71effe59f..68bc05e28 100644 --- a/src/Magnum/Math/Test/TypeTraitsTest.cpp +++ b/src/Magnum/Math/Test/TypeTraitsTest.cpp @@ -37,7 +37,6 @@ namespace Magnum { namespace Math { namespace Test { namespace { struct TypeTraitsTest: Corrade::TestSuite::Tester { explicit TypeTraitsTest(); - void sizeOfLongDouble(); void name(); void isScalar(); @@ -78,27 +77,25 @@ struct { Float getStep(Float) const { return aStep; } Double get(Double) const { return b; } Double getStep(Double) const { return bStep; } - #ifndef CORRADE_TARGET_EMSCRIPTEN long double get(long double) const { return c; } long double getStep(long double) const { return cStep; } - #endif } EqualsZeroData[EqualsZeroDataCount] = { {"", -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 #else 5.0e-14 #endif }, {"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 #else 5.0e-15 #endif }, {"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, #else -12345678901234.0, @@ -107,8 +104,7 @@ struct { }; TypeTraitsTest::TypeTraitsTest() { - addTests({&TypeTraitsTest::sizeOfLongDouble, - &TypeTraitsTest::name, + addTests({&TypeTraitsTest::name, &TypeTraitsTest::isScalar, &TypeTraitsTest::isVector, @@ -128,10 +124,8 @@ TypeTraitsTest::TypeTraitsTest() { &TypeTraitsTest::equalsIntegral, &TypeTraitsTest::equalsIntegral, &TypeTraitsTest::equalsIntegral, - #ifndef CORRADE_TARGET_EMSCRIPTEN &TypeTraitsTest::equalsIntegral, &TypeTraitsTest::equalsIntegral, - #endif &TypeTraitsTest::equalsHalf, @@ -155,37 +149,19 @@ TypeTraitsTest::TypeTraitsTest() { &TypeTraitsTest::equalsZeroIntegral, &TypeTraitsTest::equalsZeroIntegral, &TypeTraitsTest::equalsZeroIntegral, - #ifndef CORRADE_TARGET_EMSCRIPTEN &TypeTraitsTest::equalsZeroIntegral, &TypeTraitsTest::equalsZeroIntegral, - #endif }); addInstancedTests({ &TypeTraitsTest::equalsZeroFloatingPoint, &TypeTraitsTest::equalsZeroFloatingPoint, - #ifndef CORRADE_TARGET_EMSCRIPTEN - &TypeTraitsTest::equalsZeroFloatingPoint - #endif - }, EqualsZeroDataCount); + &TypeTraitsTest::equalsZeroFloatingPoint}, + EqualsZeroDataCount); 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() { CORRADE_COMPARE(TypeTraits::name(), std::string{"UnsignedShort"}); CORRADE_COMPARE(TypeTraits::name(), std::string{"Float"}); @@ -222,9 +198,7 @@ void TypeTraitsTest::isIntegral() { CORRADE_VERIFY(IsIntegral::value); CORRADE_VERIFY((IsIntegral>::value)); - #ifndef CORRADE_TARGET_EMSCRIPTEN CORRADE_VERIFY(IsIntegral>::value); - #endif CORRADE_VERIFY(!IsIntegral::value); CORRADE_VERIFY(!IsIntegral>::value); CORRADE_VERIFY(!IsIntegral::value); @@ -236,9 +210,7 @@ void TypeTraitsTest::isFloatingPoint() { CORRADE_VERIFY(!(IsFloatingPoint>::value)); CORRADE_VERIFY(IsFloatingPoint::value); CORRADE_VERIFY((IsFloatingPoint>::value)); - #ifndef CORRADE_TARGET_EMSCRIPTEN CORRADE_VERIFY(IsFloatingPoint>::value); - #endif CORRADE_VERIFY(IsFloatingPoint>::value); CORRADE_VERIFY(IsFloatingPoint>::value); CORRADE_VERIFY((IsFloatingPoint>::value)); diff --git a/src/Magnum/Math/TypeTraits.h b/src/Magnum/Math/TypeTraits.h index cc64815e9..0a013be71 100644 --- a/src/Magnum/Math/TypeTraits.h +++ b/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 #endif -#ifndef CORRADE_TARGET_EMSCRIPTEN /** @brief Precision when testing long doubles for equality @m_deprecated_since{2020,06} Use @ref Magnum::Math::TypeTraits::epsilon() instead. -They have "at least" 18 significant digits of precision, 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. +They have "at least" 18 significant digits of precision on platforms where it +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. */ #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 \ CORRADE_DEPRECATED_MACRO(LONG_DOUBLE_EQUALITY_PRECISION, "use Math::TypeTraits instead") 1.0e-17l #else @@ -93,7 +85,6 @@ for more headroom. #endif #endif #endif -#endif namespace Magnum { namespace Math { @@ -135,9 +126,7 @@ template<> struct IsScalar: std::true_type {}; template<> struct IsScalar: std::true_type {}; template<> struct IsScalar: std::true_type {}; template<> struct IsScalar: std::true_type {}; -#ifndef CORRADE_TARGET_EMSCRIPTEN template<> struct IsScalar: std::true_type {}; -#endif template class Derived, class T> struct IsScalar>: std::true_type {}; template struct IsScalar>: std::true_type {}; template struct IsScalar>: std::true_type {}; @@ -227,9 +216,7 @@ template struct IsFloatingPoint template<> struct IsFloatingPoint: std::true_type {}; template<> struct IsFloatingPoint: std::true_type {}; template<> struct IsFloatingPoint: std::true_type {}; -#ifndef CORRADE_TARGET_EMSCRIPTEN template<> struct IsFloatingPoint: std::true_type {}; -#endif template struct IsFloatingPoint>: IsFloatingPoint {}; template struct IsFloatingPoint>: IsFloatingPoint {}; template struct IsFloatingPoint>: IsFloatingPoint {}; @@ -434,10 +421,8 @@ namespace Implementation { _c(Short) _c(UnsignedInt) _c(Int) - #ifndef CORRADE_TARGET_EMSCRIPTEN _c(UnsignedLong) _c(Long) - #endif _c(Float) _c(Half) _c(Double) @@ -469,14 +454,12 @@ template<> struct TypeTraits: Implementation::TypeTraitsIntegral struct TypeTraits: Implementation::TypeTraitsIntegral { typedef Double FloatingPointType; }; -#ifndef CORRADE_TARGET_EMSCRIPTEN template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef long double FloatingPointType; }; template<> struct TypeTraits: Implementation::TypeTraitsIntegral { typedef long double FloatingPointType; }; -#endif /* Floating-point scalar types */ namespace Implementation {