Skip to content

Instantly share code, notes, and snippets.

@eddieantonio
Created August 8, 2014 03:20
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 eddieantonio/63d3cb37a6aad95ab3db to your computer and use it in GitHub Desktop.
Save eddieantonio/63d3cb37a6aad95ab3db to your computer and use it in GitHub Desktop.
Double the shenanigans
#include <stdio.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288
#endif
#define SIGNIFICAND_SIZE 52
#define EXPONENT_MASK 0x7FF
#define SIGNIFICAND_MASK 0x000FFFFFFFFFFFFFL
typedef union {
unsigned long i;
double f;
} louble;
int main() {
louble x = { .f = M_PI };
unsigned long exp = (x.i >> SIGNIFICAND_SIZE) & EXPONENT_MASK,
sig = x.i & SIGNIFICAND_MASK;
printf("π = 0x%016lx = %lg\n", x.i, x.f);
printf(" Exp: 0x%3lx\tSig: 0x%lx\n", exp, sig);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment