public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/110477] -fexcess-precision=standard not applied consistently
Date: Thu, 29 Jun 2023 08:31:13 +0000	[thread overview]
Message-ID: <bug-110477-4-uwWXmmWFgA@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110477-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110477

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Peter Dimov from comment #1)
> Looks like a duplicate of
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108742 and is fixed by casting
> the rhs to (float),

Yes, with -fexcess-precision=standard removal of excess precision only occurs
when assigning to an lvalue or with an explicit cast, not for the equality
comparison.  An even simpler version is:

double f = 2.1;
assert( f == 2.1 ); // fails

The value f has no excess precision bits, but the literal 2.1 is evaluated as
an 80-bit float. The comparison promotes f to the type of the rhs, but it's
lost its excess precision, so we're effectively doing (double)2.1L == 2.1L and
that's false.

> but any ordinary programmer would be baffled.

Yes, very much so.


(In reply to Peter Dimov from comment #3)
> That's true, but the normal expectation of anyone using
> -fexcess-precision=standard would be for it to apply consistently everywhere
> (that is, as if FLT_EVAL_METHOD is 0.)
> 
> Of course given that FLT_EVAL_METHOD is in a header, so unaffected by -f
> options, it's not clear what can be done here.

I think the rationale is that without -fexcess-precision=standard we do not
correctly respect FLT_EVAL_METHOD, so its value doesn't matter. With
-fexcess-precision=standard we do respect it ... with confusing consequences.

The solution is to kill i387 ;-)

-m32 -mfpmath=sse gives more sensible results.

  parent reply	other threads:[~2023-06-29  8:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-29  7:28 [Bug c++/110477] New: " pdimov at gmail dot com
2023-06-29  8:00 ` [Bug c++/110477] " pdimov at gmail dot com
2023-06-29  8:04 ` pinskia at gcc dot gnu.org
2023-06-29  8:10 ` pdimov at gmail dot com
2023-06-29  8:31 ` redi at gcc dot gnu.org [this message]
2023-06-29  8:32 ` redi at gcc dot gnu.org
2023-06-29  8:44 ` pdimov at gmail dot com
2023-06-29  9:07 ` mkretz at gcc dot gnu.org
2023-06-29 11:00 ` pdimov at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110477-4-uwWXmmWFgA@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).