Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi Monks,

I ran below code with use integer line commented and uncommented.

#!/usr/bin/perl #use integer; my $max_neg_num=((2**32)-1); print "\nmax neg num is $max_neg_num\n"; $error=4294967263 -$max_neg_num-1; print "error is $error \n";

With use integer commented: max neg num is 4294967295 error is -33

With use integer uncommented. max neg num is -2 error is -32

When I looked at integer pragma documentation, it says numbers are wrapped around after largest +ve number i.e. 2^31-1. By that logic max neg number should be -1 represented by 2^32-1.

Also, I am surprised that without integer pragma, how come I am able to see the results correctly even though it is 32 bit machine? I think its a naive question, but I am afraid I will remain naive if I dont ask it. I would like to know how such arithmetic is handled on 32 bit machines. Is there a potability issue if I write the code as above with use integer commented?

Please enlighten me!!


In reply to Question on simple arithmetic using perl by perlbaski

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (11)
    As of 2014-07-22 13:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (113 votes), past polls