#include #include int main () { // largest number for double { const double factor = 1.0001; double large = 1; double next_large = large*factor; while (!isinf(next_large)) { large = next_large; next_large = large*factor; } printf("Largest double precision=%e \n",large); } // largest number for float { const float factor = 1.0001; float large = 1; float next_large = large*factor; while (!isinf(next_large)) { large = next_large; next_large = large*factor; } printf("Largest single precision=%e \n",large); } // smallest number for double { // we would like to use the same // reduction factor as above, 1.0001, but // if one does so one realizes that // floating point divisions are _way_ // slower than floating point // multiplications. since we don't want // to wait quite as long, we choose a // coarser reduction factor const double factor = 2; double small = 1; double next_small = small/factor; while (next_small != 0) { small = next_small; next_small = small/factor; } printf("Smallest double precision=%e \n",small); } // smallest number for float { const float factor = 2; float small = 1; int n=0; float next_small = small/factor; while (next_small != 0) { small = next_small; next_small = small/factor; } printf("Smallest single precision=%e \n \n",small); } return 0; }