summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qfloat16.h
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-04-15 17:47:05 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2021-04-29 14:13:23 +0200
commit9bad096c091b2c2106c2f325dfca74be111eee58 (patch)
tree8d0d204e8ccbadf72b4cbceaa3db07171f0c4611 /src/corelib/global/qfloat16.h
parent6dfec83051c3426fcf2336f8b7acfdc290efe94c (diff)
Use a more forgiving threshold for qFuzzyIsNull(qfloat16)
Analysis of problems with the new test for qFuzzyIsNull() revealed that, where its version for double uses approximately 4500 * epsilon and for float used 84 * epsilon as threshold, the qfloat16 version's value was barely more than epsilon, with the result that the test had to use a different value than the threshold to pass. (Converting the threshold from float to qfloat16 and back made it bigger; in effect, the threshold value was not <= itself.) Furthermore, comparison with qFuzzyCompare() implied a value of 1/102.5 should be used, roughly 10 * epsilon, for consistency. When 1/102.5 is rounded to three significant digits (the precision we use in QTest::toString(), for example), to give 0.00976f as threshold, we get a value that, after conversion to qfloat16 and back to float, does give a result <= what we started with. So change qFuzzyIsNull() and its test to use this as qfloat16's threshold value. [ChangeLog][QtCore][QFloat16] The qfloat16 threshold value for qFuzzyIsNull() has changed from 1e-3 to 9.76e-3, almost a factor of ten increase, for consistency with qFuzzyCompare()'s tolerance. Values between these would previously have had qFuzzyIsNull(f) false despite qFuzzyCompre(f, 1+f) being true. Change-Id: I35816dce78da34a3e2339c8bc42d5bd03714a3f6 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Andreas Buhr <andreas.buhr@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global/qfloat16.h')
-rw-r--r--src/corelib/global/qfloat16.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h
index e574ffed78..c2e5379eb4 100644
--- a/src/corelib/global/qfloat16.h
+++ b/src/corelib/global/qfloat16.h
@@ -239,7 +239,7 @@ Q_CORE_EXPORT void qFloatFromFloat16(float *, const qfloat16 *, qsizetype length
*/
[[nodiscard]] inline bool qFuzzyIsNull(qfloat16 f) noexcept
{
- return qAbs(static_cast<float>(f)) <= 0.001f;
+ return qAbs(f) < 0.00976f; // 1/102.5 to 3 significant digits; see qFuzzyCompare()
}
[[nodiscard]] inline bool qIsNull(qfloat16 f) noexcept