www.delorie.com/archives/browse.cgi | search |
Xref: | news2.mv.net comp.lang.c:54740 comp.lang.c++:70278 comp.os.msdos.djgpp:726 gnu.g++.help:4465 gnu.gcc.help:5670 |
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 |
Message-ID: | <TANMOY.96Feb1164022@qcd.lanl.gov> |
From: | tanmoy AT qcd DOT lanl DOT gov (Tanmoy Bhattacharya) |
Date: | 01 Feb 1996 23:40:22 GMT |
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> | |
Organization: | Los Alamos National Laboratory |
NNTP-Posting-Host: | qcd.lanl.gov |
In-reply-to: | eggert@twinsun.com's message of 1 Feb 1996 09:40:19 -0800 |
Lines: | 35 |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
In article <4eqtu3$ddo AT der DOT twinsun DOT com> eggert AT twinsun DOT com (Paul Eggert) writes: <snip> bde AT zeta DOT org DOT au (Bruce Evans) writes: > a = 1.0; > b = FLT_EPSILON / 4.0; > c = a + b; > assert(c == (float) (a + b)); As far as I can tell the C Standard allows the assertion to either succeed or fail, depending on the implementation. The key phrase in the standard is ``The values of floating operands and of the results of floating expressions may be represented in greater precision and range than that required by the type''. So `c' might be represented in more bits than `(float) (a + b)' (or vice versa! though this is more controversial since it contradicts the Rationale, and it may be corrected by the committee soon), and the assertion might fail. 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. It can be subsequently widened to more precision: but that is a different matter. Now whether `a+b' must always give the same answer (for constant a and b) may be debatable: but certainly not outside comp.std.c (or c++) :-) Cheers Tanmoy -- tanmoy AT qcd DOT lanl DOT gov(128.165.23.46) DECNET: BETA::"tanmoy AT lanl DOT gov"(1.218=1242) Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544 Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>, <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/ internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |