Created
February 17, 2015 14:00
-
-
Save sr105/08d52821745787e28347 to your computer and use it in GitHub Desktop.
examples of C++ floating point types
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
#include <stdio.h> | |
int main() { | |
float f = 99998.1F; | |
double d = 99998.1; | |
long double ld = 99998.1L; | |
printf("sizeof(f) = %lu\n", sizeof(f)); | |
printf("sizeof(d) = %lu\n", sizeof(d)); | |
printf("sizeof(ld) = %lu\n", sizeof(ld)); | |
int precision = 25; | |
printf("precision = %d\n", precision); | |
printf("\tf = %.*f\n", precision, f); | |
printf("\td = %.*f\n", precision, d); | |
printf("\tld = %.*Lf\n", precision, ld); | |
precision = 12; | |
printf("precision = %d\n", precision); | |
printf("\tf = %.*f\n", precision, f); | |
printf("\td = %.*f\n", precision, d); | |
printf("\tld = %.*Lf\n", precision, ld); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment