summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlocale_p.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-02-07 14:52:41 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-16 05:11:18 +0100
commit1e43b64a7a5c3823a6bdcb8d0cd28a17955939a2 (patch)
treed04a48ee55209ee5dccfc59863aa4f5df959e51f /src/corelib/tools/qlocale_p.h
parentc0791ac76ec7cfdc3945efa67a6f72ee3623413c (diff)
Centralize the merging toFloat conversions
The QByteArray version was missing the overflow check that the other versions had. Change-Id: I03cd92e5e5a84c038bee1f1ee217e93e9d9a675a Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/corelib/tools/qlocale_p.h')
-rw-r--r--src/corelib/tools/qlocale_p.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index ac12f03356..917e83834a 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/tools/qlocale_p.h
@@ -56,9 +56,13 @@
#include "QtCore/qstring.h"
#include "QtCore/qvarlengtharray.h"
#include "QtCore/qvariant.h"
+#include "QtCore/qnumeric.h"
#include "qlocale.h"
+#include <limits>
+#include <cmath>
+
QT_BEGIN_NAMESPACE
#ifndef QT_NO_SYSTEMLOCALE
@@ -227,6 +231,19 @@ public:
int width = -1,
unsigned flags = NoFlags) const;
+ // this function is meant to be called with the result of stringToDouble or bytearrayToDouble
+ static float convertDoubleToFloat(double d, bool *ok)
+ {
+ if (qIsInf(d))
+ return float(d);
+ if (std::fabs(d) > std::numeric_limits<float>::max()) {
+ if (ok != 0)
+ *ok = false;
+ return 0.0f;
+ }
+ return float(d);
+ }
+
double stringToDouble(const QChar *begin, int len, bool *ok, GroupSeparatorMode group_sep_mode) const;
qint64 stringToLongLong(const QChar *begin, int len, int base, bool *ok, GroupSeparatorMode group_sep_mode) const;
quint64 stringToUnsLongLong(const QChar *begin, int len, int base, bool *ok, GroupSeparatorMode group_sep_mode) const;