From 3ff2cc81a58b3fe5287980cf618147c84a6c81f6 Mon Sep 17 00:00:00 2001 From: mtklein Date: Wed, 10 Aug 2016 08:31:42 -0700 Subject: constexpr NaN,+Inf,-Inf Reading extern values meant these couldn't be compile-time constants. math.h has INFINITY, which is macro that is supposed to expand to float +inf. On MSVC it seems it's natively a double, so we cast just to make sure. There's nan(const char*) in math.h for NaN too, but I don't trust that to be compile-time evaluated. So instead, we keep reinterpreting a bit pattern. I did try to write static constexpr float float_nan() { ... } and completely failed. constexpr seems a bit too restrictive in C++11 to make it work, but Clang kept telling me, you'll be able to do this with C++14. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2233853002 Review-Url: https://codereview.chromium.org/2233853002 --- include/private/SkFloatingPoint.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/private/SkFloatingPoint.h b/include/private/SkFloatingPoint.h index a7aa50cf9f..8d8843eb58 100644 --- a/include/private/SkFloatingPoint.h +++ b/include/private/SkFloatingPoint.h @@ -100,13 +100,10 @@ static inline float sk_float_pow(float base, float exp) { #define sk_double_round2int(x) (int)floor((x) + 0.5f) #define sk_double_ceil2int(x) (int)ceil(x) -extern const uint32_t gIEEENotANumber; -extern const uint32_t gIEEEInfinity; -extern const uint32_t gIEEENegativeInfinity; - -#define SK_FloatNaN (*SkTCast(&gIEEENotANumber)) -#define SK_FloatInfinity (*SkTCast(&gIEEEInfinity)) -#define SK_FloatNegativeInfinity (*SkTCast(&gIEEENegativeInfinity)) +static const uint32_t kIEEENotANumber = 0x7fffffff; +#define SK_FloatNaN (*SkTCast(&kIEEENotANumber)) +#define SK_FloatInfinity (+(float)INFINITY) +#define SK_FloatNegativeInfinity (-(float)INFINITY) static inline float sk_float_rsqrt_portable(float x) { // Get initial estimate. -- cgit v1.2.3