[Bug c++/105278] no warning for precise literals compared with floats

2022-11-16 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105278

--- Comment #5 from Andrew Pinski  ---
Note I think GCC's -Wfloat-equal is more reasonible than Clang's
-Wliteral-range really. The reason is because even if something can be
represented exactly in floating point (e.g. 3.0 or even 0.0), you could in
theory still get a few precision mismatch due to FMA or some other slight
differences in HW implementation.

[Bug c++/105278] no warning for precise literals compared with floats

2022-04-14 Thread dcb314 at hotmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105278

--- Comment #4 from David Binderman  ---
(In reply to Eric Gallager from comment #3)
> (In reply to David Binderman from comment #2)
> > (In reply to Eric Gallager from comment #1)
> > > -Wfloat-equal gets you a warning, as does -Wdouble-promotion:
> > 
> > Thanks for that. This looks like another case where an obscure flag
> > really ought to be in -Wall or at least -Wextra.
> > 
> > I'll be adding it into my local compiler.
> 
> Which one of them specifically do you want as part of -Wall or -Wextra?
> Because the latter is listed explicitly in some documentation somewhere as
> an example of a flag that would be bad to include in -Wall or -Wextra.

Sorry, I should have been more clear -Wfloat-equal. I haven't looked into
the pros and cons of -Wdouble-promotion. 

If you've got some spare time to pin down "some documentation somewhere",
then that would be appreciated.

[Bug c++/105278] no warning for precise literals compared with floats

2022-04-14 Thread egallager at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105278

--- Comment #3 from Eric Gallager  ---
(In reply to David Binderman from comment #2)
> (In reply to Eric Gallager from comment #1)
> > -Wfloat-equal gets you a warning, as does -Wdouble-promotion:
> 
> Thanks for that. This looks like another case where an obscure flag
> really ought to be in -Wall or at least -Wextra.
> 
> I'll be adding it into my local compiler.

Which one of them specifically do you want as part of -Wall or -Wextra? Because
the latter is listed explicitly in some documentation somewhere as an example
of a flag that would be bad to include in -Wall or -Wextra.

[Bug c++/105278] no warning for precise literals compared with floats

2022-04-14 Thread dcb314 at hotmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105278

--- Comment #2 from David Binderman  ---
(In reply to Eric Gallager from comment #1)
> -Wfloat-equal gets you a warning, as does -Wdouble-promotion:

Thanks for that. This looks like another case where an obscure flag
really ought to be in -Wall or at least -Wextra.

I'll be adding it into my local compiler.

[Bug c++/105278] no warning for precise literals compared with floats

2022-04-14 Thread egallager at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105278

Eric Gallager  changed:

   What|Removed |Added

 CC||egallager at gcc dot gnu.org
   Keywords||diagnostic

--- Comment #1 from Eric Gallager  ---
-Wfloat-equal gets you a warning, as does -Wdouble-promotion:

$ /usr/local/bin/gcc -c -g -O2 -Wall -Wextra -pedantic -Wconversion
-Wfloat-equal -Wdouble-promotion 105278.c
105278.c: In function 'f':
105278.c:5:15: warning: comparing floating-point with '==' or '!=' is unsafe
[-Wfloat-equal]
5 | if (a == 0.1234)
  |   ^~
105278.c:5:15: warning: implicit conversion from 'float' to 'double' to match
other operand of binary expression [-Wdouble-promotion]
$