// 20 Oct 2006, Jeff Ondich // A toy program for investigating the 32-bit IEEE 754 floating point format. // // For those of you who have not worked with C++, compile this like so: // // g++ -o floatformat floatformat.cpp // // and then run simply by typing the name of the executable: // // floatformat // #include using namespace std; void printfloat( float x ) { cout << x << ", " << "0x" << hex << (*((int *)&x)) << endl << endl; } int main() { float x, y, z; x = 0.0; y = 0.0; z = x / y; cout << "Should be not-a-number" << endl; printfloat( z ); z = 5.0 / x; cout << "Should be positive infinity" << endl; printfloat( z ); z = -5.0 / x; cout << "Should be negative infinity" << endl; printfloat( z ); z = -6.5; cout << "Should be -6.5" << endl; printfloat( z ); return 0; }