[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#175809: Strange or incorrect floating point behaviour



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

Regards,
-Gerhard

#include <cassert>

#if 1
  template< typename T > inline void bound( T     & x , T      const& u
) {
#else
                         inline void bound( double& x , double const& u
) {
#endif
  assert( 1. <= u ) ;            // (1)
  if( x < 1. ) { x = 1. ; }      // (2)
  if( x > u  ) { x = u  ; }
}
 
int main() {
  const double u = 2.1 ;
  double x = 3 ;
  bound( x , u ) ;
  assert( u >= x ) ;

#if defined( A )
  double ku ;
  double kx ;
  assert( ( ku = 2.5 * u ) >= ( kx = 2.5 * x ) ) ; // fails.
#else
  double ku = 2.5 * x ;
  double kx = 2.5 * u ;
  assert( ku >= kx ) ;                             // doesn't fail.
#endif

}

-- 
| voice: +43 (0)676 6253725  ***  web: http://www.cosy.sbg.ac.at/~gwesp/
|
| Passts auf, seid's vuasichdig, und lossds eich nix gfoin!
|  -- Dr. Kurt Ostbahn



Reply to: