Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qmath.h File Reference

(85c69f023fe281b7f16e1a93e61be4432f7fef9b)

#include <QtCore/qglobal.h>
#include <QtCore/qalgorithms.h>
#include <cmath>
+ Include dependency graph for qmath.h:

Go to the source code of this file.

Classes

struct  QtPrivate::QHypotType< R, F >
 
class  QtPrivate::QHypotHelper< T >
 

Namespaces

namespace  QtPrivate
 \macro QT_NO_KEYWORDS >
 

Macros

#define _USE_MATH_DEFINES
 
#define undef_USE_MATH_DEFINES
 
#define QT_SINE_TABLE_SIZE   256
 
#define M_E   (2.7182818284590452354)
 
#define M_LOG2E   (1.4426950408889634074)
 
#define M_LOG10E   (0.43429448190325182765)
 
#define M_LN2   (0.69314718055994530942)
 
#define M_LN10   (2.30258509299404568402)
 
#define M_PI   (3.14159265358979323846)
 
#define M_PI_2   (1.57079632679489661923)
 
#define M_PI_4   (0.78539816339744830962)
 
#define M_1_PI   (0.31830988618379067154)
 
#define M_2_PI   (0.63661977236758134308)
 
#define M_2_SQRTPI   (1.12837916709551257390)
 
#define M_SQRT2   (1.41421356237309504880)
 
#define M_SQRT1_2   (0.70710678118654752440)
 

Functions

template<typename T >
int qCeil (T v)
 
template<typename T >
int qFloor (T v)
 
template<typename T >
auto qFabs (T v)
 
template<typename T >
auto qSin (T v)
 
template<typename T >
auto qCos (T v)
 
template<typename T >
auto qTan (T v)
 
template<typename T >
auto qAcos (T v)
 
template<typename T >
auto qAsin (T v)
 
template<typename T >
auto qAtan (T v)
 
template<typename T1 , typename T2 >
auto qAtan2 (T1 y, T2 x)
 
template<typename T >
auto qSqrt (T v)
 
template<typename F , typename ... Fs>
auto qHypot (F first, Fs... rest)
 
template<typename Tx , typename Ty >
auto qHypot (Tx x, Ty y)
 
template<typename T >
auto qLn (T v)
 
template<typename T >
auto qExp (T v)
 
template<typename T1 , typename T2 >
auto qPow (T1 x, T2 y)
 
qreal qFastSin (qreal x)
 
qreal qFastCos (qreal x)
 
constexpr float qDegreesToRadians (float degrees)
 
constexpr double qDegreesToRadians (double degrees)
 
constexpr long double qDegreesToRadians (long double degrees)
 
template<typename T , std::enable_if_t< std::is_integral_v< T >, bool > = true>
constexpr double qDegreesToRadians (T degrees)
 
constexpr float qRadiansToDegrees (float radians)
 
constexpr double qRadiansToDegrees (double radians)
 
constexpr long double qRadiansToDegrees (long double radians)
 
constexpr quint32 QtPrivate::qConstexprNextPowerOfTwo (quint32 v)
 
constexpr quint64 QtPrivate::qConstexprNextPowerOfTwo (quint64 v)
 
constexpr quint32 QtPrivate::qConstexprNextPowerOfTwo (qint32 v)
 
constexpr quint64 QtPrivate::qConstexprNextPowerOfTwo (qint64 v)
 
constexpr quint32 qNextPowerOfTwo (quint32 v)
 
constexpr quint64 qNextPowerOfTwo (quint64 v)
 
constexpr quint32 qNextPowerOfTwo (qint32 v)
 
constexpr quint64 qNextPowerOfTwo (qint64 v)
 
constexpr unsigned long qNextPowerOfTwo (unsigned long v)
 
constexpr unsigned long qNextPowerOfTwo (long v)
 

Variables

Q_CORE_EXPORT const qreal qt_sine_table [QT_SINE_TABLE_SIZE]
 

Macro Definition Documentation

◆ _USE_MATH_DEFINES

#define _USE_MATH_DEFINES

Definition at line 19 of file qmath.h.

◆ M_1_PI

#define M_1_PI   (0.31830988618379067154)

Definition at line 221 of file qmath.h.

Referenced by addCircle(), and qt_fetch_conical_gradient_template().

◆ M_2_PI

#define M_2_PI   (0.63661977236758134308)

