-
-
Save eddieantonio/63d3cb37a6aad95ab3db to your computer and use it in GitHub Desktop.
Double the shenanigans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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