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

  2. blackswift

    Rolf Magnus Guest

    Leave out the l prefix on printf.
    printf rounded the output to 6 digits, since you didn't specify anything
    else. This has nothing to do with the precision of double.
    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. Advertisements

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 (here). After that, you can post your question and our members will help you out.