summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2019-09-23 16:46:07 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2019-10-03 16:30:40 +0200
commitd448f2ecb8bca7de1e69f9f6f10d0ffb8c3d1beb (patch)
tree76b45bb1213c81eccc2b3d536911dd9de91dccec /src
parenta978d21dac57697ae9557b99062bc804b005b9d4 (diff)
Correct handling of -qfloat16(0)
It is finite and normal; it classifies as a zero; and it should not be > qfloat16(0). Added tests to match. Change-Id: I7874fb54f622b4cdf28b0894050ad3e75cf5d77c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qfloat16.cpp2
-rw-r--r--src/corelib/global/qfloat16.h4
2 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/global/qfloat16.cpp b/src/corelib/global/qfloat16.cpp
index 2ba4c79374..6c21b7de5a 100644
--- a/src/corelib/global/qfloat16.cpp
+++ b/src/corelib/global/qfloat16.cpp
@@ -155,7 +155,7 @@ QT_BEGIN_NAMESPACE
int qfloat16::fpClassify() const noexcept
{
return isInf() ? FP_INFINITE : isNaN() ? FP_NAN
- : !b16 ? FP_ZERO : isNormal() ? FP_NORMAL : FP_SUBNORMAL;
+ : !(b16 & 0x7fff) ? FP_ZERO : isNormal() ? FP_NORMAL : FP_SUBNORMAL;
}
/*! \fn int qRound(qfloat16 value)
diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h
index 4d1aa91349..9a4f1800a4 100644
--- a/src/corelib/global/qfloat16.h
+++ b/src/corelib/global/qfloat16.h
@@ -94,7 +94,7 @@ public:
static constexpr qfloat16 _limit_quiet_NaN() noexcept { return qfloat16(Wrap(0x7e00)); }
// Signalling NaN is 0x7f00
inline constexpr bool isNormal() const noexcept
- { return b16 == 0 || ((b16 & 0x7c00) && (b16 & 0x7c00) != 0x7c00); }
+ { return (b16 & 0x7fff) == 0 || ((b16 & 0x7c00) && (b16 & 0x7c00) != 0x7c00); }
private:
quint16 b16;
constexpr inline explicit qfloat16(Wrap nibble) noexcept : b16(nibble.b16) {}
@@ -296,7 +296,7 @@ class numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> : public numeric_limits<flo
public:
/*
Treat quint16 b16 as if it were:
- uint S: 1; // b16 >> 15 (sign)
+ uint S: 1; // b16 >> 15 (sign); can be set for zero
uint E: 5; // (b16 >> 10) & 0x1f (offset exponent)
uint M: 10; // b16 & 0x3ff (adjusted mantissa)