On Sat, Nov 9, 2024, 11:19 AM Sad Clouds via Gcc <gcc@gcc.gnu.org> wrote:
> Hello, I don't know if this is a known GCC bug or intentional design, > but code like this: > > double value = 0.0; > ... > if (value == 0.0) > { > ... > } > > Results in the following warning with gcc-12.2.0: > > "... warning: comparing floating-point with ‘==’ or ‘!=’ is unsafe" > > Even though there is nothing unsafe here and comparison to floating > point 0.0 value is well defined. > > The LLVM clang seems to handle this correctly and does not produce any > warnings with -Wfloat-equal option. > > Is there any way to silence GCC without disabling -Wfloat-equal? > You can use the diagnostic pragma to disable it directly for the statement. But I will note comparing double even against 0 can be problematic. You might not get exactly 0 in some cases with things like FMA or when using x87 instructions set. That is it still unsafe. Why clang does not warn is for them to answer. > Thanks. >