public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110321] New: Double precision comaprison does not seem to work well when -std=c++17 option is selected
@ 2023-06-20 15:14 serge.ayoun at outlook dot com
2023-06-20 15:18 ` [Bug c++/110321] " redi at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: serge.ayoun at outlook dot com @ 2023-06-20 15:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110321
Bug ID: 110321
Summary: Double precision comaprison does not seem to work well
when -std=c++17 option is selected
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: serge.ayoun at outlook dot com
Target Milestone: ---
The following code:
int main(int, char**)
{
double a = 2.2;
if ( a == 2.2) return 1;
return 0;
}
compiled and link with the following instruction:
g++ -O0 -m32 -std=c++17
with gcc 11.1, returns 1 as expected
with gcc 13.1, returns 0.
when -std=c++17 is removed, both return 0 as expected.
for exact reproduction See:
https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1DIApACYAQuYukl9ZATwDKjdAGFUtAK4sGe1wAyeAyYAHI%2BAEaYxHoADqgKhE4MHt6%2BcQlJAkEh4SxRMVy2mPaOAkIETMQEqT5%2BRXaYDskVVQQ5YZHRegqV1bXpDX3twZ353VwAlLaoXsTI7BzBBADULEzBEMukK8gIVQBUB5MmGgCCJgDsFiunZysPK%2BizEfQrTLcAzAAiK2YAdGYTJ8rOdHis8FQVhB3l9vsDfgCzJMVsRMAQ5gwVlxgTc7uC0RjiFiNLjbucrt8ONNaJwAKy8PwcLSkVCcNzWawrBSzeaYW5mT48UgETTU6YAaxAkku/zpAE4uBoAGzyz6fDRceXyy7Kun6TiSRli1mcXgKEAaEVi6ZwWAwRAoVAsWJ0aLkShoF1umLALhC0hYABueAWADU8JgAO4AeVijE4wpotAI0QtEAiJoiwSqAE9E7xs8xiLmYxFtE1RdxeF62IIYwxaPnmbwsBEvMA3GJaBbq4HMOsjOIW4G8GjmkHML2WZhVE0vKmC%2BRBCUTbQ8BFiHmPFgTQRiHgWAXplQDMAFBHo3GE33%2BIIRGJ2FIZIJFCp1CPdEUDEYUJzLPoG4WpA0yoLEZQML2AC0MYaCsUEsJ8Zjwb06AIqYljWFwly8Kgk7EAeWDARA0yNM0zgQK4Az1KQgSjHkBQZIkEHUUxWQMB0DETMUpQtMMrENCUlZ8W0nFdIUtj8Z4dQ9MMYnjIUpG8gsEg0vSxojmyHArKoAAcypQcqkgrMAyDINinz/Fw0K4IQJACkKky8FWWiTJKIB0latIcEapBHpI8r/Boum6ZcZjypqyqXPpdKXKQTIslp5qWtaLa2g6EBIF6rr0GQFAQNlPogH6XBFMGoaYJesbxkySZ0KmxDppmI5FnmS6tSWZYVg4S61owBANk2Jpth2Xa0D2S5YIOwDDiy%2BDjo4k7Trws7zoufbLKuI7rpu24YIsLL7oex58GeF6RtVN5JrID7iM%2Bd7yEoagmroZj6IYxj/jYO3EaB4HJNBsHwYhyFQah6FfdhuH4YRU7wKRQnkX4lEMO40mDLRqPyYxRTxMxyQCaQePsdj3FkRBrT9OjNHkyJ1SkxJvRtITTP0/R4mqTMcwqVMBocAy8UmlpOn6YZxmmeZpVWTZ%2BBEMQDlTM5NrTAgmBMFgMQkXzvlHp5/yKlwZiXBo8q6Uh/qSJ8guaWatgpS54qkFKdIApIwVqiqqq6RoGiCvq3mfBpiW2w7bl82YQe4SHyukPhiTOJIQA%3D
Thanks,
Serge
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/110321] Double precision comaprison does not seem to work well when -std=c++17 option is selected
2023-06-20 15:14 [Bug c++/110321] New: Double precision comaprison does not seem to work well when -std=c++17 option is selected serge.ayoun at outlook dot com
@ 2023-06-20 15:18 ` redi at gcc dot gnu.org
2023-06-20 15:21 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2023-06-20 15:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110321
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
As described in the manual, sincve GCC 13.1 -fexcess-precision=standard is
enabled by -std=c++NN (but not by -std=gnu++NN).
This means the literal 2.2 is represented with excess precision, and so is not
equal to the same value converted to double.
You can use (a == (double)2.2) to make the comparison work.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/110321] Double precision comaprison does not seem to work well when -std=c++17 option is selected
2023-06-20 15:14 [Bug c++/110321] New: Double precision comaprison does not seem to work well when -std=c++17 option is selected serge.ayoun at outlook dot com
2023-06-20 15:18 ` [Bug c++/110321] " redi at gcc dot gnu.org
@ 2023-06-20 15:21 ` pinskia at gcc dot gnu.org
2023-06-20 15:31 ` redi at gcc dot gnu.org
2023-06-20 16:21 ` serge.ayoun at outlook dot com
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-20 15:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110321
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Invalid as explained.
More over this is basically bug 323 in reverse.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/110321] Double precision comaprison does not seem to work well when -std=c++17 option is selected
2023-06-20 15:14 [Bug c++/110321] New: Double precision comaprison does not seem to work well when -std=c++17 option is selected serge.ayoun at outlook dot com
2023-06-20 15:18 ` [Bug c++/110321] " redi at gcc dot gnu.org
2023-06-20 15:21 ` pinskia at gcc dot gnu.org
@ 2023-06-20 15:31 ` redi at gcc dot gnu.org
2023-06-20 16:21 ` serge.ayoun at outlook dot com
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2023-06-20 15:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110321
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|INVALID |FIXED
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #1)
> You can use (a == (double)2.2) to make the comparison work.
Or use -std=gnu++17, or use -std=c++17 -fexcess-precision=fast
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/110321] Double precision comaprison does not seem to work well when -std=c++17 option is selected
2023-06-20 15:14 [Bug c++/110321] New: Double precision comaprison does not seem to work well when -std=c++17 option is selected serge.ayoun at outlook dot com
` (2 preceding siblings ...)
2023-06-20 15:31 ` redi at gcc dot gnu.org
@ 2023-06-20 16:21 ` serge.ayoun at outlook dot com
3 siblings, 0 replies; 5+ messages in thread
From: serge.ayoun at outlook dot com @ 2023-06-20 16:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110321
--- Comment #4 from Serge Ayoun <serge.ayoun at outlook dot com> ---
Thanks guys for your help
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-20 16:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-20 15:14 [Bug c++/110321] New: Double precision comaprison does not seem to work well when -std=c++17 option is selected serge.ayoun at outlook dot com
2023-06-20 15:18 ` [Bug c++/110321] " redi at gcc dot gnu.org
2023-06-20 15:21 ` pinskia at gcc dot gnu.org
2023-06-20 15:31 ` redi at gcc dot gnu.org
2023-06-20 16:21 ` serge.ayoun at outlook dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).