That makes no sense to me at all

It was a poorly expressed explanation.
The most significant double is 0x1.921fb54442d18p+1. (We agree on this, at least.)
That string expresses an exact value, but 3.1415926535897931 is only a very poor approximation of that exact value.
The least significant double is, according to me, 0x1.1a62633145c07p-53.
That string expresses an exact value, but 1.2246467991473532e-16 is only a very poor approximation of that exact value.
So ... my doubledouble contains a value that is exactly the sum of both:
0x1.921fb54442d18p+1 + 0x1.1a62633145c07p-53
But you can't expect the sum of the 2 rough decimal approximations to be equivalent to the exact hex sum of the 2 hex numbers. (And it's not, of course.)

The least significant double that your approach came up with was 0x1.3f45eb146ba31p-53.
Your decimal approximation of that exact value is 0.0000000000000001384626433832795.
When you add your 2 decimal approximations together you end up with the input value - but that's false comfort.
The actual value contained by your doubledouble is, according to the way I look at them, is not really the sum of the 2 decimal approximations - it's the sum of the 2 hex values:
0x1.921fb54442d18p+1 + 0x1.3f45eb146ba31p-53.
That corresponds to a base 10 value of 3.141592653589793254460606851823683 (which differs significantly from the input).
Your doubledouble, expressed in base 2 is:
11.001001000011111101101010100010001000010110100011000010011111101000101111010110001010001101011101000110001
which is not the correct 107 bit representation of the input value.
If you use that doubledouble as your pi approximation, then you'll only get incorrect results.

FWIW, if I want to calculate the double-double representation of a specific value, I do essentially the same as you, except that I use Math::MPFR instead of Math::BigFloat.
And I set precision to 2098 bits. I have:
# sub dd_str takes a string as its arg and returns # the 2 doubles that form the doubledouble. # Works correctly if default Math::MPFR precision is # 2098 bits - else might return incorrect values. sub dd_str { # Set $val to the 2098 bit representation of $_[0] my $val = Math::MPFR->new($_[0]); # Most significant double is $val converted to a # double, rounding to nearest with ties to even my $msd = Rmpfr_get_d($val, MPFR_RNDN); $val -= $msd; # Least siginificant double is $val converted # to a double. return ($msd, Rmpfr_get_d($val, MPFR_RNDN)); }
2098 bits is overkill for the vast majority of conversions. It stems from the fact that the doubledouble can accurately represent certain values up to (but not exceeding) 2098 bits.
For example, on my PPC box I can assign  $x = (2 **1023) + (2 ** -1074); and the doubledouble $x will consist of the 2 doubles 2**1023 and 2**-1074, thereby accurately representing that 2098 bit value.
The value of this capability is limited - multiply $x by (say) 1.01 and all of that additional precision is lost. The result is the same as multiplying 2**1023 by 1.01.

Anyway ... first question is "how to set your doubledouble pi correctly using Math::BigFloat ?".

I couldn't quickly come up with an answer, but I'll give it some more thought later on today.

Cheers,
Rob

In reply to Re^10: Math::BigFloat to native double? by syphilis
in thread Math::BigFloat to native double? by BrowserUk

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.