From 2b77c30e246a7452a68999b47b9eaf10f6cafd2f Mon Sep 17 00:00:00 2001 From: Jonathan Liu Date: Wed, 9 Jan 2013 19:28:56 +1100 Subject: Fix Math.pow implementation with MinGW-w64 Adapted from WebKit changes 137895, 138705, 138894 and 138903. Change-Id: I166f8837e898d17d71ce4e4cab8ab45ea49de39c Reviewed-by: Simon Hausmann --- .../javascriptcore/JavaScriptCore/wtf/MathExtras.h | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/wtf/MathExtras.h b/src/3rdparty/javascriptcore/JavaScriptCore/wtf/MathExtras.h index a18949e..fc5676a 100644 --- a/src/3rdparty/javascriptcore/JavaScriptCore/wtf/MathExtras.h +++ b/src/3rdparty/javascriptcore/JavaScriptCore/wtf/MathExtras.h @@ -27,6 +27,7 @@ #define WTF_MathExtras_h #include +#include #include #include @@ -39,13 +40,6 @@ #include #endif -#if COMPILER(MSVC) -#if OS(WINCE) -#include -#endif -#include -#endif - #ifndef M_PI const double piDouble = 3.14159265358979323846; const float piFloat = 3.14159265358979323846f; @@ -186,4 +180,26 @@ 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; } +#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) + #endif // #ifndef WTF_MathExtras_h -- cgit v1.2.1