Search code examples
c++stdequalityfloating-accuracy

Is std::equal_to reliable for float types?


To be more exact, does std::equal_to<float>()(float a,float b) or std::equal_to<double>()(double a,double b) does the somewhat better float equality like abs(diff) < EPSILON or just a==b?


Solution

  • std::equal_to uses == to perform the comparison. If you want to compare with a tolerance, you'll have to write that yourself. (Or use a library.)