/* The program below illustrates the range of precision : what is the smallest number you can add to one such that the result is different from one? Execute the program to see the values for your machine. Observe the conversion characters in the printf and the f,l,L in the constants: 1.0f, 1.0l, and 1.0L are all different from each other. */ #include #include int main(void) { float f; double x; long double ld; printf("\nTesting the precision of float, double, and long double : \n"); f = 1.0f + 1.0e-7; printf(" 1.0 + 1.0e-7 = %.10f\n", f); f = 1.0f + 1.0e-8; printf(" 1.0 + 1.0e-8 = %.10f\n", f); x = 1.0l + 1.0e-15; printf(" 1.0 + 1.0e-15 = %.20lf\n", x); x = 1.0l + 1.0e-16; printf(" 1.0 + 1.0e-16 = %.20lf\n", x); ld = 1.0L + 1.0e-19; printf(" 1.0 + 1.0e-19 = %.30Lf\n", ld); ld = 1.0L + 1.0e-20; printf(" 1.0 + 1.0e-20 = %.30Lf\n", ld); printf("\nThe experiment above is explained by constants from float.h :\n"); printf(" precision of float : %e\n", FLT_EPSILON); printf(" precision of double : %.15le\n", DBL_EPSILON); printf(" precision of long double : %.30Le\n", LDBL_EPSILON); printf("\nThe largest and smallest numbers we can represent are : \n"); printf(" largest float : %e\n", FLT_MAX); printf(" largest double : %.15le\n", DBL_MAX); printf(" largest long double : %.30Le\n", LDBL_MAX); printf(" smallest float : %e\n", FLT_MIN); printf(" smallest double : %.15le\n", DBL_MIN); printf(" smallest long double : %.30Le\n", LDBL_MIN); printf("\n"); return 0; }