Definition at line 225 of file qmath.h.

◆ M_2_SQRTPI

#define M_2_SQRTPI   (1.12837916709551257390)

Definition at line 229 of file qmath.h.

◆ M_E

#define M_E   (2.7182818284590452354)

Definition at line 189 of file qmath.h.

Referenced by QV4::Heap::MathObject::init().

◆ M_LN10

#define M_LN10   (2.30258509299404568402)

Definition at line 205 of file qmath.h.

Referenced by QV4::Heap::MathObject::init().

◆ M_LN2

#define M_LN2   (0.69314718055994530942)

Definition at line 201 of file qmath.h.

Referenced by QV4::Heap::MathObject::init().

◆ M_LOG10E

#define M_LOG10E   (0.43429448190325182765)

Definition at line 197 of file qmath.h.

Referenced by QV4::Heap::MathObject::init().

◆ M_LOG2E

#define M_LOG2E   (1.4426950408889634074)

Definition at line 193 of file qmath.h.

Referenced by QV4::Heap::MathObject::init().

◆ M_PI

◆ M_PI_2

#define M_PI_2   (1.57079632679489661923)

◆ M_PI_4

#define M_PI_4   (0.78539816339744830962)

Definition at line 217 of file qmath.h.

◆ M_SQRT1_2

#define M_SQRT1_2   (0.70710678118654752440)

Definition at line 237 of file qmath.h.

Referenced by QV4::Heap::MathObject::init().

◆ M_SQRT2

#define M_SQRT2   (1.41421356237309504880)

Definition at line 233 of file qmath.h.

Referenced by QV4::Heap::MathObject::init().

◆ QT_SINE_TABLE_SIZE

#define QT_SINE_TABLE_SIZE   256

Definition at line 32 of file qmath.h.

Referenced by qFastCos(), and qFastSin().

◆ undef_USE_MATH_DEFINES

#define undef_USE_MATH_DEFINES

Definition at line 20 of file qmath.h.

Function Documentation

◆ qAcos()

template<typename T >
auto qAcos ( T v)

Definition at line 72 of file qmath.h.

Referenced by addCircle(), QQuick3DQuaternionUtils::lookAt(), and rotationQuaternionForLookAt().

+ Here is the caller graph for this function:

◆ qAsin()

template<typename T >
auto qAsin ( T v)

Definition at line 78 of file qmath.h.

◆ qAtan()

template<typename T >
auto qAtan ( T v)

Definition at line 84 of file qmath.h.

Referenced by QQC2::QStyleHelper::angle(), EaseOvershoot(), and QSSGRenderCamera::verticalFov().

+ Here is the caller graph for this function:

◆ qAtan2()

template<typename T1 , typename T2 >
auto qAtan2 ( T1 y,
T2 x )

Definition at line 90 of file qmath.h.

Referenced by QQuickFrictionAffector::affectParticle(), QQuickMaterialRipple::anchorPoint(), QLineF::angle(), computeAngle(), QQuickParentChangePrivate::doChange(), QQuickSvgParser::pathArc(), pathArc(), qt_fetch_conical_gradient_template(), QQuickParentAnimation::transition(), and AVFMediaPlayer::videoOrientationForAssetTrack().

+ Here is the caller graph for this function:

◆ qCeil()

template<typename T >
int qCeil ( T v)

Definition at line 36 of file qmath.h.

