On Sun, 10 Nov 2024, 08:26 Sad Clouds via Gcc, <gcc@gcc.gnu.org> wrote:
> On Sat, 9 Nov 2024 11:49:56 -0800 > Andrew Pinski <pins...@gmail.com> wrote: > > > You can use the diagnostic pragma to disable it directly for the > statement. > > Thanks for the tip. After a quick search, I came across this page, > which explains it: > https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html > > > 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. > > I'm not sure I understand this. As far as I know, 0.0 can be > represented exactly in a floating point type. So the statement > "if (value == 0.0)" should always be true if value is exactly 0.0. > > I'm not really concerned about "value = 0.1 - 0.1" not resulting in 0.0. > That will result in 0.0 though. But 1 - (10 * 0.1) won't, and so the warning is pointing out that any exact equality comparisons can be affected by this kind of problem. If you don't like the warning, don't enable it. It is more of a case where value was explicitly initialised to 0.0 and > then later used in the equality comparison. > Does clang only have a special case for 0.0, or for any literal value? >