Well Perl's error correction (or that of the underlying C lib) is better than it's reputation
DB<186> $x1= 1000*(4/25) => 160 DB<187> $x2= 4000/25 => 160 DB<188> $x1 == $x2 => 1

What's puzzling me is this behaviour:

DB<205> for (254..263) {$x = 1000 * ( $_ + 4/25 ); printf "%.20f\n" +, $x} 254160.00000000000000000000 255160.00000000000000000000 256160.00000000002910383046 257160.00000000002910383046 258160.00000000002910383046 259160.00000000002910383046 260160.00000000002910383046 261160.00000000002910383046 262160.00000000000000000000 263160.00000000000000000000

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

update

interestingly this only seems to happen near some powers of 2

DB<220> for (0..20) {$e=2**$_; $x = 1000 * ( $e + 4/25 ); printf "$ +_:$e => %.20f\n", $x if ($x-int($x))} 5:32 => 32159.99999999999636202119 8:256 => 256160.00000000002910383046 9:512 => 512159.99999999994179233909 10:1024 => 1024160.00000000011641532183 11:2048 => 2048159.99999999976716935635 15:32768 => 32768160.00000000372529029846 18:262144 => 262144159.99999997019767761230 19:524288 => 524288160.00000005960464477539 20:1048576 => 1048576159.99999988079071044922

update

in hindsight this may be an effect of precision and correction of the underlying processor and usage of arithmetic units, hence machine dependent.


In reply to Re^2: Integers sometimes turn into Reals after substraction (error correction ?) by LanX
in thread Integers sometimes turn into Reals after substraction by rduke15

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.