NERDVANA has asked for the wisdom of the Perl Monks concerning the following question:
I occasionally want to publish perl modules that require 64-bit integers and "pack 'Q'" support. The modules can be expanded to work on old and 32-bit perls by using BigInt, but I don't want to encumber the main users of the module with that performance hit for such rarely encountered environments. I'm looking for a generic toolkit of functions to solve this, and if it doesn't exist, I'm looking for a good CPAN name to publish mine.
For example, here is the shim I made to support "pack 'Q'" for 32-bit perl and the test I use to usually avoid needing it.
I also want to be able to declare 64-bit constants, for which I created this: (not yet published)
sub _int64_native { $_[0] =~ /^(-?)0x(.*)/? hex($2)*($1? -1 : 1) : 0+$_[0] } sub _int64_bigint { Math::BigInt->new($_[0]) } # Can scalars hold 64-bit ints natively? if ((0x7FFFFFFE << 31) > 0 && (0x7FFFFFFE << 63) == 0) { *int64= \&_int64_native; } else { *int64= \&_int64_bigint; }
Which I can use like this:
int64('-0x10000000000');
Before I go too far here, is there a CPAN module I'm overlooking?
If not, I'd like to make one. What should I name it?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Supporting 64-bit ints on 32-bit perl
by hippo (Archbishop) on Apr 19, 2023 at 22:40 UTC | |
by NERDVANA (Priest) on Apr 19, 2023 at 22:53 UTC | |
by syphilis (Archbishop) on Apr 20, 2023 at 00:59 UTC | |
by NERDVANA (Priest) on Apr 20, 2023 at 01:26 UTC | |
by syphilis (Archbishop) on Apr 20, 2023 at 02:56 UTC |