what 's the precision of 'double'?

B

blackswift

hello,

program:
double x;
scanf("%lf", &x);
printf("%lf\n", x);

input:
3.14159265358979

output:
3.141593 (GCC 4.0.1 & visual c++ 6.0)

it seems that double has the same precision as float.

can some one tell me why ?

thanks in advance!!
 
R

Rolf Magnus

blackswift said:
hello,

program:
double x;
scanf("%lf", &x);
printf("%lf\n", x);

Leave out the l prefix on printf.
input:
3.14159265358979

output:
3.141593 (GCC 4.0.1 & visual c++ 6.0)

printf rounded the output to 6 digits, since you didn't specify anything
else. This has nothing to do with the precision of double.
it seems that double has the same precision as float.

They might or might not have the same precision. The C++ standard only
defines minimum requirements for those types.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top