From: Simon Hausmann Date: Fri, 8 Feb 2013 08:23:58 +0000 (+0100) Subject: Fix cmath function usage X-Git-Tag: upstream/5.2.1~669^2~659^2~288 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=afe7ad259acbbd4c1aa6dcd8c87469788099c90f;p=platform%2Fupstream%2Fqtdeclarative.git Fix cmath function usage Some of the cmath functions in std don't work reliably on all platforms and on top of that with Visual Studio they are not in the std namespace at all (but for example prefixed as _isnan). Import MathExtras.h from WTF that includes all the necessary workarounds, including things like making pow() with MinGW compliant with what JavaScript needs. Change-Id: I3d8190ce33919db69b2889b439731a9cf5b2a46e Reviewed-by: Lars Knoll --- diff --git a/src/3rdparty/masm/wtf/MathExtras.h b/src/3rdparty/masm/wtf/MathExtras.h new file mode 100644 index 0000000..524d2ac --- /dev/null +++ b/src/3rdparty/masm/wtf/MathExtras.h @@ -0,0 +1,449 @@ +/* + * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WTF_MathExtras_h +#define WTF_MathExtras_h + +#include +#include +#include +#include +#include +#include +#include + +#if OS(SOLARIS) +#include +#endif + +#if OS(OPENBSD) +#include +#include +#endif + +#if OS(QNX) +// FIXME: Look into a way to have cmath import its functions into both the standard and global +// namespace. For now, we include math.h since the QNX cmath header only imports its functions +// into the standard namespace. +#include +#endif + +#ifndef M_PI +const double piDouble = 3.14159265358979323846; +const float piFloat = 3.14159265358979323846f; +#else +const double piDouble = M_PI; +const float piFloat = static_cast(M_PI); +#endif + +#ifndef M_PI_2 +const double piOverTwoDouble = 1.57079632679489661923; +const float piOverTwoFloat = 1.57079632679489661923f; +#else +const double piOverTwoDouble = M_PI_2; +const float piOverTwoFloat = static_cast(M_PI_2); +#endif + +#ifndef M_PI_4 +const double piOverFourDouble = 0.785398163397448309616; +const float piOverFourFloat = 0.785398163397448309616f; +#else +const double piOverFourDouble = M_PI_4; +const float piOverFourFloat = static_cast(M_PI_4); +#endif + +#if OS(DARWIN) + +// Work around a bug in the Mac OS X libc where ceil(-0.1) return +0. +inline double wtf_ceil(double x) { return copysign(ceil(x), x); } + +#define ceil(x) wtf_ceil(x) + +#endif + +#if OS(SOLARIS) + +#ifndef isfinite +inline bool isfinite(double x) { return finite(x) && !isnand(x); } +#endif +#ifndef isinf +inline bool isinf(double x) { return !finite(x) && !isnand(x); } +#endif +#ifndef signbit +inline bool signbit(double x) { return copysign(1.0, x) < 0; } +#endif + +#endif + +#if OS(OPENBSD) + +#ifndef isfinite +inline bool isfinite(double x) { return finite(x); } +#endif +#ifndef signbit +inline bool signbit(double x) { struct ieee_double *p = (struct ieee_double *)&x; return p->dbl_sign; } +#endif + +#endif + +#if COMPILER(MSVC) || (COMPILER(RVCT) && !(RVCT_VERSION_AT_LEAST(3, 0, 0, 0))) + +// We must not do 'num + 0.5' or 'num - 0.5' because they can cause precision loss. +static double round(double num) +{ + double integer = ceil(num); + if (num > 0) + return integer - num > 0.5 ? integer - 1.0 : integer; + return integer - num >= 0.5 ? integer - 1.0 : integer; +} +static float roundf(float num) +{ + float integer = ceilf(num); + if (num > 0) + return integer - num > 0.5f ? integer - 1.0f : integer; + return integer - num >= 0.5f ? integer - 1.0f : integer; +} +inline long long llround(double num) { return static_cast(round(num)); } +inline long long llroundf(float num) { return static_cast(roundf(num)); } +inline long lround(double num) { return static_cast(round(num)); } +inline long lroundf(float num) { return static_cast(roundf(num)); } +inline double trunc(double num) { return num > 0 ? floor(num) : ceil(num); } + +#endif + +#if COMPILER(GCC) && OS(QNX) +// The stdlib on QNX doesn't contain long abs(long). See PR #104666. +inline long long abs(long num) { return labs(num); } +#endif + +#if OS(ANDROID) || COMPILER(MSVC) +// ANDROID and MSVC's math.h does not currently supply log2 or log2f. +inline double log2(double num) +{ + // This constant is roughly M_LN2, which is not provided by default on Windows and Android. + return log(num) / 0.693147180559945309417232121458176568; +} + +inline float log2f(float num) +{ + // This constant is roughly M_LN2, which is not provided by default on Windows and Android. + return logf(num) / 0.693147180559945309417232121458176568f; +} +#endif + +#if COMPILER(MSVC) +// The 64bit version of abs() is already defined in stdlib.h which comes with VC10 +#if COMPILER(MSVC9_OR_LOWER) +inline long long abs(long long num) { return _abs64(num); } +#endif + +inline bool isinf(double num) { return !_finite(num) && !_isnan(num); } +inline bool isnan(double num) { return !!_isnan(num); } +inline bool signbit(double num) { return _copysign(1.0, num) < 0; } + +inline double nextafter(double x, double y) { return _nextafter(x, y); } +inline float nextafterf(float x, float y) { return x > y ? x - FLT_EPSILON : x + FLT_EPSILON; } + +inline double copysign(double x, double y) { return _copysign(x, y); } +inline int isfinite(double x) { return _finite(x); } + +// Work around a bug in Win, where atan2(+-infinity, +-infinity) yields NaN instead of specific values. +inline double wtf_atan2(double x, double y) +{ + double posInf = std::numeric_limits::infinity(); + double negInf = -std::numeric_limits::infinity(); + double nan = std::numeric_limits::quiet_NaN(); + + double result = nan; + + if (x == posInf && y == posInf) + result = piOverFourDouble; + else if (x == posInf && y == negInf) + result = 3 * piOverFourDouble; + else if (x == negInf && y == posInf) + result = -piOverFourDouble; + else if (x == negInf && y == negInf) + result = -3 * piOverFourDouble; + else + result = ::atan2(x, y); + + return result; +} + +// Work around a bug in the Microsoft CRT, where fmod(x, +-infinity) yields NaN instead of x. +inline double wtf_fmod(double x, double y) { return (!isinf(x) && isinf(y)) ? x : fmod(x, y); } + +// Work around a bug in the Microsoft CRT, where pow(NaN, 0) yields NaN instead of 1. +inline double wtf_pow(double x, double y) { return y == 0 ? 1 : pow(x, y); } + +#define atan2(x, y) wtf_atan2(x, y) +#define fmod(x, y) wtf_fmod(x, y) +#define pow(x, y) wtf_pow(x, y) + +// MSVC's math functions do not bring lrint. +inline long int lrint(double flt) +{ + int64_t intgr; +#if CPU(X86) + __asm { + fld flt + fistp intgr + }; +#else + ASSERT(isfinite(flt)); + double rounded = round(flt); + intgr = static_cast(rounded); + // If the fractional part is exactly 0.5, we need to check whether + // the rounded result is even. If it is not we need to add 1 to + // negative values and subtract one from positive values. + if ((fabs(intgr - flt) == 0.5) & intgr) + intgr -= ((intgr >> 62) | 1); // 1 with the sign of result, i.e. -1 or 1. +#endif + return static_cast(intgr); +} + +#endif // COMPILER(MSVC) + +inline double deg2rad(double d) { return d * piDouble / 180.0; } +inline double rad2deg(double r) { return r * 180.0 / piDouble; } +inline double deg2grad(double d) { return d * 400.0 / 360.0; } +inline double grad2deg(double g) { return g * 360.0 / 400.0; } +inline double turn2deg(double t) { return t * 360.0; } +inline double deg2turn(double d) { return d / 360.0; } +inline double rad2grad(double r) { return r * 200.0 / piDouble; } +inline double grad2rad(double g) { return g * piDouble / 200.0; } + +inline float deg2rad(float d) { return d * piFloat / 180.0f; } +inline float rad2deg(float r) { return r * 180.0f / piFloat; } +inline float deg2grad(float d) { return d * 400.0f / 360.0f; } +inline float grad2deg(float g) { return g * 360.0f / 400.0f; } +inline float turn2deg(float t) { return t * 360.0f; } +inline float deg2turn(float d) { return d / 360.0f; } +inline float rad2grad(float r) { return r * 200.0f / piFloat; } +inline float grad2rad(float g) { return g * piFloat / 200.0f; } + +// std::numeric_limits::min() returns the smallest positive value for floating point types +template inline T defaultMinimumForClamp() { return std::numeric_limits::min(); } +template<> inline float defaultMinimumForClamp() { return -std::numeric_limits::max(); } +template<> inline double defaultMinimumForClamp() { return -std::numeric_limits::max(); } +template inline T defaultMaximumForClamp() { return std::numeric_limits::max(); } + +template inline T clampTo(double value, T min = defaultMinimumForClamp(), T max = defaultMaximumForClamp()) +{ + if (value >= static_cast(max)) + return max; + if (value <= static_cast(min)) + return min; + return static_cast(value); +} +template<> inline long long int clampTo(double, long long int, long long int); // clampTo does not support long long ints. + +inline int clampToInteger(double value) +{ + return clampTo(value); +} + +inline float clampToFloat(double value) +{ + return clampTo(value); +} + +inline int clampToPositiveInteger(double value) +{ + return clampTo(value, 0); +} + +inline int clampToInteger(float value) +{ + return clampTo(value); +} + +inline int clampToInteger(unsigned x) +{ + const unsigned intMax = static_cast(std::numeric_limits::max()); + + if (x >= intMax) + return std::numeric_limits::max(); + return static_cast(x); +} + +inline bool isWithinIntRange(float x) +{ + return x > static_cast(std::numeric_limits::min()) && x < static_cast(std::numeric_limits::max()); +} + +template inline bool hasOneBitSet(T value) +{ + return !((value - 1) & value) && value; +} + +template inline bool hasZeroOrOneBitsSet(T value) +{ + return !((value - 1) & value); +} + +template inline bool hasTwoOrMoreBitsSet(T value) +{ + return !hasZeroOrOneBitsSet(value); +} + +template inline unsigned getLSBSet(T value) +{ + unsigned result = 0; + + while (value >>= 1) + ++result; + + return result; +} + +template inline T timesThreePlusOneDividedByTwo(T value) +{ + // Mathematically equivalent to: + // (value * 3 + 1) / 2; + // or: + // (unsigned)ceil(value * 1.5)); + // This form is not prone to internal overflow. + return value + (value >> 1) + (value & 1); +} + +#if !COMPILER(MSVC) && !COMPILER(RVCT) && !OS(SOLARIS) +using std::isfinite; +#if !COMPILER_QUIRK(GCC11_GLOBAL_ISINF_ISNAN) +using std::isinf; +using std::isnan; +#endif +using std::signbit; +#endif + +#if COMPILER_QUIRK(GCC11_GLOBAL_ISINF_ISNAN) +// A workaround to avoid conflicting declarations of isinf and isnan when compiling with GCC in C++11 mode. +namespace std { + inline bool wtf_isinf(float f) { return std::isinf(f); } + inline bool wtf_isinf(double d) { return std::isinf(d); } + inline bool wtf_isnan(float f) { return std::isnan(f); } + inline bool wtf_isnan(double d) { return std::isnan(d); } +}; + +using std::wtf_isinf; +using std::wtf_isnan; + +#define isinf(x) wtf_isinf(x) +#define isnan(x) wtf_isnan(x) +#endif + +#ifndef UINT64_C +#if COMPILER(MSVC) +#define UINT64_C(c) c ## ui64 +#else +#define UINT64_C(c) c ## ull +#endif +#endif + +#if COMPILER(MINGW64) && (!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1) +inline double wtf_pow(double x, double y) +{ + // MinGW-w64 has a custom implementation for pow. + // This handles certain special cases that are different. + if ((x == 0.0 || isinf(x)) && isfinite(y)) { + double f; + if (modf(y, &f) != 0.0) + return ((x == 0.0) ^ (y > 0.0)) ? std::numeric_limits::infinity() : 0.0; + } + + if (x == 2.0) { + int yInt = static_cast(y); + if (y == yInt) + return ldexp(1.0, yInt); + } + + return pow(x, y); +} +#define pow(x, y) wtf_pow(x, y) +#endif // COMPILER(MINGW64) && (!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1) + + +// decompose 'number' to its sign, exponent, and mantissa components. +// The result is interpreted as: +// (sign ? -1 : 1) * pow(2, exponent) * (mantissa / (1 << 52)) +inline void decomposeDouble(double number, bool& sign, int32_t& exponent, uint64_t& mantissa) +{ + ASSERT(isfinite(number)); + + sign = signbit(number); + + uint64_t bits = WTF::bitwise_cast(number); + exponent = (static_cast(bits >> 52) & 0x7ff) - 0x3ff; + mantissa = bits & 0xFFFFFFFFFFFFFull; + + // Check for zero/denormal values; if so, adjust the exponent, + // if not insert the implicit, omitted leading 1 bit. + if (exponent == -0x3ff) + exponent = mantissa ? -0x3fe : 0; + else + mantissa |= 0x10000000000000ull; +} + +// Calculate d % 2^{64}. +inline void doubleToInteger(double d, unsigned long long& value) +{ + if (isnan(d) || isinf(d)) + value = 0; + else { + // -2^{64} < fmodValue < 2^{64}. + double fmodValue = fmod(trunc(d), std::numeric_limits::max() + 1.0); + if (fmodValue >= 0) { + // 0 <= fmodValue < 2^{64}. + // 0 <= value < 2^{64}. This cast causes no loss. + value = static_cast(fmodValue); + } else { + // -2^{64} < fmodValue < 0. + // 0 < fmodValueInUnsignedLongLong < 2^{64}. This cast causes no loss. + unsigned long long fmodValueInUnsignedLongLong = static_cast(-fmodValue); + // -1 < (std::numeric_limits::max() - fmodValueInUnsignedLongLong) < 2^{64} - 1. + // 0 < value < 2^{64}. + value = std::numeric_limits::max() - fmodValueInUnsignedLongLong + 1; + } + } +} + +namespace WTF { + +// From http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 +inline uint32_t roundUpToPowerOfTwo(uint32_t v) +{ + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v++; + return v; +} + +} // namespace WTF + +#endif // #ifndef WTF_MathExtras_h diff --git a/src/v4/qmljs_runtime.cpp b/src/v4/qmljs_runtime.cpp index a785f00..639e699 100644 --- a/src/v4/qmljs_runtime.cpp +++ b/src/v4/qmljs_runtime.cpp @@ -64,7 +64,7 @@ namespace VM { QString numberToString(double num, int radix = 10) { - if (std::isnan(num)) { + if (isnan(num)) { return QStringLiteral("NaN"); } else if (qIsInf(num)) { return QLatin1String(num < 0 ? "-Infinity" : "Infinity"); diff --git a/src/v4/qmljs_runtime.h b/src/v4/qmljs_runtime.h index 7b0a44a..839133f 100644 --- a/src/v4/qmljs_runtime.h +++ b/src/v4/qmljs_runtime.h @@ -52,6 +52,8 @@ #include #include +#include + #ifdef DO_TRACE_INSTR # define TRACE1(x) fprintf(stderr, " %s\n", __FUNCTION__); # define TRACE2(x, y) fprintf(stderr, " %s\n", __FUNCTION__); @@ -306,7 +308,7 @@ inline Bool __qmljs_to_boolean(Value value, ExecutionContext *ctx) case Value::Object_Type: return true; default: // double - if (! value.doubleValue() || std::isnan(value.doubleValue())) + if (! value.doubleValue() || isnan(value.doubleValue())) return false; return true; } @@ -361,11 +363,11 @@ inline unsigned short __qmljs_to_uint16(Value value, ExecutionContext *ctx) if ((number >= 0 && number < D16)) return static_cast(number); - if (!std::isfinite(number)) + if (!isfinite(number)) return +0; double d = ::floor(::fabs(number)); - if (std::signbit(number)) + if (signbit(number)) d = -d; number = ::fmod(d , D16); diff --git a/src/v4/qmljs_value.cpp b/src/v4/qmljs_value.cpp index 8dba13a..83dd9c6 100644 --- a/src/v4/qmljs_value.cpp +++ b/src/v4/qmljs_value.cpp @@ -42,6 +42,8 @@ #include #include +#include + namespace QQmlJS { namespace VM { @@ -104,11 +106,11 @@ int Value::toInt32(double number) return static_cast(number); - if (!std::isfinite(number)) + if (!isfinite(number)) return 0; double d = ::floor(::fabs(number)); - if (std::signbit(number)) + if (signbit(number)) d = -d; number = ::fmod(d , D32); @@ -127,11 +129,11 @@ unsigned int Value::toUInt32(double number) if ((number >= 0 && number < D32)) return static_cast(number); - if (!std::isfinite(number)) + if (!isfinite(number)) return +0; double d = ::floor(::fabs(number)); - if (std::signbit(number)) + if (signbit(number)) d = -d; number = ::fmod(d , D32); @@ -144,12 +146,12 @@ unsigned int Value::toUInt32(double number) double Value::toInteger(double number) { - if (std::isnan(number)) + if (isnan(number)) return +0; - else if (! number || std::isinf(number)) + else if (! number || isinf(number)) return number; const double v = floor(fabs(number)); - return std::signbit(number) ? -v : v; + return signbit(number) ? -v : v; } Value Value::property(ExecutionContext *ctx, String *name) const diff --git a/src/v4/qv4dateobject.cpp b/src/v4/qv4dateobject.cpp index c808c78..bdfc4be 100644 --- a/src/v4/qv4dateobject.cpp +++ b/src/v4/qv4dateobject.cpp @@ -61,6 +61,8 @@ #include #include +#include + #ifndef Q_OS_WIN # include # ifndef Q_OS_VXWORKS @@ -572,7 +574,7 @@ static inline double ParseString(const QString &s) */ static inline QDateTime ToDateTime(double t, Qt::TimeSpec spec) { - if (std::isnan(t)) + if (isnan(t)) return QDateTime(); if (spec == Qt::LocalTime) t = LocalTime(t); @@ -588,7 +590,7 @@ static inline QDateTime ToDateTime(double t, Qt::TimeSpec spec) static inline QString ToString(double t) { - if (std::isnan(t)) + if (isnan(t)) return QStringLiteral("Invalid Date"); QString str = ToDateTime(t, Qt::LocalTime).toString() + QStringLiteral(" GMT"); double tzoffset = LocalTZA + DaylightSavingTA(t); @@ -608,7 +610,7 @@ static inline QString ToString(double t) static inline QString ToUTCString(double t) { - if (std::isnan(t)) + if (isnan(t)) return QStringLiteral("Invalid Date"); return ToDateTime(t, Qt::UTC).toString() + QStringLiteral(" GMT"); } @@ -858,7 +860,7 @@ Value DatePrototype::method_getTime(ExecutionContext *ctx) Value DatePrototype::method_getYear(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = YearFromTime(LocalTime(t)) - 1900; return Value::fromDouble(t); } @@ -866,7 +868,7 @@ Value DatePrototype::method_getYear(ExecutionContext *ctx) Value DatePrototype::method_getFullYear(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = YearFromTime(LocalTime(t)); return Value::fromDouble(t); } @@ -874,7 +876,7 @@ Value DatePrototype::method_getFullYear(ExecutionContext *ctx) Value DatePrototype::method_getUTCFullYear(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = YearFromTime(t); return Value::fromDouble(t); } @@ -882,7 +884,7 @@ Value DatePrototype::method_getUTCFullYear(ExecutionContext *ctx) Value DatePrototype::method_getMonth(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = MonthFromTime(LocalTime(t)); return Value::fromDouble(t); } @@ -890,7 +892,7 @@ Value DatePrototype::method_getMonth(ExecutionContext *ctx) Value DatePrototype::method_getUTCMonth(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = MonthFromTime(t); return Value::fromDouble(t); } @@ -898,7 +900,7 @@ Value DatePrototype::method_getUTCMonth(ExecutionContext *ctx) Value DatePrototype::method_getDate(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = DateFromTime(LocalTime(t)); return Value::fromDouble(t); } @@ -906,7 +908,7 @@ Value DatePrototype::method_getDate(ExecutionContext *ctx) Value DatePrototype::method_getUTCDate(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = DateFromTime(t); return Value::fromDouble(t); } @@ -914,7 +916,7 @@ Value DatePrototype::method_getUTCDate(ExecutionContext *ctx) Value DatePrototype::method_getDay(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = WeekDay(LocalTime(t)); return Value::fromDouble(t); } @@ -922,7 +924,7 @@ Value DatePrototype::method_getDay(ExecutionContext *ctx) Value DatePrototype::method_getUTCDay(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = WeekDay(t); return Value::fromDouble(t); } @@ -930,7 +932,7 @@ Value DatePrototype::method_getUTCDay(ExecutionContext *ctx) Value DatePrototype::method_getHours(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = HourFromTime(LocalTime(t)); return Value::fromDouble(t); } @@ -938,7 +940,7 @@ Value DatePrototype::method_getHours(ExecutionContext *ctx) Value DatePrototype::method_getUTCHours(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = HourFromTime(t); return Value::fromDouble(t); } @@ -946,7 +948,7 @@ Value DatePrototype::method_getUTCHours(ExecutionContext *ctx) Value DatePrototype::method_getMinutes(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = MinFromTime(LocalTime(t)); return Value::fromDouble(t); } @@ -954,7 +956,7 @@ Value DatePrototype::method_getMinutes(ExecutionContext *ctx) Value DatePrototype::method_getUTCMinutes(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = MinFromTime(t); return Value::fromDouble(t); } @@ -962,7 +964,7 @@ Value DatePrototype::method_getUTCMinutes(ExecutionContext *ctx) Value DatePrototype::method_getSeconds(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = SecFromTime(LocalTime(t)); return Value::fromDouble(t); } @@ -970,7 +972,7 @@ Value DatePrototype::method_getSeconds(ExecutionContext *ctx) Value DatePrototype::method_getUTCSeconds(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = SecFromTime(t); return Value::fromDouble(t); } @@ -978,7 +980,7 @@ Value DatePrototype::method_getUTCSeconds(ExecutionContext *ctx) Value DatePrototype::method_getMilliseconds(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = msFromTime(LocalTime(t)); return Value::fromDouble(t); } @@ -986,7 +988,7 @@ Value DatePrototype::method_getMilliseconds(ExecutionContext *ctx) Value DatePrototype::method_getUTCMilliseconds(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = msFromTime(t); return Value::fromDouble(t); } @@ -994,7 +996,7 @@ Value DatePrototype::method_getUTCMilliseconds(ExecutionContext *ctx) Value DatePrototype::method_getTimezoneOffset(ExecutionContext *ctx) { double t = getThisDate(ctx); - if (! std::isnan(t)) + if (! isnan(t)) t = (t - LocalTime(t)) / msPerMinute; return Value::fromDouble(t); } @@ -1184,13 +1186,13 @@ Value DatePrototype::method_setYear(ExecutionContext *ctx) ctx->throwTypeError(); double t = self->value.asDouble(); - if (std::isnan(t)) + if (isnan(t)) t = 0; else t = LocalTime(t); double year = ctx->argument(0).toNumber(ctx); double r; - if (std::isnan(year)) { + if (isnan(year)) { r = qSNaN(); } else { if ((Value::toInteger(year) >= 0) && (Value::toInteger(year) <= 99)) @@ -1225,7 +1227,7 @@ Value DatePrototype::method_setFullYear(ExecutionContext *ctx) ctx->throwTypeError(); double t = LocalTime(self->value.asDouble()); - if (std::isnan(t)) + if (isnan(t)) t = 0; double year = ctx->argument(0).toNumber(ctx); double month = (ctx->argumentCount < 2) ? MonthFromTime(t) : ctx->argument(1).toNumber(ctx); @@ -1265,7 +1267,7 @@ Value DatePrototype::method_toISOString(ExecutionContext *ctx) ctx->throwTypeError(); double t = self->value.asDouble(); - if (!std::isfinite(t)) + if (!isfinite(t)) ctx->throwRangeError(ctx->thisObject); QString result; @@ -1301,7 +1303,7 @@ Value DatePrototype::method_toJSON(ExecutionContext *ctx) Value O = __qmljs_to_object(ctx->thisObject, ctx); Value tv = __qmljs_to_primitive(O, ctx, NUMBER_HINT); - if (tv.isNumber() && !std::isfinite(tv.toNumber(ctx))) + if (tv.isNumber() && !isfinite(tv.toNumber(ctx))) return Value::nullValue(); FunctionObject *toIso = O.objectValue()->__get__(ctx, ctx->engine->newString(QStringLiteral("toISOString"))).asFunctionObject(); diff --git a/src/v4/qv4globalobject.cpp b/src/v4/qv4globalobject.cpp index 220704b..86d8c38 100644 --- a/src/v4/qv4globalobject.cpp +++ b/src/v4/qv4globalobject.cpp @@ -57,6 +57,8 @@ #include #include +#include + using namespace QQmlJS::VM; static inline char toHex(char c) @@ -611,7 +613,7 @@ Value GlobalFunctions::method_isNaN(ExecutionContext *context) return Value::fromBoolean(false); double d = v.toNumber(context); - return Value::fromBoolean(std::isnan(d)); + return Value::fromBoolean(isnan(d)); } /// isFinite [15.1.2.5] @@ -622,7 +624,7 @@ Value GlobalFunctions::method_isFinite(ExecutionContext *context) return Value::fromBoolean(true); double d = v.toNumber(context); - return Value::fromBoolean(std::isfinite(d)); + return Value::fromBoolean(isfinite(d)); } /// decodeURI [15.1.3.1] diff --git a/src/v4/qv4jsonobject.cpp b/src/v4/qv4jsonobject.cpp index 4bb6cd5..241c3c8 100644 --- a/src/v4/qv4jsonobject.cpp +++ b/src/v4/qv4jsonobject.cpp @@ -48,6 +48,7 @@ #include #include +#include namespace QQmlJS { namespace VM { @@ -737,7 +738,7 @@ QString Stringify::Str(const QString &key, Value value) if (value.isNumber()) { double d = value.toNumber(ctx); - return std::isfinite(d) ? value.toString(ctx)->toQString() : QStringLiteral("null"); + return isfinite(d) ? value.toString(ctx)->toQString() : QStringLiteral("null"); } if (Object *o = value.asObject()) { diff --git a/src/v4/qv4mathobject.cpp b/src/v4/qv4mathobject.cpp index 2f92e52..f0523ba 100644 --- a/src/v4/qv4mathobject.cpp +++ b/src/v4/qv4mathobject.cpp @@ -206,7 +206,7 @@ Value MathObject::method_max(ExecutionContext *parentCtx, Value thisObject, Valu double mx = -qInf(); for (unsigned i = 0; i < argc; ++i) { double x = argv[i].toNumber(parentCtx); - if (x > mx || std::isnan(x)) + if (x > mx || isnan(x)) mx = x; } return Value::fromDouble(mx); @@ -218,7 +218,7 @@ Value MathObject::method_min(ExecutionContext *parentCtx, Value thisObject, Valu for (unsigned i = 0; i < argc; ++i) { double x = argv[i].toNumber(parentCtx); if ((x == 0 && mx == x && copySign(1.0, x) == -1.0) - || (x < mx) || std::isnan(x)) { + || (x < mx) || isnan(x)) { mx = x; } } @@ -230,12 +230,12 @@ Value MathObject::method_pow(ExecutionContext *parentCtx, Value, Value *argv, in double x = argc > 0 ? argv[0].toNumber(parentCtx) : qSNaN(); double y = argc > 1 ? argv[1].toNumber(parentCtx) : qSNaN(); - if (std::isnan(y)) + if (isnan(y)) return Value::fromDouble(qSNaN()); if (y == 0) { return Value::fromDouble(1); - } else if (((x == 1) || (x == -1)) && std::isinf(y)) { + } else if (((x == 1) || (x == -1)) && isinf(y)) { return Value::fromDouble(qSNaN()); } else if (((x == 0) && copySign(1.0, x) == 1.0) && (y < 0)) { return Value::fromDouble(qInf()); diff --git a/src/v4/qv4numberobject.cpp b/src/v4/qv4numberobject.cpp index d732297..57cfab9 100644 --- a/src/v4/qv4numberobject.cpp +++ b/src/v4/qv4numberobject.cpp @@ -115,7 +115,7 @@ Value NumberPrototype::method_toString(ExecutionContext *ctx) return Value::undefinedValue(); } - if (std::isnan(num)) { + if (isnan(num)) { return Value::fromString(ctx, QStringLiteral("NaN")); } else if (qIsInf(num)) { return Value::fromString(ctx, QLatin1String(num < 0 ? "-Infinity" : "Infinity")); @@ -186,7 +186,7 @@ Value NumberPrototype::method_toFixed(ExecutionContext *ctx) if (ctx->argumentCount > 0) fdigits = ctx->argument(0).toInteger(ctx); - if (std::isnan(fdigits)) + if (isnan(fdigits)) fdigits = 0; if (fdigits < 0 || fdigits > 20) @@ -194,7 +194,7 @@ Value NumberPrototype::method_toFixed(ExecutionContext *ctx) double v = thisObject->value.asDouble(); QString str; - if (std::isnan(v)) + if (isnan(v)) str = QString::fromLatin1("NaN"); else if (qIsInf(v)) str = QString::fromLatin1(v < 0 ? "-Infinity" : "Infinity"); diff --git a/src/v4/qv4stringobject.cpp b/src/v4/qv4stringobject.cpp index a070cc0..dee5dae 100644 --- a/src/v4/qv4stringobject.cpp +++ b/src/v4/qv4stringobject.cpp @@ -274,7 +274,7 @@ Value StringPrototype::method_lastIndexOf(ExecutionContext *parentCtx, Value thi Value posArg = argc > 1 ? argv[1] : Value::undefinedValue(); double position = __qmljs_to_number(posArg, parentCtx); - if (std::isnan(position)) + if (isnan(position)) position = +qInf(); else position = trunc(position); @@ -645,10 +645,10 @@ Value StringPrototype::method_substring(ExecutionContext *parentCtx, Value thisO if (!endValue.isUndefined()) end = endValue.toInteger(parentCtx); - if (std::isnan(start) || start < 0) + if (isnan(start) || start < 0) start = 0; - if (std::isnan(end) || end < 0) + if (isnan(end) || end < 0) end = 0; if (start > length)