Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qnumeric.h File Reference

(08ebe3465cc2fce98662b5833b75503490f66265)

#include <QtCore/qassert.h>
#include <QtCore/qminmax.h>
#include <QtCore/qtconfigmacros.h>
#include <QtCore/qtcoreexports.h>
#include <QtCore/qtypes.h>
#include <cmath>
#include <limits>
#include <QtCore/q20type_traits.h>
Include dependency graph for qnumeric.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  QtPrivate
namespace  QtPrivate::QRoundImpl

Macros

#define Q_INFINITY   (QT_PREPEND_NAMESPACE(qInf)())
#define Q_QNAN   (QT_PREPEND_NAMESPACE(qQNaN)())

Functions

template<typename T>
QT_BEGIN_NAMESPACE constexpr std::enable_if< std::is_integral< T >::value, bool >::type qIsInf (T)
template<typename T>
constexpr std::enable_if< std::is_integral< T >::value, bool >::type qIsNaN (T)
template<typename T>
constexpr std::enable_if< std::is_integral< T >::value, bool >::type qIsFinite (T)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsInf (double d)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsNaN (double d)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsFinite (double d)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION int qFpClassify (double val)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsInf (float f)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsNaN (float f)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsFinite (float f)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION int qFpClassify (float val)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION double qQNaN ()
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION double qInf ()
Q_CORE_EXPORT quint32 qFloatDistance (float a, float b)
Q_CORE_EXPORT quint64 qFloatDistance (double a, double b)
template<typename T>
constexpr std::enable_if_t< std::is_unsigned_v< T >, bool > QtPrivate::qAddOverflowGeneric (T v1, T v2, T *r)
template<typename T>
constexpr std::enable_if_t< std::is_same_v< T, decltype(+T{})>, bool > QtPrivate::qMulOverflowWideMultiplication (T v1, T v2, T *r)
template<typename T>
constexpr std::enable_if_t<(std::is_unsigned_v< T >||std::is_signed_v< T >), bool > QtPrivate::qMulOverflowGeneric (T v1, T v2, T *r)
template<typename T>
constexpr std::enable_if_t< std::is_unsigned_v< T >, bool > qAddOverflow (T v1, T v2, T *r)
template<typename T>
constexpr std::enable_if_t< std::is_signed_v< T >, bool > qAddOverflow (T v1, T v2, T *r)
template<typename T>
constexpr std::enable_if_t< std::is_unsigned_v< T >, bool > qSubOverflow (T v1, T v2, T *r)
template<typename T>
constexpr std::enable_if_t< std::is_signed_v< T >, bool > qSubOverflow (T v1, T v2, T *r)
template<typename T>
constexpr std::enable_if_t< std::is_unsigned_v< T >||std::is_signed_v< T >, bool > qMulOverflow (T v1, T v2, T *r)
template<typename T, T V2>
constexpr bool qAddOverflow (T v1, std::integral_constant< T, V2 >, T *r)
template<auto V2, typename T>
constexpr bool qAddOverflow (T v1, T *r)
template<typename T, T V2>
constexpr bool qSubOverflow (T v1, std::integral_constant< T, V2 >, T *r)
template<auto V2, typename T>
constexpr bool qSubOverflow (T v1, T *r)
template<typename T, T V2>
constexpr bool qMulOverflow (T v1, std::integral_constant< T, V2 >, T *r)
template<auto V2, typename T>
constexpr bool qMulOverflow (T v1, T *r)
template<typename T>
constexpr T qAbs (const T &t)
template<typename T, typename std::enable_if_t< std::is_integral_v< T >, bool > = true>
constexpr auto QtPrivate::qUnsignedAbs (T t)
template<typename Result, typename FP, typename std::enable_if_t< std::is_integral_v< Result >, bool > = true, typename std::enable_if_t< std::is_floating_point_v< FP >, bool > = true>
constexpr Result QtPrivate::qCheckedFPConversionToInteger (FP value)
constexpr double QtPrivate::QRoundImpl::qRound (double d)
constexpr float QtPrivate::QRoundImpl::qRound (float d)
template<typename FP, typename std::enable_if_t< std::is_floating_point_v< FP >, bool > = true>
constexpr int QtPrivate::qSaturateRound (FP value)
constexpr int qRound (double d)
constexpr int qRound (float f)
constexpr qint64 qRound64 (double d)
constexpr qint64 qRound64 (float f)
template<typename T>
constexpr const T & QtPrivate::min (const T &a, const T &b)
constexpr bool qFuzzyCompare (double p1, double p2) noexcept
constexpr bool qFuzzyCompare (float p1, float p2) noexcept
constexpr bool qFuzzyIsNull (double d) noexcept
constexpr bool qFuzzyIsNull (float f) noexcept
QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE constexpr bool qIsNull (double d) noexcept
constexpr bool qIsNull (float f) noexcept
QT_WARNING_POP int qIntCast (double f)
int qIntCast (float f)

