I may be wrong but Perl double are based on C double which are defined like this according to ANSI/ISO IEEE 754-1985 standard :

double -> 64 bits
A double element has a sign bit, an 11-bit exponent and a 52-bit fraction.
The precise form to be used is quite tightly specified by the standard IEEE 754 which is implemented in hardware on most modern machines.
Features of the notation:
The first bit represents the sign of the number.

The next 8 bits (float or single precision) or 11 bits (double, double precision)
represent the exponent in excess-127 or excess-1023 notation.
To overcome difficulties related to signed exponents, the exponent is stored as a binary integer with a bias of 127(float) or 1023(double) added to it.
When the number is normalised, the first digit, immediately before the binary point, will always be 1.
This digit is made implicit and the remaining fraction part of the mantissa is stored in the next 23 bits (float) or 53 bits (double).
The value of the number is
(-1)**Sign * ( 1 + Mantissa ) 2**(Exponent - Bias)
where
Sign is the sign bit (0 or 1)
Mantissa is the mantissa part with the point assumed at the start.
Exponent is the exponent part treated as a normal binary integer.
Bias is 127 for float, 1023 for double

(see my Source for more details)

The main problem is that
the number of significant digit displayed can't be 'guessed' one for all ('a priori'):


for example
13176825*2**(-22) will be displayed with 5 digits 3.1416
Whereas 11*2**(-20) will be displayed with 9 digits

Hope this helps...

Now for the Fun Pi/Perl part you could also check
Arithmetic-Geometric Mean calculation of pi.
or my modest <shameless plug> Simple Pi calculator </shameless plug>

"Only Bad Coders Code Badly In Perl" (OBC2BIP)

In reply to Re: tasty pi by arhuman
in thread tasty pi by jynx

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.