diff options
author | Jan Arve Saether <jan-arve.saether@digia.com> | 2013-07-31 15:43:09 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-27 07:57:23 +0200 |
commit | e37001aad7f6e4bbad250addba033f1eaf97d566 (patch) | |
tree | e83a70da7f50edd967128f84df18287e805e30a9 /src/corelib/global/qnumeric.h | |
parent | 88999e9ea037ee79557d0c012ad9fdfc72fb5ece (diff) |
Say hello to qFloatDistance()
This function is useful if a floating point comparison requires a
certain precision. The return value can be considered as the precision.
For instance, if you want to compare two 32-bit floating point values
and all you need is a 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
}
Task-number: QTBUG-32632
Change-Id: I020a58d2f9f9452ac3c510b4bb560dc806f0d93c
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global/qnumeric.h')
-rw-r--r-- | src/corelib/global/qnumeric.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/corelib/global/qnumeric.h b/src/corelib/global/qnumeric.h index 25db5443eb..633486dff1 100644 --- a/src/corelib/global/qnumeric.h +++ b/src/corelib/global/qnumeric.h @@ -57,6 +57,9 @@ Q_CORE_EXPORT double qSNaN(); Q_CORE_EXPORT double qQNaN(); Q_CORE_EXPORT double qInf(); +Q_CORE_EXPORT quint32 qFloatDistance(float a, float b); +Q_CORE_EXPORT quint64 qFloatDistance(double a, double b); + #define Q_INFINITY (QT_PREPEND_NAMESPACE(qInf)()) #define Q_SNAN (QT_PREPEND_NAMESPACE(qSNaN)()) #define Q_QNAN (QT_PREPEND_NAMESPACE(qQNaN)()) |