Skip to content

Commit b9ca383

Browse files
committed
quantization: Extract union to a named type
This mostly helps clang-format that, in absence of a separate properly formatted declaration, tries to format the union as several lines.
1 parent e9ed24b commit b9ca383

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Diff for: src/quantization.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33

44
#include <assert.h>
55

6+
union FloatBits
7+
{
8+
float f;
9+
unsigned int ui;
10+
};
11+
612
unsigned short meshopt_quantizeHalf(float v)
713
{
8-
union { float f; unsigned int ui; } u = {v};
14+
FloatBits u = {v};
915
unsigned int ui = u.ui;
1016

1117
int s = (ui >> 16) & 0x8000;
@@ -30,7 +36,7 @@ float meshopt_quantizeFloat(float v, int N)
3036
{
3137
assert(N >= 0 && N <= 23);
3238

33-
union { float f; unsigned int ui; } u = {v};
39+
FloatBits u = {v};
3440
unsigned int ui = u.ui;
3541

3642
const int mask = (1 << (23 - N)) - 1;
@@ -64,7 +70,7 @@ float meshopt_dequantizeHalf(unsigned short h)
6470
// 112 is an exponent bias fixup; since we already applied it once, applying it twice converts 31 to 255
6571
r += (em >= (31 << 10)) ? (112 << 23) : 0;
6672

67-
union { float f; unsigned int ui; } u;
73+
FloatBits u;
6874
u.ui = s | r;
6975
return u.f;
7076
}

0 commit comments

Comments
 (0)