From b08368d99fa41b3f84cf30468c2dc9f5c2c43423 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 24 Feb 2017 14:40:51 +0100 Subject: Add qHypot() to qmath.h, exposing and extending std::hypot() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have plenty of places where we add some squares and take a square root; this may be done more accurately and faster by hypot(). Introduce QHypotHelper to handle hypot with more than 3 parameters, and with 3 when the C++17 version is missing (which it never should be). Include an overload taking arbitrarily many valus and ensure that we can use qHypot() with qfloat16. Illustrate with some example uses, add some tests. [ChangeLog][QtCore][QMath] Header now provides qHypot(), an implementation of std::hypot() taking arbitrarily many numeric values, including support for qfloat16, while avoiding the overflow and underflow problems that arise when naively taking the square root of a sum of squares. Change-Id: Ia4e3913fe83fc27d17d8e7f1a52f03ad445c1fed Reviewed-by: Andrei Golubev Reviewed-by: MÃ¥rten Nordheim --- src/plugins/platforms/xcb/qxcbconnection_xi2.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms/xcb') diff --git a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp index 07f66af9e3..f69655e403 100644 --- a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp @@ -43,11 +43,11 @@ #include "qxcbscreen.h" #include "qxcbwindow.h" #include "QtCore/qmetaobject.h" +#include "QtCore/qmath.h" #include #include #include #include -#include #include @@ -758,11 +758,11 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo } else if (vci.label == QXcbAtom::AbsMTTouchMajor) { const qreal sw = screen->geometry().width(); const qreal sh = screen->geometry().height(); - w = valuatorNormalized * std::sqrt(sw * sw + sh * sh); + w = valuatorNormalized * qHypot(sw, sh); } else if (vci.label == QXcbAtom::AbsMTTouchMinor) { const qreal sw = screen->geometry().width(); const qreal sh = screen->geometry().height(); - h = valuatorNormalized * std::sqrt(sw * sw + sh * sh); + h = valuatorNormalized * qHypot(sw, sh); } else if (vci.label == QXcbAtom::AbsMTOrientation) { // Find the closest axis. // 0 corresponds to the Y axis, vci.max to the X axis. -- cgit v1.2.3