Variables

template<typename T, typename Enable = void>
constexpr bool QtPrivate::HasLargerInt = false
template<typename T>
constexpr bool QtPrivate::HasLargerInt< T, std::void_t< typename QIntegerForSize< sizeof(T) *2 >::Unsigned > > = true

Macro Definition Documentation

◆ Q_INFINITY

#define Q_INFINITY   (QT_PREPEND_NAMESPACE(qInf)())

Definition at line 94 of file qnumeric.h.

◆ Q_QNAN

#define Q_QNAN   (QT_PREPEND_NAMESPACE(qQNaN)())

Definition at line 98 of file qnumeric.h.

Function Documentation

◆ qAbs()

template<typename T>
T qAbs ( const T & t)
inlineconstexpr

Definition at line 506 of file qnumeric.h.

◆ qAddOverflow() [1/4]

template<typename T, T V2>
bool qAddOverflow ( T v1,
std::integral_constant< T, V2 > ,
T * r )
constexpr
Since
6.1

Equivalent to qAddOverflow(v1, v2, r) with v1 as first argument, the compile time constant V2 as second argument, and r as third argument.

Definition at line 429 of file qnumeric.h.

◆ qAddOverflow() [2/4]

template<auto V2, typename T>
bool qAddOverflow ( T v1,
T * r )
constexpr
Since
6.1

Equivalent to qAddOverflow(v1, v2, r) with v1 as first argument, the compile time constant V2 as second argument, and r as third argument.

Definition at line 434 of file qnumeric.h.

◆ qAddOverflow() [3/4]

template<typename T>
std::enable_if_t< std::is_unsigned_v< T >, bool > qAddOverflow ( T v1,
T v2,
T * r )
inlineconstexpr

Definition at line 276 of file qnumeric.h.

◆ qAddOverflow() [4/4]

template<typename T>
std::enable_if_t< std::is_signed_v< T >, bool > qAddOverflow ( T v1,
T v2,
T * r )
inlineconstexpr

Definition at line 309 of file qnumeric.h.

◆ qFloatDistance() [1/2]

Q_CORE_EXPORT quint64 qFloatDistance ( double a,
double b )

◆ qFloatDistance() [2/2]

Q_CORE_EXPORT quint32 qFloatDistance ( float a,
float b )

◆ qFpClassify() [1/2]

Q_CORE_EXPORT Q_DECL_CONST_FUNCTION int qFpClassify ( double val)

Definition at line 101 of file qnumeric.cpp.

◆ qFpClassify() [2/2]

Q_CORE_EXPORT Q_DECL_CONST_FUNCTION int qFpClassify ( float val)

Definition at line 102 of file qnumeric.cpp.

◆ qFuzzyCompare() [1/2]

bool qFuzzyCompare ( double p1,
double p2 )
nodiscardconstexprnoexcept

Definition at line 617 of file qnumeric.h.

◆ qFuzzyCompare() [2/2]

bool qFuzzyCompare ( float p1,
float p2 )
nodiscardconstexprnoexcept

Definition at line 622 of file qnumeric.h.

◆ qFuzzyIsNull() [1/2]

bool qFuzzyIsNull ( double d)
nodiscardconstexprnoexcept

Definition at line 627 of file qnumeric.h.

◆ qFuzzyIsNull() [2/2]

bool qFuzzyIsNull ( float f)
nodiscardconstexprnoexcept

Definition at line 632 of file qnumeric.h.

◆ qInf()

Q_CORE_EXPORT Q_DECL_CONST_FUNCTION double qInf ( )

◆ qIntCast() [1/2]

QT_WARNING_POP int qIntCast ( double f)
inline

Definition at line 652 of file qnumeric.h.

◆ qIntCast() [2/2]

int qIntCast ( float f)
inline

Definition at line 653 of file qnumeric.h.

