summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmath.h
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-04-21 02:09:27 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-06-17 17:56:48 +0200
commita97cda8b8b5806d3fd170c6ffd56094bbd60bd65 (patch)
treee178ca70b611debee09588236f2efc2430acc2aa /src/corelib/kernel/qmath.h
parentd2a04cf165c455f70bf8588cf75709831d1c078d (diff)
QMath: make the math-related functions templates
This way we can take and return more datatypes than qreal, just piggy-backing on the std:: functions (which take any integral and any fp datatype). This makes these functions pure ADL enablers (like qSwap). A type (hi, QAngle!) that wants to have math related functions simply needs those defined in its own namespace using the "standard" names (sin, cos, etc.); and we'll find them using the q-prefixed function. qCeil and qFloor signatures however still return int to avoid too much breakage. The FP-related functions (qIsInf, etc.) have been left alone. Those are "special"; a lot of care is in qnumeric because some implementations define them as macros, which blocks any possibility of user-defined overloads found via ADL. [ChangeLog][QtCore][QtMath] The math-related functions (such as qSin, qCos, qPow and so on) can now take an arbitrary parameter rather than just qreal. They will do a ADL-enabled call to the respective free function, using the functions in namespace std as a fallback. Moreover, they will now return whatever datatype is returned by the free function (e.g. long double if the call is placed on a long double). Change-Id: I111084eda52556663802e65a85e082187c2a6861 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/kernel/qmath.h')
-rw-r--r--src/corelib/kernel/qmath.h28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/corelib/kernel/qmath.h b/src/corelib/kernel/qmath.h
index 391d6d4282..57314901e8 100644
--- a/src/corelib/kernel/qmath.h
+++ b/src/corelib/kernel/qmath.h
@@ -65,85 +65,85 @@ QT_BEGIN_NAMESPACE
extern Q_CORE_EXPORT const qreal qt_sine_table[QT_SINE_TABLE_SIZE];
-inline int qCeil(qreal v)
+template <typename T> int qCeil(T v)
{
using std::ceil;
return int(ceil(v));
}
-inline int qFloor(qreal v)
+template <typename T> int qFloor(T v)
{
using std::floor;
return int(floor(v));
}
-inline qreal qFabs(qreal v)
+template <typename T> auto qFabs(T v)
{
using std::fabs;
return fabs(v);
}
-inline qreal qSin(qreal v)
+template <typename T> auto qSin(T v)
{
using std::sin;
return sin(v);
}
-inline qreal qCos(qreal v)
+template <typename T> auto qCos(T v)
{
using std::cos;
return cos(v);
}
-inline qreal qTan(qreal v)
+template <typename T> auto qTan(T v)
{
using std::tan;
return tan(v);
}
-inline qreal qAcos(qreal v)
+template <typename T> auto qAcos(T v)
{
using std::acos;
return acos(v);
}
-inline qreal qAsin(qreal v)
+template <typename T> auto qAsin(T v)
{
using std::asin;
return asin(v);
}
-inline qreal qAtan(qreal v)
+template <typename T> auto qAtan(T v)
{
using std::atan;
return atan(v);
}
-inline qreal qAtan2(qreal y, qreal x)
+template <typename T1, typename T2> auto qAtan2(T1 y, T2 x)
{
using std::atan2;
return atan2(y, x);
}
-inline qreal qSqrt(qreal v)
+template <typename T> auto qSqrt(T v)
{
using std::sqrt;
return sqrt(v);
}
-inline qreal qLn(qreal v)
+template <typename T> auto qLn(T v)
{
using std::log;
return log(v);
}
-inline qreal qExp(qreal v)
+template <typename T> auto qExp(T v)
{
using std::exp;
return exp(v);
}
-inline qreal qPow(qreal x, qreal y)
+template <typename T1, typename T2> auto qPow(T1 x, T2 y)
{
using std::pow;
return pow(x, y);