Last active
September 15, 2016 10:58
-
-
Save alemures/d429210a90ab37949c52b0a14dd4a8f0 to your computer and use it in GitHub Desktop.
Convert a double to long in ANSI C (Java's doubleToRawLongBits)
This file contains hidden or 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
// Make sure that unsigned long is 8 bytes of length | |
unsigned long utilDoubleToLong(double value) { | |
unsigned long longValue; | |
memcpy(&longValue, &value, sizeof(unsigned long)); | |
return longValue; | |
} | |
double utilLongToDouble(unsigned long value) { | |
double doubleValue; | |
memcpy(&doubleValue, &value, sizeof(unsigned long)); | |
return doubleValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment