First of all, 4/25 is periodic in binary (just like 1/3 is periodic in decimal).

____________________ 4/25 = 0.00101000111101011100 base 2

This means it can't be stored exactly in a floating point number.

Sometimes, floating point number errors get canceled out or reduced to nothing. It turns out that this happens for one of the chains of operations but not the other.

That's why you want to avoid checking if two floating point numbers are equal without allowing for an error margin. Replace

$n1 == $n2

with

abs($n1 - $n2) < $epsilon

In reply to Re: Integers sometimes turn into Reals after substraction by ikegami
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":