Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I'm not a c compiler expert, but have a look at double precision pi It may be the difference between computational precision and "%Lf" display precision. I started looking into it, when I questioned the way GLib defined pi as a constant. They defined it out to 50 decimal places, but any use of it in it's long double is limited to 15 decimal places.

One of the c gurus in that thread said that c's precision is only gauranteed to 10 decimal places, but with IEEE standards, it's common to see 15. I see 15.

Eventually, I found mpfr which lets you set how many digits of precision you want to use.

If you can show me a simple c program that computes and displays values out to 50 decimal places, with normal c, I would be greatful. Everything I see truncates it (pi) to 3.(15 decimal places).

For example, in this code, the value of pi is correctly printed as a string on the first line of output, but the subsequent lines all have garbage after the 15th decimal place.

#include <gtk/gtk.h> /* gcc -o test test.c `pkg-config --cflags --libs gtk+-2.0` */ int main (){ /* how the headers define G_PI */ /* #define G_PI 3.1415926535897932384626433832795028841971693993751 + */ long double PI = G_PI; g_print("3.1415926535897932384626433832795028841971693993751\n"); g_print("%0.50e\n",G_PI); g_print("%0.50Lf\n",G_PI); g_print("%0.50Lf\n",PI); g_print("%0.50Lg\n",PI); g_print("%0.50Le\n",PI); return 0; }
Output:
^^^^^^^^^^^ -> unstable after 15 dec +imal 3.1415926535897932384626433832795028841971693993751 3.14159265358979311599796346854418516159057617187500e+00 -0.00000000000000000000000000000000000000000000000000 3.14159265358979311599796346854418516159057617187500 3.141592653589793115997963468544185161590576171875 3.14159265358979311599796346854418516159057617187500e+00 ^^^^^^^^^^^^ -> unstable after 15 dec +imal

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re^3: RFC: Getting Started with PDL (the Perl Data Language) by zentara
in thread RFC: Getting Started with PDL (the Perl Data Language) by lin0

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (15)
    As of 2014-09-17 14:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (82 votes), past polls