From 1e43b64a7a5c3823a6bdcb8d0cd28a17955939a2 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 7 Feb 2014 14:52:41 -0800 Subject: 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 --- src/corelib/tools/qlocale_p.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/corelib/tools/qlocale_p.h') 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 +#include + 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::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; -- cgit v1.2.3