diff options
author | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-27 00:09:42 +0000 |
---|---|---|
committer | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-27 00:09:42 +0000 |
commit | ae2c20f398933a9e86c387dcc465ec0f71065ffc (patch) | |
tree | de668b1411e2ee0b4e49b6d8f8b68183134ac990 /skia/corecg/SkFloatBits.h | |
parent | 09911bf300f1a419907a9412154760efd0b7abc3 (diff) | |
download | chromium_src-ae2c20f398933a9e86c387dcc465ec0f71065ffc.zip chromium_src-ae2c20f398933a9e86c387dcc465ec0f71065ffc.tar.gz chromium_src-ae2c20f398933a9e86c387dcc465ec0f71065ffc.tar.bz2 |
Add skia to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/corecg/SkFloatBits.h')
-rw-r--r-- | skia/corecg/SkFloatBits.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/skia/corecg/SkFloatBits.h b/skia/corecg/SkFloatBits.h new file mode 100644 index 0000000..012770a --- /dev/null +++ b/skia/corecg/SkFloatBits.h @@ -0,0 +1,43 @@ +#ifndef SkFloatBits_DEFINED +#define SkFloatBits_DEFINED + +#include "SkTypes.h" + +/** Convert a sign-bit int (i.e. float interpreted as int) into a 2s compliement + int. This also converts -0 (0x80000000) to 0. Doing this to a float allows + it to be compared using normal C operators (<, <=, etc.) +*/ +static inline int32_t SkSignBitTo2sCompliment(int32_t x) { + if (x < 0) { + x &= 0x7FFFFFFF; + x = -x; + } + return x; +} + +#ifdef SK_CAN_USE_FLOAT + +union SkFloatIntUnion { + float fFloat; + int32_t fSignBitInt; +}; + +/** Return the float as a 2s compliment int. Just just be used to compare floats + to each other or against positive float-bit-constants (like 0) +*/ +static int32_t SkFloatAsInt(float x) { + SkFloatIntUnion data; + data.fFloat = x; + return SkSignBitTo2sCompliment(data.fSignBitInt); +} + +#endif + +#ifdef SK_SCALAR_IS_FLOAT + #define SkScalarAsInt(x) SkFloatAsInt(x) +#else + #define SkScalarAsInt(x) (x) +#endif + +#endif + |