Created
March 11, 2013 07:33
-
-
Save mpurbo/5132544 to your computer and use it in GitHub Desktop.
Integer bits of double/float
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 <stdint.h> | |
uint64_t doubleToBits(double x) { | |
const union { double f; uint64_t i; } xUnion = { .f = x }; | |
return xUnion.i; | |
} | |
uint32_t floatToBits(float x) { | |
const union { float f; uint32_t i; } xUnion = { .f = x }; | |
return xUnion.i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment