diff options
author | The Qt Project <gerrit-noreply@qt-project.org> | 2019-11-25 14:49:13 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2019-11-25 14:49:13 +0000 |
commit | bc1cae774ad8cc084a98cb37d363770efbde025c (patch) | |
tree | aeb16a5fa9093632eba6143fe53ef1dad3e383a4 /src/corelib/global/qnumeric_p.h | |
parent | 8d35ad8726f44c4e853b5a192203ffcbbd2476e1 (diff) | |
parent | 26e876912435bdafbca2b425af43824d7ec5b876 (diff) |
Merge "Merge remote-tracking branch 'origin/dev' into wip/cmake" into wip/cmake
Diffstat (limited to 'src/corelib/global/qnumeric_p.h')
-rw-r--r-- | src/corelib/global/qnumeric_p.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/corelib/global/qnumeric_p.h b/src/corelib/global/qnumeric_p.h index 86e7997680..c006296b3d 100644 --- a/src/corelib/global/qnumeric_p.h +++ b/src/corelib/global/qnumeric_p.h @@ -202,7 +202,7 @@ namespace { This function works for v containing infinities, but not NaN. It's the caller's responsibility to exclude that possibility before calling it. */ -template <typename T> static inline bool convertDoubleTo(double v, T *value) +template <typename T> static inline bool convertDoubleTo(double v, T *value, bool allow_precision_upgrade = true) { Q_STATIC_ASSERT(std::numeric_limits<T>::is_integer); @@ -227,6 +227,10 @@ template <typename T> static inline bool convertDoubleTo(double v, T *value) supremum = -2.0 * std::numeric_limits<ST>::min(); // -2 * (-2^63) = 2^64, exact (for T = quint64) v = fabs(v); } + if (std::is_integral<T>::value && sizeof(T) > 4 && !allow_precision_upgrade) { + if (v > double(Q_INT64_C(1)<<53) || v < double(-((Q_INT64_C(1)<<53) + 1))) + return false; + } *value = std::numeric_limits<T>::max(); if (v >= supremum) |