Referenced by QFontEngine::alphaMapForGlyph(), QSvgAnimateColor::apply(), QGridLayoutItem::box(), QQuickStyleItemTextField::calculateGeometry(), QQuickTextInputPrivate::calculateImplicitWidthForText(), QQuickBorderImagePrivate::calculateRects(), QQuickStyleItem::contentSize(), QDistanceFieldData::create(), QCommandLinkButtonPrivate::descriptionHeight(), QTextLayout::draw(), drawCellBorder(), QTextLayout::drawCursor(), QPaintEngine::drawImage(), QRasterPaintEngine::drawImage(), drawTextItemDecoration(), QTextDocumentLayout::dynamicPageCount(), QQuickLayout::effectiveSizeHints_helper(), QTimeLine::frameForTime(), QSSGMesh::Mesh::fromAssetData(), QSSGMesh::Mesh::fromRuntimeData(), generateWavyPixmap(), getLineHeightParams(), QRasterPaintEnginePrivate::getPenFunc(), intmaxlog(), QPrintPreviewWidgetPrivate::layoutPages(), QQuickTextPrivate::lineHeightOffset(), QScrollerPrivate::nextSnapPos(), QSGOpenVGPainterNode::paint(), QSGSoftwarePainterNode::paint(), QSGDefaultPainterNode::paint(), QQuickBasicDial::paint(), QStaticTextPrivate::paintText(), QQuickSvgParser::pathArc(), pathArc(), QSvgPattern::patternImage(), QAccessibleBridgeUtils::performEffectiveAction(), QTextureGlyphCache::populate(), QQC2::qDrawBorderPixmap(), QSGSoftwareHelpers::qDrawBorderPixmap(), qt_convertMargins(), qt_findAtNxFile(), qt_scale_image_16bit(), qt_scale_image_32bit(), qt_transform_image(), read_jpeg_image(), QSSGMesh::MeshInternal::readMeshData(), QMdi::RegularTiler::rearrange(), QComboBoxPrivate::recomputeSizeHint(), QSGRhiDistanceFieldGlyphCache::requestGlyphs(), QMdiAreaPrivate::resizeToMinimumTileSize(), QSvgAnimateTransform::resolveMatrix(), QHighDpiScaling::roundScaleFactor(), QSvgPaintEngine::saveGradientStops(), QIconLoaderEngine::scaledPixmap(), segmentCount(), QWindowsIntegration::setApplicationBadge(), QQuickTextPrivate::setupTextLayout(), QLabelPrivate::sizeForWidth(), QWasmAudioSink::start(), QSGRhiDistanceFieldGlyphCache::storeGlyphs(), QQC2_NAMESPACE::QMacStyle::subControlRect(), QMacStyle::subControlRect(), QQC2_NAMESPACE::QMacStyle::subElementRect(), QQC2::QCommonStyle::subElementRect(), QMacStyle::subElementRect(), QCommonStyle::subElementRect(), QItemDelegatePrivate::textLayoutBounds(), QItemDelegate::textRectangle(), QRectF::toAlignedRect(), toRectMin(), QQuickMaterialBusyIndicatorNode::updateCurrentTime(), updateDirtySkeletons(), QSGBasicInternalImageNode::updateGeometry(), QSGBasicInternalRectangleNode::updateGeometry(), QSGBasicInternalImageNode::updateGeometry(), QQuickIconImagePrivate::updateIcon(), QQuickTextInputPrivate::updateLayout(), QQuickImage::updatePaintNode(), QQuickShaderEffectSource::updatePaintNode(), QQuickTextPrivate::updateSize(), QQuick3DSkin::updateSpatialNode(), QQuick3DTexture::updateSpatialNode(), and QSSGQmlUtilities::writeQmlForAnimation().

◆ qCos()

◆ qDegreesToRadians() [1/4]

constexpr double qDegreesToRadians ( double degrees)
inlineconstexpr

Definition at line 265 of file qmath.h.

References M_PI.

◆ qDegreesToRadians() [2/4]

constexpr float qDegreesToRadians ( float degrees)
inlineconstexpr

Definition at line 260 of file qmath.h.

References M_PI.

Referenced by QQuickGravityAffector::affectParticle(), QGeoCoordinatePrivate::atDistanceAndAzimuth(), QGeoCoordinate::azimuthTo(), QSSGUtils::degToRad(), QGeoCoordinate::distanceTo(), QOpenGL2PaintEngineExPrivate::drawPixmapFragments(), QLineF::fromPolar(), QT_BEGIN_NAMESPACE::generateMeshLevelsOfDetail(), QQuickImageParticle::initialize(), makeDistanceField(), BasicOperations::paintEvent(), parseTransformationMatrix(), QQuickSvgParser::pathArc(), pathArcSegment(), QDoubleMatrix4x4::perspective(), QMatrix4x4::perspective(), QMatrix4x4::projectedRotate(), qDegreesToRadians(), qt_fromEulerRotation(), qt_normalFromRotation(), qt_t_for_arc_angle(), QLocationUtils::radians(), AVFMediaEncoder::record(), QSvgAnimateTransform::resolveMatrix(), QDoubleMatrix4x4::rotate(), QMatrix4x4::rotate(), QTransform::rotate(), QLineF::setAngle(), QSSGMaterialShaderGenerator::setRhiMaterialProperties(), QSpanData::setup(), setupCameraForShadowMap(), setupCubeReflectionCameras(), setupCubeShadowCameras(), transformFromLine(), QWindowsTabletSupport::translateTabletPacketEvent(), QOpenGL2PaintEngineExPrivate::updateBrushUniforms(), QQuick3DPerspectiveCamera::updateSpatialNode(), QT_BEGIN_NAMESPACE::QSGCurveFillMaterialShader::updateUniformData(), QQuickShapeConicalGradientRhiShader::updateUniformData(), and QSSGParticleRenderer::updateUniformsForParticles().

