diff --git a/src/corelib/global/qcomparehelpers.h b/src/corelib/global/qcomparehelpers.h index 9c9da2c7d91..ad21d461b9f 100644 --- a/src/corelib/global/qcomparehelpers.h +++ b/src/corelib/global/qcomparehelpers.h @@ -341,6 +341,14 @@ template constexpr bool IsIntegralType_v = std::numeric_limits>::is_specialized && std::numeric_limits>::is_integer; +template +constexpr bool IsFloatType_v = std::is_floating_point_v; + +#if QFLOAT16_IS_NATIVE +template <> +constexpr bool IsFloatType_v = true; +#endif + } // namespace QtPrivate namespace Qt { @@ -353,14 +361,14 @@ using if_integral = template using if_floating_point = - std::enable_if_t>, - std::is_floating_point>>, + std::enable_if_t> + && QtPrivate::IsFloatType_v>, bool>; template using if_integral_and_floating_point = std::enable_if_t> - && std::is_floating_point_v>, + && QtPrivate::IsFloatType_v>, bool>; template diff --git a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp index 0dfe4ab5de4..86ca75680c9 100644 --- a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp +++ b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp @@ -663,13 +663,31 @@ void tst_QCompareHelpers::builtinOrder() TEST_BUILTIN(qint64, std::float16_t) TEST_BUILTIN(uint, std::float16_t) #endif - TEST_BUILTIN(long double, long double) TEST_BUILTIN(float, long double) TEST_BUILTIN(double, long double) TEST_BUILTIN(quint64, long double) TEST_BUILTIN(ushort, long double) +#if QFLOAT16_IS_NATIVE + { + // Cannot use TEST_BUILTIN here, because std::numeric_limits are not defined + // for QtPrivate::NativeFloat16Type. + const QtPrivate::NativeFloat16Type smaller{1.0}; + const QtPrivate::NativeFloat16Type bigger{2.0}; + // native vs native + QCOMPARE_EQ(Qt::compareThreeWay(smaller, smaller), Qt::partial_ordering::equivalent); + QCOMPARE_EQ(Qt::compareThreeWay(smaller, bigger), Qt::partial_ordering::less); + QCOMPARE_EQ(Qt::compareThreeWay(bigger, smaller), Qt::partial_ordering::greater); + // native vs float + QCOMPARE_EQ(Qt::compareThreeWay(smaller, 1.0f), Qt::partial_ordering::equivalent); + QCOMPARE_EQ(Qt::compareThreeWay(1.0f, bigger), Qt::partial_ordering::less); + QCOMPARE_EQ(Qt::compareThreeWay(bigger, 1.0f), Qt::partial_ordering::greater); + const auto floatNaN = std::numeric_limits::quiet_NaN(); + QCOMPARE_EQ(Qt::compareThreeWay(bigger, floatNaN), Qt::partial_ordering::unordered); + } +#endif + QCOMPARE_EQ(Qt::compareThreeWay(TestEnum::Smaller, TestEnum::Bigger), Qt::strong_ordering::less); QCOMPARE_EQ(Qt::compareThreeWay(TestEnum::Bigger, TestEnum::Smaller),