diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-28 11:46:30 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-28 18:12:07 +0200 |
commit | d782df48612a932f03a579c889670d34c26e9574 (patch) | |
tree | c27f330cce93aa86a5b4974d7a4d6edd0b2bc6d9 | |
parent | f16613f7ef34769181ac19a45b5c42059e63572f (diff) |
Make qfloat16 helper functions consistent with float/double versions
Infinite is only when the mantissa is 0, everything else is NaN.
std::isnormal returns false on zero.
Pick-to: 5.15
Change-Id: I897fc0dc3b8a9c557bb1922ea7ca8df501e91859
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/global/qfloat16.h | 10 | ||||
-rw-r--r-- | tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp | 2 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h index 9ac811a3e6..ab480f84f5 100644 --- a/src/corelib/global/qfloat16.h +++ b/src/corelib/global/qfloat16.h @@ -80,9 +80,9 @@ public: inline operator float() const noexcept; // Support for qIs{Inf,NaN,Finite}: - bool isInf() const noexcept { return ((b16 >> 8) & 0x7e) == 0x7c; } - bool isNaN() const noexcept { return ((b16 >> 8) & 0x7e) == 0x7e; } - bool isFinite() const noexcept { return ((b16 >> 8) & 0x7c) != 0x7c; } + bool isInf() const noexcept { return (b16 & 0x7fff) == 0x7c00; } + bool isNaN() const noexcept { return (b16 & 0x7fff) > 0x7c00; } + bool isFinite() const noexcept { return (b16 & 0x7fff) < 0x7c00; } Q_CORE_EXPORT int fpClassify() const noexcept; // Can't specialize std::copysign() for qfloat16 qfloat16 copySign(qfloat16 sign) const noexcept @@ -96,10 +96,10 @@ public: static constexpr qfloat16 _limit_infinity() noexcept { return qfloat16(Wrap(0x7c00)); } static constexpr qfloat16 _limit_quiet_NaN() noexcept { return qfloat16(Wrap(0x7e00)); } #if QT_CONFIG(signaling_nan) - static constexpr qfloat16 _limit_signaling_NaN() noexcept { return qfloat16(Wrap(0x7f00)); } + static constexpr qfloat16 _limit_signaling_NaN() noexcept { return qfloat16(Wrap(0x7d00)); } #endif inline constexpr bool isNormal() const noexcept - { return (b16 & 0x7fff) == 0 || ((b16 & 0x7c00) && (b16 & 0x7c00) != 0x7c00); } + { return (b16 & 0x7c00) && (b16 & 0x7c00) != 0x7c00; } private: quint16 b16; constexpr inline explicit qfloat16(Wrap nibble) noexcept : b16(nibble.b16) {} diff --git a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp index a661b0388e..99f539f341 100644 --- a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp +++ b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp @@ -423,7 +423,7 @@ void tst_qfloat16::finite() { QFETCH(qfloat16, value); QFETCH(int, mode); - QCOMPARE(value.isNormal(), mode != FP_SUBNORMAL); + QCOMPARE(value.isNormal(), mode == FP_NORMAL); QCOMPARE(value, value); // Fuzzy QVERIFY(value == value); // Exact QVERIFY(qIsFinite(value)); |