That's terrific, thanks.

That uses the first idea: unpack as two L's.

It seems your design goal was portability, since you automatically detect the endian.

I see that you try to unpack "Q" first (in the signed form, you should be using "q"). I like that idea, but I think I'll swap out the whole sub so it only tries once when it decides it can't do that. In yours, you'll confuse a valid 0 integer with failure.

I noticed you wrote 1+~0 for 0x100000000, and my first impression was that this was also for portability. But, I think it's nonportable now, and that's just clearer than writing it out in decimal (the hex form overflows Perl's parser and is not allowed). But, unpack "L" is specifically 32-bit fields and not necessarily the native size, and nowhere does it say what size bit operators operate on, but I think this is the definition of "native size".

So, you are assuming that the native size is 32 bits if quadword support is disabled. I think I'll use 2**32 for clarity, and trust the optomizer to fold the constant arithmetic down.

—John

update: I didn't notice the extra ;1; at the end of the eval block. Cute. But easy to miss.


In reply to Re: (tye)Re: 52-bit numbers as floating point by John M. Dlugosz
in thread 52-bit numbers as floating point by John M. Dlugosz

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.