Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f32 pack_color_cast(u8 r, u8 g, u8 b, u8 a = 255)
- {
- u32 raw = (a << 24) | (b << 16) | (g << 8) | r;
- return *cast(f32*)&raw;
- }
- f32 pack_color_union(u8 r, u8 g, u8 b, u8 a = 255)
- {
- union RawValue { f32 value; u32 raw; }
- RawValue rv = void;
- rv.raw = (a << 24) | (b << 16) | (g << 8) | r;
- return rv.value;
- }
- enum RED = pack_color_cast(1.0, 0.0, 0.0, 1.0); // OK
- enum BLUE = pack_color_union(1.0, 0.0, 0.0, 1.0); // Error: reinterpretation through overlapped field value is not allowed in CTFE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement