Is this a compiler bug?
A Moore
happyjoe@dontemail.com
Thu Feb 16 21:50:00 GMT 2006
Using floats, floor() returns wrong result, as shown in this program:
( BTW, using gcc 4.0.1 )
#include <cmath>
#include <iostream>
int
main()
{
float x( 3.31682e-7 );
float y( -292.608 );
float z( 19.5072 );
std::cout << "Using floats, floor() returns the wrong result:" <<
std::endl;
std::cout << "( x - y ) / z : " << ( ( x - y ) / z ) << std::endl;
std::cout << "floor of ( ( x - y ) / z ) : " << ::floor( ( x - y ) /
z ) << std::endl;
double xx( 3.31682e-7 );
double yy( -292.608 );
double zz( 19.5072 );
std::cout << "Using doubles, floor() works as expected:" << std::endl;
std::cout << "( xx - yy ) / zz : " << ( ( xx - yy ) / zz ) << std::endl;
std::cout << "floor of ( ( xx - yy ) / zz ) : " << ::floor( ( xx - yy
) / zz ) << std::endl;
return 0;
}
More information about the Gcc-bugs
mailing list