#include #include #include #include using namespace std; // just a random floating point constant. const double MY_NUMBER{23.3124}; void PrintNums(); int main() { float aNumber{1.0f}; string restOfLine; cout << "Default " << endl; PrintNums(); cout << "With Showpoint " << endl; cout << showpoint; PrintNums(); cout << "With setprecision(15) " << endl; cout << noshowpoint; cout << setprecision(15); PrintNums(); cout << "with fixed " << endl; cout << fixed; PrintNums(); cout << "with scientific " << endl; cout << scientific; PrintNums(); cout << defaultfloat; cout << "With defaultfloat" << endl; PrintNums(); cout << endl << endl; while (aNumber != 0) { cout << "Enter a number =>"; cin >> aNumber; getline(cin, restOfLine); cout << "The number was " << aNumber << endl; cout << "The rest of the line was \"" << restOfLine << '"' << endl; cout << endl; } cout << endl << endl; cout << setprecision(40); cout << "The Limits" << endl; cout << "\tfloat min: " << numeric_limits::min() << endl; cout << "\tfloat max: " << numeric_limits::max() << endl; cout << "\tdouble min: " << numeric_limits::min() << endl; cout << "\tdouble max: " << numeric_limits::max() << endl; cout << "\tlong double min: " << numeric_limits::min() << endl; cout << "\tlong double max: " << numeric_limits::max() << endl; cout << endl << endl; cout << "The Gap " << endl; aNumber = 7; cout << aNumber << " + " << numeric_limits::max() << endl; aNumber += numeric_limits::max(); cout << " = " << aNumber << endl; cout << endl << endl; cout << "Overflow " << endl; cout << " " << aNumber << endl << " + " << aNumber << endl; aNumber += aNumber; cout << " = " << aNumber << endl; cout << endl << endl; cout << "Roundoff " << endl; cout << fixed; aNumber = 1.0e-15f; cout << "1.0e-15f = " << aNumber << endl; cout << endl << endl; cout << "NAN" << endl; cout << " 4/0 = " << 4/0 << endl; return 0; } void PrintNums() { float aNumber{1.0f}; float bNumber{1.0f}; int i{0}; string junk; while(i < 10) { cout << setw(30) << aNumber << setw(40) << bNumber << endl; aNumber /= 11; bNumber *= 11; ++i; } cout << endl; cout << "Press enter to continue"; getline(cin,junk); cout << endl << endl; return; }