Last active
December 17, 2015 18:09
-
-
Save yoya/5651633 to your computer and use it in GitHub Desktop.
double => long cast
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> | |
int main(void) { | |
double d = 1234567890; | |
double *dp = &d; | |
long l = (double) d; | |
long *lp = (long *) dp; | |
union dl_t { | |
double d; | |
long l; | |
} dl; | |
dl.d = d; | |
printf("d:%f dp:%f\n", d, *dp); | |
printf("l:%ld lp:%ld dl.l=%ld\n", l, *lp, dl.l); | |
return 0; | |
} | |
/* outout | |
d:1234567890.000000 dp:1234567890.000000 | |
l:1234567890 lp:4742964961033060352 dl.l=4742964961033060352 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment