blob: 012770a5b61795f11be01aea574794201eb51ab6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
|