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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |