diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-06-13 13:03:08 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-06-13 13:03:08 +0000 |
commit | 9a323c98f6cd5d1dc002936588d182121231c69d (patch) | |
tree | 1da694a5819d823d9872c71e601613bebd2cefa8 /include/core/SkScalar.h | |
parent | e98ade4fdee03a234f68669bea84d07db4a8527e (diff) |
faster SkScalarIsFinite()
git-svn-id: http://skia.googlecode.com/svn/trunk@4244 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core/SkScalar.h')
-rw-r--r-- | include/core/SkScalar.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/include/core/SkScalar.h b/include/core/SkScalar.h index c87342c152..5be18cb859 100644 --- a/include/core/SkScalar.h +++ b/include/core/SkScalar.h @@ -53,12 +53,19 @@ /** SkScalarIsNaN(n) returns true if argument is not a number */ static inline bool SkScalarIsNaN(float x) { return x != x; } + /** Returns true if x is not NaN and not infinite */ static inline bool SkScalarIsFinite(float x) { - uint32_t bits = SkFloat2Bits(x); // need unsigned for our shifts - int exponent = bits << 1 >> 24; - return exponent != 0xFF; + // We rely on the following behavior of infinities and nans + // 0 * finite --> 0 + // 0 * infinity --> NaN + // 0 * NaN --> NaN + float prod = x * 0; + // At this point, prod will either be NaN or 0 + // Therefore we can return (prod == prod) or (0 == prod). + return prod == prod; } + #ifdef SK_DEBUG /** SkIntToScalar(n) returns its integer argument as an SkScalar * |