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
abs($n1 - $n2) < $epsilon
In reply to Re: Integers sometimes turn into Reals after substraction
in thread Integers sometimes turn into Reals after substraction by rduke15
<code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>