Skip to content

Instantly share code, notes, and snippets.

@x4m
Created September 10, 2016 17:40
Show Gist options
  • Save x4m/a5066149af47ddbe60b4c905318054c9 to your computer and use it in GitHub Desktop.
Save x4m/a5066149af47ddbe60b4c905318054c9 to your computer and use it in GitHub Desktop.
float pack_float_bits(const float v, const int r)
{
union {
float f;
struct { unsigned value:31, sign:1; } vbits;
struct { unsigned value:29, realm:2, sign:1; } rbits;
} a;
a.f = v;
a.rbits.value = a.vbits.value >> 2;
a.rbits.realm = r;
return a.f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment