diff options
author | Mitch Curtis <mitch.curtis@nokia.com> | 2012-05-30 16:56:20 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-05 06:14:57 +0200 |
commit | 872f0b94ac7a863c59bf1175b94cca3b3636cf13 (patch) | |
tree | 41951b0fd58977349f6a621c487de0cd0bbb6a8c /src/corelib/tools/qstring.cpp | |
parent | 93ead3593997f9b67868170aa0f876eec30d3130 (diff) |
Make QString("inf").toFloat() return inf instead of zero.
Currently, QString::toFloat() returns 0 (and sets ok to false) if you
try to convert "inf". This is because inf is greater than QT_MAX_FLOAT
and there is currently no check to handle inf.
Task-number: QTBUG-8629
Change-Id: I498daf4a7a6f880f928461fca628fcaf7d1d6d08
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r-- | src/corelib/tools/qstring.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index a5a7badeac..a2d91c561c 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -48,6 +48,7 @@ #endif #include <private/qutfcodec_p.h> #include "qsimd_p.h" +#include <qnumeric.h> #include <qdatastream.h> #include <qlist.h> #include "qlocale.h" @@ -6051,14 +6052,21 @@ float QString::toFloat(bool *ok) const { bool myOk; double d = toDouble(&myOk); - if (!myOk || d > QT_MAX_FLOAT || d < -QT_MAX_FLOAT) { + if (!myOk) { + if (ok != 0) + *ok = false; + return 0.0; + } + if (qIsInf(d)) + return float(d); + if (d > QT_MAX_FLOAT || d < -QT_MAX_FLOAT) { if (ok != 0) *ok = false; return 0.0; } if (ok != 0) *ok = true; - return (float) d; + return float(d); } /*! \fn QString &QString::setNum(int n, int base) |