It could be that they're not actually the same. Sure, they may look the same, but depending on what calculations were used to derive those numbers, their appearance may be deceiving to you; you could be getting bit by the floating point problems inherent in converting base two (binary) representations of numbers into base ten representations. This is discussed further in perlfaq4 under the heading, "Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?".

The short version of it is that it's problematic to perform equality comparisons on floating point numbers. This is not a Perl-specific issue; it exists for any language where numbers are represented internally in base-2 (binary).

Update: I just remembered an article that I found a year or so ago: What Every Computer Scientist Should Know About Foating-Point Arithmetic. It's an excellent article, and might qualify as "far more than you ever wanted to know", but definately will give you enough information to never fall for this type of bug again.


Dave


In reply to Re: problem with variables by davido
in thread problem with variables by jeanluca

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.