in reply to 52-bit numbers as floating point

The first one is pretty easy. See (tye)Re: 64 bit Integer anyone? for my version. It even detects if the number didn't quite fit in the 52 bits.

        - tye (but my friends call me "Tye")
  • Comment on (tye)Re: 52-bit numbers as floating point

Replies are listed 'Best First'.
Re: (tye)Re: 52-bit numbers as floating point
by John M. Dlugosz (Monsignor) on Aug 08, 2002 at 15:01 UTC
    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 yours, you'll confuse a valid 0 integer with failure.

      No, it won't. Your other points are valid. (:

              - tye (but my friends call me "Tye")