#include #include //for setprecision #include #include //for atan #include //for FLT_DIG, DBL_DIG, LDBL_DIG using namespace std; /* By default, C and C++ print 6 significant digits of a float, double, or long double. In C++, override this default with setprecision. The _DIG macros give the maximum number of significant digits (in decimal) that the data type can hold. 4.0f is of data type float, 4.0 is double, 4.0L is long double. The value of pi is 3.14159 26535 89793 23846 26433 83279 50... */ int main() { const float pi_float = 4.0f * atan(1.0f); cout << setw(2) << FLT_DIG << " significant digits: " << setprecision(FLT_DIG) << pi_float << "\n"; const double pi_double = 4.0 * atan(1.0); cout << DBL_DIG << " significant digits: " << setprecision(DBL_DIG) << pi_double << "\n"; const long double pi_long_double = 4.0L * atan(1.0L); cout << LDBL_DIG << " significant digits: " << setprecision(LDBL_DIG) << pi_long_double << "\n"; return EXIT_SUCCESS; }