approximatelyEqual rationale

Hi,

I notice that the JUCE code had a massive change recently where (all ?) float comparisons were replaced by a call to approximatelyEqual or exactlyEqual :

I wonder what is the rationale here, especially in cases where a comparison to 0.0 is replaced by approximatelyEqual(x, 0) .

We hit a hard to reproduce bug recently which came down to the fact that we were comparing floats. Really you should never compare floats using == in the few cases where we’re confident we want an exact comparison we also added exactlyEqual().

2 Likes

It might be nice to have a tuneable overload of approximatelyEqual() for things like autocorrelation with error margins, I think that’s what the ULP argument offers in this example:

https://en.cppreference.com/w/cpp/types/numeric_limits/epsilon

1 Like