delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/01/30/02:30:39

Date: Tue, 30 Jan 1996 09:23:20 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Axel Thimm <axl AT zedat DOT fu-berlin DOT de>
Cc: djgpp AT delorie DOT com
Subject: Re: float != float and floats as return types

On Mon, 29 Jan 1996, Axel Thimm wrote:

> 	    c = quad(a);
> 	    cout << (b - c) << '\t';
> 	    cout << (b - a*a) << '\t';
> 	    cout << (c - quad(a)) << '\n';
[snip]
> digits, but I cannot understand what happens with c! Both times a
> function is called, that _is_not_ inlined, so in both cases the same
> loss of digits should be observed.

Look at the machine code generated by GCC.  Most probably, the result of
`quad' is stored in c to lose some precision.  When c - quad(a) is
computed, the compiler doesn't bother to store the result of `quad', but 
instead leaves it on the stack of the FPU and just subtracts it from c.  
You then see how much did you lose by using a float (a relative precision 
of 1e-7 is usually all you can rely on with floats; use double for twice 
as much significant digits).

If you want to make this ``feature'' go away, try using the -ffloat-store 
switch to GCC.  It's described in the GCC docs.


- Raw text -


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