views:

678

answers:

5

A single/double/extended precision floating point representation of Pi is accurate up to how many decimal places?

+1  A: 

6 places and 14 places.1 place is over 0 for the 3, and the last place although stored can't be considered as a precision point.

And sorry but I don't know what extended means without more context. Do you mean C#'s decimal?

Robert Gould
Please see"An Informal Description of IEEE754"http://www.cse.ttu.edu.tw/~jmchen/NM/refs/story754.pdf
+2  A: 

Print and count, baby, print and count. (Or read the specs.)

Bombe
+7  A: 
#include <stdio.h>

#define E_PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062

int main(int argc, char** argv)
{
        long double pild = E_PI;
        double pid = pild;
        float pif = pid;
        printf("%s\n%1.80f\n%1.80f\n%1.80Lf\n",
        "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899",
        pif, pid, pild);
        return 0;
}


[quassnoi #] gcc --version
gcc (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7)

[quassnoi #] ./test

3.14159265358979323846264338327950288419716939937510582097494459230781640628620899

3.14159274101257324218750000000000000000000000000000000000000000000000000000000000
        ^
3.14159265358979311599796346854418516159057617187500000000000000000000000000000000
                 ^
3.14159265358979311599796346854418516159057617187500000000000000000000000000000000
                 ^
  0000000001111111
  1234567890123456
Quassnoi
interesting test... unfortunately, I bet it's all sorts of system dependent :P
rmeador
Actually I say dependent on the math.h library.
Jim C
Sure, that's why I put gcc --version there
Quassnoi
I used math.h only for M_PI constant, I think it should be same in every version, it's a PI, after all :) Anyway, I updated the code not to use math.h
Quassnoi
No +1 because you’re working as root. :)
Bombe
@Bombe: corrected, you may vote your +1 now :)
Quassnoi
A: 

World of PI have PI to 100,000,000,000 digits, you could just print and compare. For a slightly easier to read version Joy of PI have 10,000 digits. And if you want to remember the digits youself you could try lerning the Cadaeic Cadenza poem.

Martin Brown
A: 

For C code, look at the definitions in <float.h>. That covers float (FLT_*), double (DBL_*) and long double (LDBL_*) definitions.

Jonathan Leffler