New comment on reddit

Because you have floating point numbers

Floating point numbers get represented in IEEE 754 format

In short, binary doesn’t handle floating point – so it gets approximated

Traditionally, to compare “equivalence” of two floating point values, you subtract one from the other, and see if the abs() of the result is less than a defined epsilon

And you adjust your epsilon to manage the error window you’re willing to work inside of (for money, for example, you likely can get away with epsilon=0.0001;)

For example:

result=false; epsilon=0.000000000001 if(abs(a-b)<epsilon) { result=true; } 

See https://en.wikipedia.org/wiki/IEEE_floating_point

April 09, 2020 at 02:15PM
via reddit https://www.reddit.com/r/PHP/comments/fxxdnp/why_1112_929_2041/fmx061f?utm_source=ifttt