diff options
author | Glenn Watson <glenn.watson@nokia.com> | 2012-02-03 11:21:24 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-06 04:10:41 +0100 |
commit | 0323a56a04dd4d858eb0c98955d179b8418c1ed7 (patch) | |
tree | ea0bd3b91ff5bcd3f6cb6ce218b8b04ea8713f3a /src/declarative | |
parent | 9d12cc1544028ee12e0355c364e3a36360236638 (diff) |
Fix some QJSValue test failures.
Fix precision issues causing test failures on platforms where
qreal is defined as single precision. Also use explicit casts
to ensure well defined behaviour when converting a negative
double value to an unsigned integer.
Change-Id: Ia0048bf83169d3b617f70828f86368c23f4f3786
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/qml/v8/qjsvalue_impl_p.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/declarative/qml/v8/qjsvalue_impl_p.h b/src/declarative/qml/v8/qjsvalue_impl_p.h index 69ec70beed..cd33859c50 100644 --- a/src/declarative/qml/v8/qjsvalue_impl_p.h +++ b/src/declarative/qml/v8/qjsvalue_impl_p.h @@ -304,7 +304,11 @@ double QJSValuePrivate::toInteger() const return 0; if (qIsInf(result)) return result; - return (result > 0) ? qFloor(result) : -1 * qFloor(-result); + + // Must use floor explicitly rather than qFloor here. On some + // platforms qFloor will cast the value to a single precision float and use + // floorf() which results in test failures. + return (result > 0) ? floor(result) : -1 * floor(-result); } qint32 QJSValuePrivate::toInt32() const @@ -324,7 +328,11 @@ quint32 QJSValuePrivate::toUInt32() const // some of these operation are invoked in toInteger subcall. if (qIsInf(result)) return 0; - return result; + + // The explicit casts are required to avoid undefined behaviour. For example, casting + // a negative double directly to an unsigned int on ARM NEON FPU results in the value + // being set to zero. Casting to a signed int first ensures well defined behaviour. + return (quint32) (qint32) result; } quint16 QJSValuePrivate::toUInt16() const |