Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   what 's the precision of 'double'? (http://www.velocityreviews.com/forums/t450238-what-s-the-precision-of-double.html)

blackswift 12-03-2005 10:58 AM

what 's the precision of 'double'?
 
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 12-03-2005 11:13 AM

Re: what 's the precision of 'double'?
 
blackswift wrote:

> 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.



All times are GMT. The time now is 07:12 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.