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

(df97b6b2de6282bd6422f1e531a42475dadc980d)

#include <QtCore/qassert.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 80 of file qnumeric.h.

◆ Q_QNAN

#define Q_QNAN   (QT_PREPEND_NAMESPACE(qQNaN)())

Definition at line 84 of file qnumeric.h.

Function Documentation

◆ qAbs()

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

Definition at line 475 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 400 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 405 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 262 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 292 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 98 of file qnumeric.cpp.

◆ qFpClassify() [2/2]

Q_CORE_EXPORT Q_DECL_CONST_FUNCTION int qFpClassify ( float val)

Definition at line 99 of file qnumeric.cpp.

◆ qFuzzyCompare() [1/2]

bool qFuzzyCompare ( double p1,
double p2 )
nodiscardconstexprnoexcept

Definition at line 578 of file qnumeric.h.

◆ qFuzzyCompare() [2/2]

bool qFuzzyCompare ( float p1,
float p2 )
nodiscardconstexprnoexcept

Definition at line 583 of file qnumeric.h.

◆ qFuzzyIsNull() [1/2]

bool qFuzzyIsNull ( double d)
nodiscardconstexprnoexcept

Definition at line 588 of file qnumeric.h.

◆ qFuzzyIsNull() [2/2]

bool qFuzzyIsNull ( float f)
nodiscardconstexprnoexcept

Definition at line 593 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 613 of file qnumeric.h.

◆ qIntCast() [2/2]

int qIntCast ( float f)
inline

Definition at line 614 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 59 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 53 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 56 of file qnumeric.h.

◆ qIsNull() [1/2]

QT_WARNING_PUSH QT_WARNING_DISABLE_FLOAT_COMPARE constexpr bool qIsNull ( double d)
nodiscardconstexprnoexcept

Definition at line 601 of file qnumeric.h.

◆ qIsNull() [2/2]

bool qIsNull ( float f)
nodiscardconstexprnoexcept

Definition at line 606 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 420 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 467 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 354 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 553 of file qnumeric.h.

◆ qRound() [2/2]

int qRound ( float f)
inlineconstexpr

Definition at line 558 of file qnumeric.h.

◆ qRound64() [1/2]

qint64 qRound64 ( double d)
inlineconstexpr

Definition at line 563 of file qnumeric.h.

◆ qRound64() [2/2]

qint64 qRound64 ( float f)
inlineconstexpr

Definition at line 568 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 410 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 415 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 321 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 335 of file qnumeric.h.