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?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.