Mail Archives: djgpp/1996/01/31/07:36:12
Xref: | news2.mv.net comp.lang.c:54496 comp.lang.c++:69991 comp.os.msdos.djgpp:675 gnu.g++.help:4433 gnu.gcc.help:5648
|
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: | <DM04ur.I6u@cwi.nl>
|
From: | dik AT cwi DOT nl (Dik T. Winter)
|
Date: | Tue, 30 Jan 1996 16:08:50 GMT
|
Sender: | news AT cwi DOT nl (The Daily Dross)
|
References: | <4ej9lb$mpc AT fu-berlin DOT de>
|
Organization: | CWI, Amsterdam
|
Nntp-Posting-Host: | chrysant.cwi.nl
|
Lines: | 24
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
In article <4ej9lb$mpc AT fu-berlin DOT de> axl AT zedat DOT fu-berlin DOT de writes:
> Hello,
> I am getting confused, about how C/C++ manage float binary operations,
> in particular multiplication. The next C++ example gives me surprising
> results:
.....
> float quad( float );
.....
> a = i/13.123123;
> b = a*a;
> c = quad(a);
> cout << (b - c) << '\t';
> cout << (b - a*a) << '\t';
> cout << (c - quad(a)) << '\n';
Declaring a function as returning float does not imply that the actual
value returned is indeed a float! In K&R times expressions involving
floats were calculated using doubles. Some compilers extended that
to functions declared as returning float: a double result was returned;
others did indeed truncate the return value to float. Thorough
reading of K&R does not lead to a clear solution here. In ANSI C both
are allowed.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924098
- Raw text -