From b42be1c5ce09c36f1d435c2fc847c3db46b683f1 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 15 Apr 2016 12:22:12 +0200 Subject: V4: Use std::copysign instead of home-grown bit twiddling. Of course, not every standard library correctly implements C++11, so there we fall back to copysign from math.h Change-Id: I0283640ef69803a338ff1969c94c92c7ab1d71cb Reviewed-by: Robin Burchell --- src/qml/jsruntime/qv4mathobject.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/qml/jsruntime/qv4mathobject.cpp') diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp index 4a304b6138..50b81098b2 100644 --- a/src/qml/jsruntime/qv4mathobject.cpp +++ b/src/qml/jsruntime/qv4mathobject.cpp @@ -85,17 +85,18 @@ Heap::MathObject::MathObject() m->defineDefaultProperty(QStringLiteral("tan"), QV4::MathObject::method_tan, 1); } -/* copies the sign from y to x and returns the result */ -static double copySign(double x, double y) +#ifdef Q_OS_ANDROID +// C++11's std::copysign is missing in the std namespace, so get it from the root namespace (math.h) +static Q_ALWAYS_INLINE double copySign(double x, double y) { - uchar *xch = (uchar *)&x; - uchar *ych = (uchar *)&y; - if (QSysInfo::ByteOrder == QSysInfo::BigEndian) - xch[0] = (xch[0] & 0x7f) | (ych[0] & 0x80); - else - xch[7] = (xch[7] & 0x7f) | (ych[7] & 0x80); - return x; + return ::copysign(x, y); +} +#else // Ok, we have a proper C++11 standard library +static Q_ALWAYS_INLINE double copySign(double x, double y) +{ + return std::copysign(x, y); } +#endif ReturnedValue MathObject::method_abs(CallContext *context) { -- cgit v1.2.3