<QtGlobal> Proxy Page

Functions

quint32 qFloatDistance(float a, float b)
quint64 qFloatDistance(double a, double b)
int qFpClassify(double val)
int qFpClassify(float val)
double qInf()
bool qIsFinite(double d)
bool qIsFinite(float f)
bool qIsInf(float f)
bool qIsNaN(double d)
bool qIsNaN(float f)
double qQNaN()
double qSNaN()

Function Documentation

int qFpClassify(double val)

int qFpClassify(float val)

Classifies a floating-point value.

The return values are defined in <cmath>: returns one of the following, determined by the floating-point class of val:

  • FP_NAN not a number
  • FP_INFINITE infinities (positive or negative)
  • FP_ZERO zero (positive or negative)
  • FP_NORMAL finite with a full mantissa
  • FP_SUBNORMAL finite with a reduced mantissa

[since 5.2] quint32 qFloatDistance(float a, float b)

Returns the number of representable floating-point numbers between a and b.

This function provides an alternative way of doing approximated comparisons of floating-point numbers similar to qFuzzyCompare(). However, it returns the distance between two numbers, which gives the caller a possibility to choose the accepted error. Errors are relative, so for instance the distance between 1.0E-5 and 1.00001E-5 will give 110, while the distance between 1.0E36 and 1.00001E36 will give 127.

This function is useful if a floating point comparison requires a certain precision. Therefore, if a and b are equal it will return 0. The maximum value it will return for 32-bit floating point numbers is 4,278,190,078. This is the distance between -FLT_MAX and +FLT_MAX.

The function does not give meaningful results if any of the arguments are Infinite or NaN. You can check for this by calling qIsFinite().

The return value can be considered as the "error", so if you for instance want to compare two 32-bit floating point numbers and all you need is an approximated 24-bit precision, you can use this function like this:

     if (qFloatDistance(a, b) < (1 << 7)) {   // The last 7 bits are not
                                             // significant
         // precise enough
     }

This function was introduced in Qt 5.2.

See also qFuzzyCompare().

[since 5.2] quint64 qFloatDistance(double a, double b)

Returns the number of representable floating-point numbers between a and b.

This function serves the same purpose as qFloatDistance(float, float), but returns the distance between two double numbers. Since the range is larger than for two float numbers ([-DBL_MAX,DBL_MAX]), the return type is quint64.

This function was introduced in Qt 5.2.

See also qFuzzyCompare().

int qFpClassify(double val)

int qFpClassify(float val)

double qInf()

Returns the bit pattern for an infinite number as a double.

See also qIsInf().

bool qIsFinite(double d)

Returns true if the double d is a finite number.

bool qIsFinite(float f)

Returns true if the float f is a finite number.

bool qIsInf(float f)

Returns true if the float f is equivalent to infinity.

See also qInf().

bool qIsNaN(double d)

Returns true if the double d is not a number (NaN).

bool qIsNaN(float f)

Returns true if the float f is not a number (NaN).

double qQNaN()

Returns the bit pattern of a quiet NaN as a double.

See also qIsNaN().

double qSNaN()

Returns the bit pattern of a signalling NaN as a double.