What about this situation - assuming you can get a large loan in Galactic Credits, at 0% APR, for a year:
use strict; use warnings; use diagnostics; my $amount = 1e9; my $months = 12; my $repayment = $amount/$months; print "Monthly repayment = $repayment\n"; use integer; $repayment = $amount/$months; print "Monthly repayment = $repayment\n";

prints out:

Monthly repayment = 83333333.3333333
Monthly repayment = 83333333

which is not the same thing!

On a different, but related note, increasing the loan to 1e12 Galactic Credits, gives this:

Monthly repayment = 83333333333.3333
Monthly repayment = 0

That's because the loan amount is too big to hold in an integer (on my machine anyway):

perl -le'use POSIX;print for SHRT_MAX, INT_MAX, LONG_MAX, FLT_MAX, DBL +_MAX;' 32767 2147483647 2147483647 3.40282346638529e+38 1.79769313486232e+308

So use the integer pragma with caution!


In reply to Re^4: Numeric Comparisons Randomly Giving the Wrong Result by mjscott2702
in thread Numeric Comparisons Randomly Giving the Wrong Result by Likeless

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!
  • 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:
    & &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.