I'll follow up as soon as I've double-checked

Ok ... I thought my perl script was printing out the decimal values to full precision, but it wasn't.

Corrected decimal representations are:
0x1.921fb54442d18p+1 => 3.1415926535897931 0x1.1a62633145c07p-53 => 1.2246467991473532e-16
They still don't add up to something near the original input value - but nor should they.
Whilst it's quite valid to simply add (concatenate) base 2 or base 16 values, if we want to add in base 10, we need to first convert those hex values to *106* bit precision decimal values.
Expressed as decimals to 106 bits of precision, I get:
0x1.921fb54442d18p+1 => 3.14159265358979311599796346854419 0x1.1a62633145c07p-53 => 1.2246467991473532071737640294584e-16
The sum of which is:
3.14159265358979323846264338327953
(This is the same as the input value, except for the extra "3" digit at the end.)

I was curious to see the actual hex values that Buk's script was producing so, on perl 5.22.0 (which provides "%a" formatting), I ran:
use Math::BigFloat;; $n = Math::BigFloat->new( '3.1415926535897932384626433832795' );; $d = 0 + $n->bstr;; printf "%.17f\n", $d;; printf "%a\n", $d;; $bfd = Math::BigFloat->new( sprintf "%.17f", $d );; print $bfd;; $n -= $bfd;; print $n;; printf "%a\n", $n;;
which outputs (when run with the "-l" switch):
3.14159265358979310 0x1.921fb54442d18p+1 3.1415926535897931 0.0000000000000001384626433832795 0x1.3f45eb146ba31p-53
So the most significant double agrees with my ppc box, but the value of the least significant double differs.
Not so sure that splitting the values on the basis of the Math::BigFloat values can provide correct 106-bit values.

Cheers,
Rob

In reply to Re^8: 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.