Connecting Tech Pros Worldwide Forums | Help | Site Map

what 's the precision of 'double'?

blackswift
Guest
 
Posts: n/a
#1: Dec 3 '05
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!!


Rolf Magnus
Guest
 
Posts: n/a
#2: Dec 3 '05

re: what 's the precision of 'double'?


blackswift wrote:
[color=blue]
> hello,
>
> program:
> double x;
> scanf("%lf", &x);
> printf("%lf\n", x);[/color]

Leave out the l prefix on printf.
[color=blue]
> input:
> 3.14159265358979
>
> output:
> 3.141593 (GCC 4.0.1 & visual c++ 6.0)[/color]

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

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

Closed Thread