File tree 1 file changed +9
-3
lines changed
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 3
3
4
4
#include < assert.h>
5
5
6
+ union FloatBits
7
+ {
8
+ float f;
9
+ unsigned int ui;
10
+ };
11
+
6
12
unsigned short meshopt_quantizeHalf (float v)
7
13
{
8
- union { float f; unsigned int ui; } u = {v};
14
+ FloatBits u = {v};
9
15
unsigned int ui = u.ui ;
10
16
11
17
int s = (ui >> 16 ) & 0x8000 ;
@@ -30,7 +36,7 @@ float meshopt_quantizeFloat(float v, int N)
30
36
{
31
37
assert (N >= 0 && N <= 23 );
32
38
33
- union { float f; unsigned int ui; } u = {v};
39
+ FloatBits u = {v};
34
40
unsigned int ui = u.ui ;
35
41
36
42
const int mask = (1 << (23 - N)) - 1 ;
@@ -64,7 +70,7 @@ float meshopt_dequantizeHalf(unsigned short h)
64
70
// 112 is an exponent bias fixup; since we already applied it once, applying it twice converts 31 to 255
65
71
r += (em >= (31 << 10 )) ? (112 << 23 ) : 0 ;
66
72
67
- union { float f; unsigned int ui; } u;
73
+ FloatBits u;
68
74
u.ui = s | r;
69
75
return u.f ;
70
76
}
You can’t perform that action at this time.
0 commit comments