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 /include/private/SkFloatingPoint.h | |
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
Diffstat (limited to 'include/private/SkFloatingPoint.h')
-rw-r--r-- | include/private/SkFloatingPoint.h | 11 |
1 files changed, 4 insertions, 7 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. |