Float equality warnings in gcc/clang

At seemingly random points I get new warnings thrown up and today is one of those days.

We know that comparing floats can be problematic but now it’s official. There are obvious ways around it in non-templated code (e.g. x <= y && y <= x) but in templated code like this CachedValue example it’s a bit more of a pain.

What’s the best way to deal with it here? A isEqual template that can be specialised and is for float/double?

You can use juce::exactlyEqual when you’re certain that a direct comparison (i.e. no epsilon) has the correct semantics.

Can you use that in CachedValue to suppress the warning please? The semantics will be the same as they always have been anyway.

1 Like

Yep, I’ll add that