what 's the precision of 'double'?

Discussion in 'C++' started by blackswift, Dec 3, 2005.

  1. blackswift

    blackswift Guest

    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!!
     
    blackswift, Dec 3, 2005
    #1
    1. Advertising

  2. blackswift

    Rolf Magnus Guest

    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.
     
    Rolf Magnus, Dec 3, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Geisenhoff

    Bug in double precision computing?

    Daniel Geisenhoff, Jul 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    345
    Shan Plourde
    Jul 29, 2004
  2. Wolfgang
    Replies:
    4
    Views:
    5,198
    Andrew Hobbs
    Feb 24, 2004
  3. Replies:
    5
    Views:
    204,777
  4. Andersen

    double precision vs. integers

    Andersen, Dec 18, 2005, in forum: Java
    Replies:
    11
    Views:
    1,000
    Andersen
    Dec 20, 2005
  5. Sydex
    Replies:
    12
    Views:
    6,598
    Victor Bazarov
    Feb 17, 2005
Loading...

Share This Page