diff options
author | mtklein <mtklein@chromium.org> | 2016-08-10 08:31:42 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-10 08:31:42 -0700 |
commit | 3ff2cc81a58b3fe5287980cf618147c84a6c81f6 (patch) | |
tree | 6de878cca8d7a083f4897ac8f6a47a45b577a5e3 | |
parent | 6e90d42d3d5b8e51e60afbe97b27a0c16c2bacf1 (diff) |
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
-rw-r--r-- | include/private/SkFloatingPoint.h | 11 | ||||
-rw-r--r-- | src/core/SkLiteDL.cpp | 5 | ||||
-rw-r--r-- | src/core/SkMath.cpp | 4 |
3 files changed, 6 insertions, 14 deletions
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<const float*>(&gIEEENotANumber)) -#define SK_FloatInfinity (*SkTCast<const float*>(&gIEEEInfinity)) -#define SK_FloatNegativeInfinity (*SkTCast<const float*>(&gIEEENegativeInfinity)) +static const uint32_t kIEEENotANumber = 0x7fffffff; +#define SK_FloatNaN (*SkTCast<const float*>(&kIEEENotANumber)) +#define SK_FloatInfinity (+(float)INFINITY) +#define SK_FloatNegativeInfinity (-(float)INFINITY) static inline float sk_float_rsqrt_portable(float x) { // Get initial estimate. diff --git a/src/core/SkLiteDL.cpp b/src/core/SkLiteDL.cpp index 4557b375a8..c6a3a8e8ea 100644 --- a/src/core/SkLiteDL.cpp +++ b/src/core/SkLiteDL.cpp @@ -14,12 +14,11 @@ #include "SkRSXform.h" #include "SkSpinlock.h" #include "SkTextBlob.h" -#include <math.h> // A stand-in for an optional SkRect which was not set, e.g. bounds for a saveLayer(). -static const SkRect kUnset = {(SkScalar)INFINITY, 0,0,0}; +static const SkRect kUnset = { SK_ScalarInfinity, 0,0,0}; static const SkRect* maybe_unset(const SkRect& r) { - return r.left() == (SkScalar)INFINITY ? nullptr : &r; + return r.left() == SK_ScalarInfinity ? nullptr : &r; } // copy_v(dst, src,n, src,n, ...) copies an arbitrary number of typed srcs into dst. diff --git a/src/core/SkMath.cpp b/src/core/SkMath.cpp index 1f671d3949..6eff790c85 100644 --- a/src/core/SkMath.cpp +++ b/src/core/SkMath.cpp @@ -11,10 +11,6 @@ #include "SkFloatingPoint.h" #include "SkScalar.h" -const uint32_t gIEEENotANumber = 0x7FFFFFFF; -const uint32_t gIEEEInfinity = 0x7F800000; -const uint32_t gIEEENegativeInfinity = 0xFF800000; - #define sub_shift(zeros, x, n) \ zeros -= n; \ x >>= n |