This is not a mistake; it is a very well-documented phenomenon of the IEEE754 floating point standards.
There is a limited number of bits to represent floating point numbers, and there is, let me see if I can remember, yes, an infinite number of real numbers between any two different numbers.
This means that you cannot represent all real numbers, but must provide approximations.
A way to fix this does not mean that numbers can be represented accurately. You must determine if the number is enough to be zero and not equal to zero, and you can do this by choosing a suitable small error value based on your numbers and operations.
Read What Every Computer Scientist Should Know About Floating-Point Arithmetic as a Detailed Treatise (Warning, this can be a bit difficult to read), or the Floating-Point Guide has a softer introduction, as well as a link to > PHP Math Package (arbitrary precision arithmetic), which may be useful to you.
source share