diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-08-10 16:21:16 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-08-11 04:24:12 +0200 |
commit | d7205a7cae869fca0b2feb15fd77aaf99ce9846b (patch) | |
tree | 187142973dd6fb66eeedacd2cb7886c9d349657f /src | |
parent | 20db9a0d7ff35f38e53487c640abb4550f0d1532 (diff) |
Add degree<->radians conversions for long double and integral types
For long double: they're just missing, so add them for completeness.
For integral types: follow the advice of C11's trigonometric
functions; first convert the angle to double, then do the actual
conversion. This is offered only for the degree->radians conversions,
as someone may legitimately want to call e.g. qDegreesToRadians(90).
On the other hand, it seems extremely unlikely that someone may
want to do a radians->degree conversion starting from integral
datatypes, so I'm not adding it for the moment being (instead,
I'm leaving a note).
[ChangeLog][QtCore][QtMath] qDegreesToRadians now also accepts
long double and integral types. A value of integral type will be
casted to double before the conversion to radians.
[ChangeLog][QtCore][QtMath] qRadiansToDegrees now also accepts
long double.
Change-Id: Ib1576be5193ae09bb6cb4a70d7a31702955df2c5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qmath.h | 20 | ||||
-rw-r--r-- | src/corelib/kernel/qmath.qdoc | 34 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/corelib/kernel/qmath.h b/src/corelib/kernel/qmath.h index 57314901e8..e7b6ab9c0e 100644 --- a/src/corelib/kernel/qmath.h +++ b/src/corelib/kernel/qmath.h @@ -233,6 +233,17 @@ Q_DECL_CONSTEXPR inline double qDegreesToRadians(double degrees) return degrees * (M_PI / 180); } +Q_DECL_CONSTEXPR inline long double qDegreesToRadians(long double degrees) +{ + return degrees * (M_PI / 180); +} + +template <typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true> +Q_DECL_CONSTEXPR inline double qDegreesToRadians(T degrees) +{ + return qDegreesToRadians(static_cast<double>(degrees)); +} + Q_DECL_CONSTEXPR inline float qRadiansToDegrees(float radians) { return radians * float(180/M_PI); @@ -243,6 +254,15 @@ Q_DECL_CONSTEXPR inline double qRadiansToDegrees(double radians) return radians * (180 / M_PI); } +Q_DECL_CONSTEXPR inline long double qRadiansToDegrees(long double radians) +{ + return radians * (180 / M_PI); +} + +// A qRadiansToDegrees(Integral) overload isn't here; it's extremely +// questionable that someone is manipulating quantities in radians +// using integral datatypes... + namespace QtPrivate { constexpr inline quint32 qConstexprNextPowerOfTwo(quint32 v) { v |= v >> 1; diff --git a/src/corelib/kernel/qmath.qdoc b/src/corelib/kernel/qmath.qdoc index 82a4ae85a5..b0a52a4a52 100644 --- a/src/corelib/kernel/qmath.qdoc +++ b/src/corelib/kernel/qmath.qdoc @@ -205,6 +205,30 @@ */ /*! + \fn long double qDegreesToRadians(long double degrees) + \relates <QtMath> + \since 6.0 + + This function converts the \a degrees in double to radians. + + \sa qRadiansToDegrees() +*/ + +/*! + \fn template <typename Integral> double qDegreesToRadians(Integral degrees) + \relates <QtMath> + \since 6.0 + + This function converts the \a degrees in double to radians; + the angle is casted to a double before the conversion. + + This function participates in overload resolution if and only if + \c Integral is an integral type. + + \sa qRadiansToDegrees() +*/ + +/*! \fn float qRadiansToDegrees(float radians) \relates <QtMath> \since 5.1 @@ -233,6 +257,16 @@ */ /*! + \fn long double qRadiansToDegrees(long double radians) + \relates <QtMath> + \since 6.0 + + This function converts the \a radians in double to degrees. + + \sa qDegreesToRadians() +*/ + +/*! \fn quint32 qNextPowerOfTwo(quint32 value) \relates <QtMath> \since 5.4 |