Jim Michaels
2011-02-22 02:17:48 UTC
#include <tr1/stdint.h>
#include <stdio.h>
int main(void) {
int64_t n1=1300000000000LL;
int64_t n2=1999888999256LL;
double
dnum=n1,
dden=n2,
dpercent=n1;
long double
ldnum=n1,
ldden=n2,
ldpercent=n1;
dpercent/=dden;
dpercent*=100;
ldpercent/=ldden;
ldpercent*=100;
printf("n1=%I64d, n2=%I64d\n", n1, n2);
printf("dnum=%g, dden=%g, dpercent=%4.2f", dnum, dden, dpercent);
//printf("ldnum=%Lg, ldden=%Lg, ldpercent=%4.2Lf\n", ldnum, ldden,
ldpercent);//this gives error on the L
printf("ldnum=%lg, ldden=%lg, ldpercent=%4.2lf\n", ldnum, ldden, ldpercent);
//%Lf is a microsoft format and is preferred over %lf for stability.
//should display percentages with 3 places to left, and 2 places to right of
decimal point.
return 0;
}
/*
mingw-test-printf-lf.cpp: In function 'int main()':
mingw-test-printf-lf.cpp:25:79: warning: format '%lg' expects type 'double', but
argument 2 has type 'long double'
mingw-test-printf-lf.cpp:25:79: warning: format '%lg' expects type 'double', but
argument 3 has type 'long double'
mingw-test-printf-lf.cpp:25:79: warning: format '%4.2lf' expects type 'double',
but argument 4 has type 'long double'
so... how to you display a long double in printf????
*/
-------------
Jim Michaels
***@yahoo.com
***@JimsComputerRepairandWebDesign.com
http://JimsComputerRepairandWebDesign.com
http://JesusnJim.com (my personal site, has software)
http://DoLifeComputers.JesusnJim.com (group which I lead)
---
Computer memory/disk size measurements:
[KB KiB] [MB MiB] [GB GiB] [TB TiB]
[10^3B=1,000B=1KB][2^10B=1,024B=1KiB]
[10^6B=1,000,000B=1MB][2^20B=1,048,576B=1MiB]
[10^9B=1,000,000,000B=1GB][2^30B=1,073,741,824B=1GiB]
[10^12B=1,000,000,000,000B=1TB][2^40B=1,099,511,627,776B=1TiB]
Note: disk size is measured in MB, GB, or TB, not in MiB, GiB, or TiB. computer
memory (RAM) is measured in MiB and GiB.
#include <stdio.h>
int main(void) {
int64_t n1=1300000000000LL;
int64_t n2=1999888999256LL;
double
dnum=n1,
dden=n2,
dpercent=n1;
long double
ldnum=n1,
ldden=n2,
ldpercent=n1;
dpercent/=dden;
dpercent*=100;
ldpercent/=ldden;
ldpercent*=100;
printf("n1=%I64d, n2=%I64d\n", n1, n2);
printf("dnum=%g, dden=%g, dpercent=%4.2f", dnum, dden, dpercent);
//printf("ldnum=%Lg, ldden=%Lg, ldpercent=%4.2Lf\n", ldnum, ldden,
ldpercent);//this gives error on the L
printf("ldnum=%lg, ldden=%lg, ldpercent=%4.2lf\n", ldnum, ldden, ldpercent);
//%Lf is a microsoft format and is preferred over %lf for stability.
//should display percentages with 3 places to left, and 2 places to right of
decimal point.
return 0;
}
/*
mingw-test-printf-lf.cpp: In function 'int main()':
mingw-test-printf-lf.cpp:25:79: warning: format '%lg' expects type 'double', but
argument 2 has type 'long double'
mingw-test-printf-lf.cpp:25:79: warning: format '%lg' expects type 'double', but
argument 3 has type 'long double'
mingw-test-printf-lf.cpp:25:79: warning: format '%4.2lf' expects type 'double',
but argument 4 has type 'long double'
so... how to you display a long double in printf????
*/
-------------
Jim Michaels
***@yahoo.com
***@JimsComputerRepairandWebDesign.com
http://JimsComputerRepairandWebDesign.com
http://JesusnJim.com (my personal site, has software)
http://DoLifeComputers.JesusnJim.com (group which I lead)
---
Computer memory/disk size measurements:
[KB KiB] [MB MiB] [GB GiB] [TB TiB]
[10^3B=1,000B=1KB][2^10B=1,024B=1KiB]
[10^6B=1,000,000B=1MB][2^20B=1,048,576B=1MiB]
[10^9B=1,000,000,000B=1GB][2^30B=1,073,741,824B=1GiB]
[10^12B=1,000,000,000,000B=1TB][2^40B=1,099,511,627,776B=1TiB]
Note: disk size is measured in MB, GB, or TB, not in MiB, GiB, or TiB. computer
memory (RAM) is measured in MiB and GiB.