+ Here is the caller graph for this function:

◆ qDegreesToRadians() [3/4]

constexpr long double qDegreesToRadians ( long double degrees)
inlineconstexpr

Definition at line 270 of file qmath.h.

References M_PI.

◆ qDegreesToRadians() [4/4]

template<typename T , std::enable_if_t< std::is_integral_v< T >, bool > = true>
constexpr double qDegreesToRadians ( T degrees)
inlineconstexpr

Definition at line 276 of file qmath.h.

References qDegreesToRadians().

+ Here is the call graph for this function:

◆ qExp()

template<typename T >
auto qExp ( T v)

Definition at line 174 of file qmath.h.

◆ qFabs()

template<typename T >
auto qFabs ( T v)

Definition at line 48 of file qmath.h.

Referenced by EVRCustomPresenter::IsRateSupported().

+ Here is the caller graph for this function:

◆ qFastCos()

qreal qFastCos ( qreal x)
inline

Definition at line 250 of file qmath.h.

References d, M_PI, qt_sine_table, and QT_SINE_TABLE_SIZE.

Referenced by QOpenGL2PaintEngineExPrivate::drawPixmapFragments(), QTriangulatingStroker::process(), and QSGBasicInternalRectangleNode::updateGeometry().

+ Here is the caller graph for this function:

◆ qFastSin()

qreal qFastSin ( qreal x)
inline

Definition at line 240 of file qmath.h.

References d, M_PI, qt_sine_table, and QT_SINE_TABLE_SIZE.

Referenced by QOpenGL2PaintEngineExPrivate::drawPixmapFragments(), QTriangulatingStroker::process(), and QSGBasicInternalRectangleNode::updateGeometry().

+ Here is the caller graph for this function:

◆ qFloor()

template<typename T >
int qFloor ( T v)

Definition at line 42 of file qmath.h.

Referenced by QQuickGridViewPrivate::addVisibleItems(), QQuick3DParticleScaleAffector::affectParticle(), QFontEngine::alphaMapForGlyph(), QSvgAnimateColor::apply(), QQuickGridViewPrivate::applyInsertionChange(), QQuickTableViewPrivate::calculateTopLeft(), QDirectFbBlitter::drawCachedGlyphs(), QRasterPaintEngine::drawCachedGlyphs(), QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(), drawCellBorder(), QPaintEngine::drawImage(), QRasterPaintEngine::drawImage(), QX11PaintEngine::drawPoints(), drawTextItemDecoration(), fetchTransformed_fetcher(), fetchTransformedBilinear_slow_fetcher(), QX11PaintEnginePrivate::fillPolygon_dev(), firstDayOfYear(), generateWavyPixmap(), QWaylandOutputPrivate::handleWindowPixelSizeChanged(), QWaylandOutput::initialize(), QWaylandSurface::inputRegionContains(), QJalaliCalendar::julianDayToDate(), QPrintPreviewWidgetPrivate::layoutPages(), QWindowsFontEngine::minRightBearing(), QRhi::mipLevelsForSize(), QScrollerPrivate::nextSnapPos(), QSGOpenVGPainterNode::paint(), QSGSoftwarePainterNode::paint(), QSGDefaultPainterNode::paint(), QQuickBasicDial::paint(), QQuickStyledTextPrivate::parseImageAttributes(), QSGTextMaskMaterial::populate(), QQuickPathView::positionViewAtIndex(), qDrawEdge(), qt_convertPointsToPixels(), qt_curves_for_arc(), qt_find_ellipse_coords(), qt_image_convolute_filter(), qt_scale_image_16bit(), qt_scale_image_32bit(), qt_transform_image(), QQuickGridViewPrivate::resetColumns(), QHighDpiScaling::roundScaleFactor(), QBackingStore::scroll(), QRectF::toAlignedRect(), toRectMin(), QSGBasicInternalImageNode::updateGeometry(), QSGBasicInternalImageNode::updateGeometry(), and QDoubleValidatorPrivate::validateWithLocale().

◆ qHypot() [1/2]

template<typename F , typename ... Fs>
auto qHypot ( F first,
Fs... rest )

Definition at line 145 of file qmath.h.

References QtPrivate::QHypotHelper< T >::add().

+ Here is the call graph for this function:

◆ qHypot() [2/2]

template<typename Tx , typename Ty >
auto qHypot ( Tx x,
Ty y )

Definition at line 152 of file qmath.h.

◆ qLn()

template<typename T >
auto qLn ( T v)

Definition at line 168 of file qmath.h.

Referenced by intmaxlog().

+ Here is the caller graph for this function:

◆ qNextPowerOfTwo() [1/6]

constexpr unsigned long qNextPowerOfTwo ( long v)
inlineconstexpr

Definition at line 378 of file qmath.h.

References qNextPowerOfTwo().

+ Here is the call graph for this function:

◆ qNextPowerOfTwo() [2/6]

constexpr quint32 qNextPowerOfTwo ( qint32 v)
inlineconstexpr

Definition at line 363 of file qmath.h.

References qNextPowerOfTwo().

+ Here is the call graph for this function:

◆ qNextPowerOfTwo() [3/6]

constexpr quint64 qNextPowerOfTwo ( qint64 v)
inlineconstexpr

Definition at line 368 of file qmath.h.

References qNextPowerOfTwo().

+ Here is the call graph for this function:

◆ qNextPowerOfTwo() [4/6]

constexpr quint32 qNextPowerOfTwo ( quint32 v)
inlineconstexpr

Definition at line 335 of file qmath.h.

References Q_ASSERT, and QtPrivate::qConstexprNextPowerOfTwo().

Referenced by QSGRhiAtlasTexture::Manager::Manager(), QSSGRhiContext::checkAndAdjustForNPoT(), QSGPlainTexture::commitTextureOperations(), QTextureGlyphCache::fillInPendingGlyphs(), QTextureGlyphCache::populate(), QV4::MarkStack::push(), qCalculateGrowingBlockSize(), qNextPowerOfTwo(), qNextPowerOfTwo(), qNextPowerOfTwo(), qNextPowerOfTwo(), QOpenGLTextureUploader::textureImage(), and QOpenGL2PaintEngineExPrivate::updateBrushTexture().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qNextPowerOfTwo() [5/6]

constexpr quint64 qNextPowerOfTwo ( quint64 v)
inlineconstexpr

Definition at line 349 of file qmath.h.

References Q_ASSERT, Q_UINT64_C, and QtPrivate::qConstexprNextPowerOfTwo().

+ Here is the call graph for this function:

◆ qNextPowerOfTwo() [6/6]

constexpr unsigned long qNextPowerOfTwo ( unsigned long v)
inlineconstexpr

Definition at line 373 of file qmath.h.

References qNextPowerOfTwo().

+ Here is the call graph for this function:

◆ qPow()

template<typename T1 , typename T2 >
auto qPow ( T1 x,
T2 y )

◆ qRadiansToDegrees() [1/3]

constexpr double qRadiansToDegrees ( double radians)
inlineconstexpr

Definition at line 286 of file qmath.h.

References M_PI.

◆ qRadiansToDegrees() [2/3]

◆ qRadiansToDegrees() [3/3]

constexpr long double qRadiansToDegrees ( long double radians)
inlineconstexpr

Definition at line 291 of file qmath.h.

References M_PI.

◆ qSin()

◆ qSqrt()

template<typename T >
auto qSqrt ( T v)

Definition at line 96 of file qmath.h.

◆ qTan()

template<typename T >
auto qTan ( T v)

Definition at line 66 of file qmath.h.

Referenced by parseTransformationMatrix(), QSvgAnimateTransform::resolveMatrix(), and QSSGRenderCamera::verticalFov().

+ Here is the caller graph for this function:

Variable Documentation

◆ qt_sine_table

Q_CORE_EXPORT const qreal qt_sine_table[QT_SINE_TABLE_SIZE]
extern

Definition at line 9 of file qmath.cpp.

Referenced by qFastCos(), and qFastSin().