Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Comment on

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

Hi,

I’ve been using the exponentiation operator ** in conjunction with the bigint pragma to generate large integral powers, which I need to be exact. After some debugging, I found the following:

#! perl use strict; use warnings; use bigint; print "\nWith two foreach loops:\n\n"; for my $i (12 .. 14) { for my $j (20 .. 22) { print $i ** $j, "\n"; } } print "\nWith an inner C-style for loop:\n\n"; for my $i (12 .. 14) { for (my $j = 20; $j <= 22; ++$j) { print $i ** $j, "\n"; } }

Output:

22:38 >perl 604_SoPW.pl With two foreach loops: 3.83375999244748e+021 4.60051199093697e+022 5.52061438912436e+023 1.90049637748808e+022 2.4706452907345e+023 3.21183887795486e+024 8.36682554252848e+022 1.17135557595399e+024 1.63989780633558e+025 With an inner C-style for loop: 3833759992447475122176 46005119909369701466112 552061438912436417593344 19004963774880799438801 247064529073450392704413 3211838877954855105157369 83668255425284801560576 1171355575953987221848064 16398978063355821105872896 22:38 >

As you can see, the inner foreach loop is somehow cancelling the effect of the use bigint pragma; but converting that loop into a C-style for loop fixes the problem and gives me the output I need.

So, what’s going on? Is this behaviour documented anywhere? Is it a bug?

Thanks,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Strange interaction of bigint and foreach by Athanasius

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 rifling through the Monastery: (11)
    As of 2014-09-23 19:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (239 votes), past polls