summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-11-27 01:00:08 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-11-27 01:00:09 +0100
commit1b5bbacdb0888c01de588bf3b4d42166757c98e0 (patch)
treeadba8989ebb09a024c5e5924d2910856ca42473f /src/corelib/tools
parentba13c6c08f30a4c2f188f69deeaf4ca6a020d7a1 (diff)
parent71bd06d516a2410ae0ea698e79dcb94aba9bc5b4 (diff)
Merge remote-tracking branch 'origin/5.11' into 5.12
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qbytearray.cpp6
-rw-r--r--src/corelib/tools/qlocale.cpp36
-rw-r--r--src/corelib/tools/qlocale_p.h11
-rw-r--r--src/corelib/tools/qlocale_tools.cpp2
-rw-r--r--src/corelib/tools/qstring.cpp12
5 files changed, 47 insertions, 20 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 53ae7b9452..c8bb384532 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -4114,7 +4114,8 @@ ushort QByteArray::toUShort(bool *ok, int base) const
/*!
Returns the byte array converted to a \c double value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -4149,7 +4150,8 @@ double QByteArray::toDouble(bool *ok) const
/*!
Returns the byte array converted to a \c float value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index ddc973cb37..1f5d5f0dc6 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -1366,8 +1366,10 @@ qulonglong QLocale::toULongLong(const QString &s, bool *ok) const
}
/*!
- Returns the float represented by the localized string \a s, or 0.0
- if the conversion failed.
+ Returns the float represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1386,8 +1388,10 @@ float QLocale::toFloat(const QString &s, bool *ok) const
}
/*!
- Returns the double represented by the localized string \a s, or
- 0.0 if the conversion failed.
+ Returns the double represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1533,8 +1537,10 @@ qulonglong QLocale::toULongLong(const QStringRef &s, bool *ok) const
}
/*!
- Returns the float represented by the localized string \a s, or 0.0
- if the conversion failed.
+ Returns the float represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1555,8 +1561,10 @@ float QLocale::toFloat(const QStringRef &s, bool *ok) const
}
/*!
- Returns the double represented by the localized string \a s, or
- 0.0 if the conversion failed.
+ Returns the double represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1705,8 +1713,10 @@ qulonglong QLocale::toULongLong(QStringView s, bool *ok) const
}
/*!
- Returns the float represented by the localized string \a s, or 0.0
- if the conversion failed.
+ Returns the float represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1724,8 +1734,10 @@ float QLocale::toFloat(QStringView s, bool *ok) const
}
/*!
- Returns the double represented by the localized string \a s, or
- 0.0 if the conversion failed.
+ Returns the double represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index a9c23aed61..a96ecf1c1c 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/tools/qlocale_p.h
@@ -249,7 +249,16 @@ public:
if (std::fabs(d) > std::numeric_limits<float>::max()) {
if (ok != 0)
*ok = false;
- return 0.0f;
+ const float huge = std::numeric_limits<float>::infinity();
+ return d < 0 ? -huge : huge;
+ }
+ if (std::fabs(d) >= std::numeric_limits<double>::min() // i.e. d != 0
+ && std::fabs(d) < std::numeric_limits<float>::min()) {
+ // Values smaller than std::numeric_limits<double>::min() have
+ // failed already; match them.
+ if (ok != 0)
+ *ok = false;
+ return 0;
}
return float(d);
}
diff --git a/src/corelib/tools/qlocale_tools.cpp b/src/corelib/tools/qlocale_tools.cpp
index bde52a20b9..53258bec3e 100644
--- a/src/corelib/tools/qlocale_tools.cpp
+++ b/src/corelib/tools/qlocale_tools.cpp
@@ -354,7 +354,7 @@ double qt_asciiToDouble(const char *num, int numLen, bool &ok, int &processed,
ok = false;
for (int i = 0; i < processed; ++i) {
char c = num[i];
- if ((c < '0' || c > '9') && c != '.' && c != '-' && c != '+' && c != 'e') {
+ if ((c < '0' || c > '9') && c != '.' && c != '-' && c != '+' && c != 'e' && c != 'E') {
// Garbage found
processed = 0;
return 0.0;
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index d5a67352ad..edb9983c33 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -7401,7 +7401,8 @@ ushort QString::toUShort(bool *ok, int base) const
/*!
Returns the string converted to a \c double value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -7439,7 +7440,8 @@ double QString::toDouble(bool *ok) const
/*!
Returns the string converted to a \c float value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -12008,7 +12010,8 @@ ushort QStringRef::toUShort(bool *ok, int base) const
/*!
Returns the string converted to a \c double value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -12033,7 +12036,8 @@ double QStringRef::toDouble(bool *ok) const
/*!
Returns the string converted to a \c float value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.