Bug#175809: Strange or incorrect floating point behaviour
On Fri, Jan 10, 2003 at 11:58:33AM +0100, Gerhard Wesp wrote:
> > Do you get the expected results if you do this?
> Yes and no.
> I include a modified example.
> The assertion fails if compiled with -O3 -ffloat-store -DA, it doesn't
> if compiled without the -DA. So it seems to depend on where the
> assignments take place.
> #if defined( A )
> double ku ;
> double kx ;
> assert( ( ku = 2.5 * u ) >= ( kx = 2.5 * x ) ) ; // fails.
> double ku = 2.5 * x ;
> double kx = 2.5 * u ;
> assert( ku >= kx ) ; // doesn't fail.
Yup, that's C for you. The former uses the value of 2.5*u, the latter
uses the value of ku. You can see how this works by declaring ku
volatile and looking at the assembly; it'll be reloaded in the second
case but not the first.
MontaVista Software Debian GNU/Linux Developer