summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmath.h
Commit message (Collapse)AuthorAgeFilesLines
* Whitespace cleanup in corelib/kernelAllan Sandfeld Jensen2020-10-241-4/+6
| | | | | Change-Id: If061ef0af5ced4384e20a82afcea3712fa7e45d7 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Only include <bit> if using post C++17Allan Sandfeld Jensen2020-09-151-1/+1
| | | | | | | Otherwise we hit an #error statement in MSVC standard library. Change-Id: Ib029edf0be8513a80f2640fd9ca75541615a0448 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Use universal C++20 bit operations when availableAllan Sandfeld Jensen2020-09-131-2/+10
| | | | | | | Avoids using compiler builtins, and can in future replace them. Change-Id: I3f0afe7d28b6ba05bcd1c1132b44a8db7b182d8a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace Qt CONSTEXPR defines with constexprAllan Sandfeld Jensen2020-08-141-7/+7
| | | | | | | | Both normal and relaxed constexpr are required by our new minimum of C++17. Change-Id: Ic028b88a2e7a6cb7d5925f3133b9d54859a81744 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Add degree<->radians conversions for long double and integral typesGiuseppe D'Angelo2020-08-111-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* QMath: make the math-related functions templatesGiuseppe D'Angelo2020-06-171-14/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fix qConstexprNextPowerOfTwo(qint64) to return quint64Shawn Rutledge2020-04-131-3/+5
| | | | | | | | | | | | | | It doesn't make sense to lose precision, and that's a fatal warning when used on a 32-bit platform: implicit conversion loses integer precision: 'quint64' (aka 'unsigned long long') to 'quint32' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32] Also fix coding style. Amends 7ef382649754c261ca9eb99dd50b67050e748efb Change-Id: I2c8f51883d74f0c6dc1b5faefe7b3ace1d9c15b9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Introduce always constexpr variants of qNextPowerOfTwoFabian Kosmale2020-03-171-18/+35
| | | | | | | | | Amends e464e1eb8eb63c631fb0916c3ea4540a88d8aad3. qNextPowerOfTwo has the same issue as qCountTrailingZeroBits. Change-Id: Ib1905986e932ac130bce7a1d98f4f7b5ef73991f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Make qNextPowerOfTwo constexpr when building as C++14Tor Arne Vestbø2017-05-091-14/+8
| | | | | | Change-Id: Ic29dcbf1c4b70516ebb436b90962e3fdeb0e5608 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Document M_PI and friends in <QtMath>Edward Welbourne2017-03-291-0/+2
| | | | | | | | | These symbols should at least be mentioned in the documentation. Also comment on the option of using template variables for them once we haev support for C++14 Change-Id: Ia40f9b89d9d8a38536a2e51ae3f174b8f16ca7d6 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Remove _bit_scan_{forward,reverse}Erik Verbruggen2016-05-311-10/+12
| | | | | | | | | | Use qCountTrailingZeroBits and qCountLeadingZeroBits from qalgorithms.h instead. Also extended these versions for MSVC. The _bit_scan_* versions stem from a time before the glorious days of qalgorithms.h. A big advantage is that these functions can be used on all platforms. Change-Id: I5a1b886371520310a7fe16e617635ea335046beb Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Updated license headersJani Heikkinen2016-01-151-14/+20
| | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* Force Visual C++ math.h to define the M_ constantsThiago Macieira2015-06-221-0/+10
| | | | | | | | | | | | | | | That header defines those constants outside of the math.h include guard, so if someone #define'd _USE_MATH_DEFINES and #include'd math.h later, they would get VC++ warnings about constants like M_PI being redefined with different values (ours have parentheses, VS2010's math.h don't). Instead, let's define _USE_MATH_DEFINES ourselves so we get the M_* macros from math.h. That way, we won't redefine them outselves. Task-number: QTBUG-45935 Change-Id: Idf715b895bac4d56b4afffff13db2c98ba8345c2 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Use C++ <cmath> instead of <math.h>Allan Sandfeld Jensen2015-02-161-84/+29
| | | | | | | | | | | | | | Including math.h can pollute the default namespace, and break some compilers if cmath versions of the method are declared as using. Switching to C++ math functions also greatly simplifies handling of float qreal as C++ automatically chooses the right method. [ChangeLog][QtCore][QtMath] qmath.h no longer includes math.h, so any sources depending on that indirect inclusion may fail to build. Change-Id: I4d0e331dafba354ec05dc5052e61ef4ff8d387fe Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
* Update copyright headersJani Heikkinen2015-02-111-7/+7
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* Update license headers and add new license filesMatti Paaso2014-09-241-19/+11
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* Unduplicate the implementations of next power of twoAllan Sandfeld Jensen2014-06-261-0/+52
| | | | | | | | | | | Qtbase contains four identical implementations of next power of two, these should be shared and the implementation made available to other qt modules, as it is also used many places outside of qtbase. [ChangeLog][QtCore][QtMath] Introduced qNextPowerOfTwo methods. Change-Id: Id23fbe5ad6bae647b30d5a4212c0330e48a50278 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add qDegreesToRadians and qRadiansToDegrees math functionsLaszlo Papp2013-02-051-0/+20
| | | | | Change-Id: I6e9fd76f2d2860f46531a72349b46193b8eeaaa7 Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
* Generate forward header (QtMath) for the math operations with syncqtLaszlo Papp2013-01-291-0/+4
| | | | | Change-Id: Ief5b5871a5d56bb606e09efcfd3a1422dcfbcd08 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove QT_{BEGIN,END}_HEADER macro usageSergio Ahumada2013-01-291-4/+0
| | | | | | | | | | | The macro was made empty in ba3dc5f3b56d1fab6fe37fe7ae08096d7dc68bcb and is no longer necessary or used. Discussed-on: http://lists.qt-project.org/pipermail/development/2013-January/009284.html Change-Id: Id2bb2e2cabde059305d4af5f12593344ba30f001 Reviewed-by: Laszlo Papp <lpapp@kde.org> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
* Update copyright year in Digia's license headersSergio Ahumada2013-01-181-1/+1
| | | | | Change-Id: Ic804938fc352291d011800d21e549c10acac66fb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Define additional math.h constants if not already definedJonathan Liu2012-10-301-0/+48
| | | | | | | | | | | | The M_E, M_PI_2, etc. math.h constants are not defined with MinGW-w64 GCC when compiling with -std=c++11. Task-number: QTBUG-27561 Change-Id: I2267c170dd3788abc9c37425a9be514bbae51f5a Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Alexey Pavlov <alexpux@gmail.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-221-24/+24
| | | | | | | | Change copyrights and license headers from Nokia to Digia Change-Id: If1cc974286d29fd01ec6c19dd4719a67f4c3f00e Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
* Fix the name of the arguments of qAtan2 to match std::atan2Thiago Macieira2012-08-311-3/+3
| | | | | | | | | There is no change in functionality, just swapping of the names x and y. The std::atan2 function uses (y, x) in that order, so we should too. Task-number: QTBUG-27090 Change-Id: I7d4597a6c6909f574c517033f5d49fe17b7a7ead Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* Remove "All rights reserved" line from license headers.Jason McDonald2012-01-301-1/+1
| | | | | | | | | | As in the past, to avoid rewriting various autotests that contain line-number information, an extra blank line has been inserted at the end of the license text to ensure that this commit does not change the total number of lines in the license header. Change-Id: I311e001373776812699d6efc045b5f742890c689 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Remove use of QT_MODULE from libraryGunnar Sletta2012-01-251-1/+0
| | | | | | | | | | These defines were there to aid in the commercial licensing scheme we used long ago, and are no longer needed. Keep a QT_MODULE(x) define so other modules continue compiling. Change-Id: I8fd76cd5270df8f14aee746b6cf32ebf7c23fec7 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* Remove Symbian code from QtCore.Xizhi Zhu2012-01-241-109/+45
| | | | | Change-Id: I9abdc674bcfa7bb38ce27c5213c5a672f59e63d5 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* Update contact information in license headers.Jason McDonald2012-01-231-1/+1
| | | | | | | Replace Nokia contact email address with Qt Project website. Change-Id: I431bbbf76d7c27d8b502f87947675c116994c415 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update copyright year in license headers.Jason McDonald2012-01-051-1/+1
| | | | | Change-Id: I02f2c620296fcd91d4967d58767ea33fc4e1e7dc Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update licenseheader text in source files for qtbase Qt moduleJyri Tahtela2011-05-241-17/+17
| | | | | | | Updated version of LGPL and FDL licenseheaders. Apply release phase licenseheaders for all source files. Reviewed-by: Trust Me
* Initial import from the monolithic Qt.Qt by Nokia2011-04-271-0/+288
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12