www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/02/02/19:50:20

Xref: news2.mv.net comp.lang.c:54828 comp.lang.c++:70380 comp.os.msdos.djgpp:742 gnu.g++.help:4479 gnu.gcc.help:5681
From: eggert AT twinsun DOT com (Paul Eggert)
Newsgroups: comp.lang.c,comp.lang.c++,gnu.gcc.help,gnu.g++.help,comp.os.msdos.djgpp
Subject: Re: float != float and floats as return types
Date: 2 Feb 1996 12:57:08 -0800
Organization: Twin Sun Inc, El Segundo, CA, USA
Lines: 34
Message-ID: <4ettr4$al5@der.twinsun.com>
References: <4ej9lb$mpc AT fu-berlin DOT de> <4elnjj$er4 AT server2 DOT rz DOT uni-leipzig DOT de> <4eqc7l$ugh AT godzilla DOT zeta DOT org DOT au> <4eqtu3$ddo AT der DOT twinsun DOT com> <TANMOY DOT 96Feb1164022 AT qcd DOT lanl DOT gov>
NNTP-Posting-Host: der.twinsun.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

tanmoy AT qcd DOT lanl DOT gov (Tanmoy Bhattacharya) writes:

> I do not agree with this interpretation, as the footnote (technically,
> not part of the standard) clarifies: an assignment and cast both must
> truncate the result to the required precision.

Sorry, that footnote doesn't clarify matters.  All the footnote says
is that the required conversions must be performed.  In the example
we're talking about, there's no conversion to be performed, since
both sides of the assignment have `float' type.

Furthermore, even if there is a conversion, I don't see where the standard
requires that excess precision be discarded.  All the standard requires is
that the result be ``represented exactly''; it doesn't say what it means
by this, and an implementation that keeps excess precision is certainly
representing _its_ result exactly.  The standard explicitly licenses
excess precision, and never explicitly (or implicitly, as far as I can
see) requires excess precision to be discarded.

Also please see ANSI C 3.3.4, which says ``A cast that specifies no
conversion has no effect on the type or value of the expression'';
this means that an implementation with extra precision is not allowed
to discard it because of a cast of float to float.  It is natural to
assume that assignment of float to float can behave similarly to a cast.

I realize that the standard is muddled in this area -- for example, the
Rationale contradicts it, and I've been told that the C Standard committee
may amend 3.3.4 because of the problem with floating point casts
(surely an implementation should be allowed to discard excess precision
whenever it wants to).

That being the case, I think it wise for users not to rely on the fine
points here, and my advice to the GCC implementers is to hold off on
changing GCC's behavior until the C Standard committee acts.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019