www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/02/15/05:38:00

Xref: news2.mv.net comp.lang.c:56546 comp.lang.c++:72614 comp.os.msdos.djgpp:1125 gnu.g++.help:4634 gnu.gcc.help:5826
From: rfg AT monkeys DOT com (Ronald F. Guilmette)
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: 15 Feb 1996 01:15:26 -0800
Organization: Infinite Monkeys & Co.
Lines: 37
Message-ID: <4futje$6a4@segfault.monkeys.com>
References: <4ej9lb$mpc AT fu-berlin DOT de> <DM04ur DOT I6u AT cwi DOT nl>
NNTP-Posting-Host: segfault.monkeys.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <DM04ur DOT I6u AT cwi DOT nl>, Dik T. Winter <dik AT cwi DOT nl> wrote:
>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!

Yes, it does.

Please check the ISO C standard and all relevant Committee responses to
official Defect Reports before making incorrect claims.

>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.

That is simply untrue.
-- 

-- Ron Guilmette, Roseville, CA -------- Infinite Monkeys & Co. ------------
---- E-mail: rfg AT monkeys DOT com ----------- Purveyors of Compiler Test Suites -
------ Copyright (c) 1996 by Ronald F. Guilmette; All rights reserved. -----

- Raw text -


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