Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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?

In reply to portably finding max integer by martin

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (5)
    As of 2015-11-30 02:57 GMT
    Find Nodes?
      Voting Booth?

      What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

      Results (756 votes), past polls