◆ qIsFinite() [1/3]

Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsFinite ( double d)

◆ qIsFinite() [2/3]

Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsFinite ( float f)

◆ qIsFinite() [3/3]

template<typename T>
std::enable_if< std::is_integral< T >::value, bool >::type qIsFinite ( T )
constexpr

Definition at line 73 of file qnumeric.h.

◆ qIsInf() [1/3]

Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsInf ( double d)

◆ qIsInf() [2/3]

Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsInf ( float f)

◆ qIsInf() [3/3]

template<typename T>
QT_BEGIN_NAMESPACE constexpr std::enable_if< std::is_integral< T >::value, bool >::type qIsInf ( T )
constexpr

Definition at line 67 of file qnumeric.h.

◆ qIsNaN() [1/3]

Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsNaN ( double d)

◆ qIsNaN() [2/3]

Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qIsNaN ( float f)

◆ qIsNaN() [3/3]

template<typename T>
std::enable_if< std::is_integral< T >::value, bool >::type qIsNaN ( T )
constexpr

Definition at line 70 of file qnumeric.h.

◆ qIsNull() [1/2]

QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE constexpr bool qIsNull ( double d)
nodiscardconstexprnoexcept

Definition at line 640 of file qnumeric.h.

◆ qIsNull() [2/2]

bool qIsNull ( float f)
nodiscardconstexprnoexcept

Definition at line 645 of file qnumeric.h.

◆ qMulOverflow() [1/3]

template<typename T, T V2>
bool qMulOverflow ( T v1,
std::integral_constant< T, V2 > ,
T * r )
constexpr
Since
6.1

Equivalent to qMulOverflow(v1, v2, r) with v1 as first argument, the compile time constant V2 as second argument, and r as third argument. This can be faster than calling the version with only variable arguments.

Definition at line 449 of file qnumeric.h.

◆ qMulOverflow() [2/3]

template<auto V2, typename T>
bool qMulOverflow ( T v1,
T * r )
constexpr
Since
6.1

Equivalent to qMulOverflow(v1, v2, r) with v1 as first argument, the compile time constant V2 as second argument, and r as third argument. This can be faster than calling the version with only variable arguments.

Definition at line 498 of file qnumeric.h.

◆ qMulOverflow() [3/3]

template<typename T>
std::enable_if_t< std::is_unsigned_v< T >||std::is_signed_v< T >, bool > qMulOverflow ( T v1,
T v2,
T * r )
inlineconstexpr

Definition at line 380 of file qnumeric.h.

◆ qQNaN()

Q_CORE_EXPORT Q_DECL_CONST_FUNCTION double qQNaN ( )

◆ qRound() [1/2]

int qRound ( double d)
inlineconstexpr

Definition at line 592 of file qnumeric.h.

◆ qRound() [2/2]

int qRound ( float f)
inlineconstexpr

Definition at line 597 of file qnumeric.h.

◆ qRound64() [1/2]

qint64 qRound64 ( double d)
inlineconstexpr

Definition at line 602 of file qnumeric.h.

◆ qRound64() [2/2]

qint64 qRound64 ( float f)
inlineconstexpr

Definition at line 607 of file qnumeric.h.

◆ qSubOverflow() [1/4]

template<typename T, T V2>
bool qSubOverflow ( T v1,
std::integral_constant< T, V2 > ,
T * r )
constexpr
Since
6.1

Equivalent to qSubOverflow(v1, v2, r) with v1 as first argument, the compile time constant V2 as second argument, and r as third argument.

Definition at line 439 of file qnumeric.h.

◆ qSubOverflow() [2/4]

template<auto V2, typename T>
bool qSubOverflow ( T v1,
T * r )
constexpr
Since
6.1

Equivalent to qSubOverflow(v1, v2, r) with v1 as first argument, the compile time constant V2 as second argument, and r as third argument.

Definition at line 444 of file qnumeric.h.

◆ qSubOverflow() [3/4]

template<typename T>
std::enable_if_t< std::is_unsigned_v< T >, bool > qSubOverflow ( T v1,
T v2,
T * r )
inlineconstexpr

Definition at line 341 of file qnumeric.h.

◆ qSubOverflow() [4/4]

template<typename T>
std::enable_if_t< std::is_signed_v< T >, bool > qSubOverflow ( T v1,
T v2,
T * r )
inlineconstexpr

Definition at line 358 of file qnumeric.h.