Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / include / core / SkFloatingPoint.h
index 7dfa9d8..2df8f9b 100644 (file)
 
 #include <math.h>
 #include <float.h>
+
+// For _POSIX_VERSION
+#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
+#include <unistd.h>
+#endif
+
 #include "SkFloatBits.h"
 
 // C++98 cmath std::pow seems to be the earliest portable way to get float pow.
@@ -24,9 +30,26 @@ static inline float sk_float_pow(float base, float exp) {
 }
 
 static inline float sk_float_copysign(float x, float y) {
+// c++11 contains a 'float copysign(float, float)' function in <cmath>.
+// clang-cl reports __cplusplus for clang, not the __cplusplus vc++ version _MSC_VER would report.
+#define SK_BUILD_WITH_CLANG_CL (defined(_MSC_VER) && defined(__clang__))
+#if (!SK_BUILD_WITH_CLANG_CL && __cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
+    return copysign(x, y);
+
+// Posix has demanded 'float copysignf(float, float)' (from C99) since Issue 6.
+#elif defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
+    return copysignf(x, y);
+
+// Visual studio prior to 13 only has 'double _copysign(double, double)'.
+#elif defined(_MSC_VER)
+    return (float)_copysign(x, y);
+
+// Otherwise convert to bits and extract sign.
+#else
     int32_t xbits = SkFloat2Bits(x);
     int32_t ybits = SkFloat2Bits(y);
     return SkBits2Float((xbits & 0x7FFFFFFF) | (ybits & 0x80000000));
+#endif
 }
 
 #ifdef SK_BUILD_FOR_WINCE
@@ -99,7 +122,7 @@ extern const uint32_t gIEEENegativeInfinity;
 
 #if defined(__SSE__)
 #include <xmmintrin.h>
-#elif defined(__ARM_NEON__)
+#elif defined(SK_ARM_HAS_NEON)
 #include <arm_neon.h>
 #endif
 
@@ -115,7 +138,7 @@ static inline float sk_float_rsqrt(const float x) {
     float result;
     _mm_store_ss(&result, _mm_rsqrt_ss(_mm_set_ss(x)));
     return result;
-#elif defined(__ARM_NEON__)
+#elif defined(SK_ARM_HAS_NEON)
     // Get initial estimate.
     const float32x2_t xx = vdup_n_f32(x);  // Clever readers will note we're doing everything 2x.
     float32x2_t estimate = vrsqrte_f32(xx);