Skip to content

Instantly share code, notes, and snippets.

@pwl
Created March 2, 2012 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwl/1957567 to your computer and use it in GitHub Desktop.
Save pwl/1957567 to your computer and use it in GitHub Desktop.
memory alignment of binary128
#include <stdio.h>
#include <stdint.h>
#include <endian.h>
typedef union
{
__float128 val;
struct
{
#if __BYTE_ORDER == __BIG_ENDIAN
uint64_t sign : 1;
uint64_t exp : 15;
uint64_t frac1 : 48;
uint64_t frac0 : 64;
#else
uint64_t frac0 : 64;
uint64_t frac1 : 48;
uint64_t exp : 15;
uint64_t sign : 1;
#endif
} bits;
} qfloat;
int main()
{
qfloat foo;
qfloat bar;
foo.val = 65536.0;
foo.val += 1.0;
foo.val *= foo.val;
bar.val = 8191.0;
printf("%04X %012llX %016llX\n", (uint16_t)foo.bits.exp, (uint64_t)foo.bits.frac1, foo.bits.frac0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment