Hello,
I am designing a library module that should be able to switch from native perl integer arithmetic to Math::BigInt if need arises. To that end I need to find out the biggest integer of the currently running perl interpreter in a portable way.
For now I have come up with two approaches:
# solution 1
use Config;
if ($Config{'use64bitint'}) {
# max_integer is probably 2**63-1
}
else {
# max_integer is probably 2**31-1
}
# solution 2
my $max_int = (-1)>>1;
Both solutions seem to work on UNIX/i386 machines I have access to. But how portable is either one? Is there a better way? In case of doubt my module should rather assume a smaller value than risk loss of precision when perl internally switches to floating point. Would 2147483647 (2**31-1) be an integer value for any perl (5.6 or higher) on any platform out there?