Skip to content

Commit

Permalink
Fix some QJSValue test failures.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Glenn Watson authored and Qt by Nokia committed Feb 6, 2012
1 parent 9d12cc1 commit 0323a56
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/declarative/qml/v8/qjsvalue_impl_p.h
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0323a56

Please sign in to comment.