diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2024-03-01 10:19:54 -0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-03-03 17:55:34 +0000 |
commit | 8a92fbf80c24a9dd78ab7fe6f55f287f59bf72a0 (patch) | |
tree | 9b760a0417e0009738fd446814e5072234550cea | |
parent | 922370814a0c8f258153c560ba7797f481531eee (diff) |
qfloat16: use std::numeric_limits<std::float16> if available
Instead of going through the bit casts. Also solves the violation of
constexpr requirements from the previous commit.
Change-Id: I01ec3c774d9943adb903fffd17b8b6ee93d3c031
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
(cherry picked from commit 398a51686eda225f222d9df7ce56898c18ecdaa1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/corelib/global/qfloat16.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h index a9527544d7..2408597a5f 100644 --- a/src/corelib/global/qfloat16.h +++ b/src/corelib/global/qfloat16.h @@ -93,6 +93,20 @@ public: qfloat16 copySign(qfloat16 sign) const noexcept { return qfloat16(Wrap((sign.b16 & 0x8000) | (b16 & 0x7fff))); } // Support for std::numeric_limits<qfloat16> + +#ifdef __STDCPP_FLOAT16_T__ +private: + using Bounds = std::numeric_limits<NativeType>; +public: + static constexpr qfloat16 _limit_epsilon() noexcept { return Bounds::epsilon(); } + static constexpr qfloat16 _limit_min() noexcept { return Bounds::min(); } + static constexpr qfloat16 _limit_denorm_min() noexcept { return Bounds::denorm_min(); } + static constexpr qfloat16 _limit_max() noexcept { return Bounds::max(); } + static constexpr qfloat16 _limit_lowest() noexcept { return Bounds::lowest(); } + static constexpr qfloat16 _limit_infinity() noexcept { return Bounds::infinity(); } + static constexpr qfloat16 _limit_quiet_NaN() noexcept { return Bounds::quiet_NaN(); } + static constexpr qfloat16 _limit_signaling_NaN() noexcept { return Bounds::signaling_NaN(); } +#else static constexpr qfloat16 _limit_epsilon() noexcept { return qfloat16(Wrap(0x1400)); } static constexpr qfloat16 _limit_min() noexcept { return qfloat16(Wrap(0x400)); } static constexpr qfloat16 _limit_denorm_min() noexcept { return qfloat16(Wrap(1)); } @@ -103,6 +117,7 @@ public: #if QT_CONFIG(signaling_nan) static constexpr qfloat16 _limit_signaling_NaN() noexcept { return qfloat16(Wrap(0x7d00)); } #endif +#endif inline constexpr bool isNormal() const noexcept { return (b16 & 0x7c00) && (b16 & 0x7c00) != 0x7c00; } private: |