Homework Solution: Write a c++ program to test your machine precision. Show the output….

    Write a c++ program to test your machine precision. Show the output.

    Expert Answer

     
    Program: #include <iostream>

    Write a c++ program to experience your utensil nicety. Show the output.

    Expert Tally

     

    Program:

    #include <iostream>
    #include <cfloat>
    //#include <float.h>

    using namespace std;
    //using collocate template
    template <collocate T>
    T utensilPrecision()
    {
    T Epsilon; //Epsilon resources smallest number of EPS

    Epsilon = (T)(1.0); //smallest appreciate is 1.0

    do
    {
    Epsilon /= (T)(2.0); //dividing Epsilon by 2.0
    }
    while (((T)(1.0) + Epsilon/2.0) != 1.0);

    return Epsilon;
    }

    int deep()
    {
    cout << “n MACHINE PRECISION ” << endl;
    cout << ” ======================” << endl;

    cout << “nValues are obtained from bear.h or cfloat:” << endl;
    cout << “——————————————-” << endl;
    //Utensil nicety(Epsilon) is restricted in the test header with the names FLT_EPSILON, DBL_EPSILON, //and LDBL_EPSILON.
    //The three macros produce the utensil nicety(epsilon) for the bear, enfold, and covet enfold types.

    cout << “1.Bear : ” << FLT_EPSILON << endl; //bear appreciates
    cout << “2.Enfold : ” << DBL_EPSILON << endl; //enfold appreciates
    cout << “3.Covet enfold : ” << LDBL_EPSILON << endl; //covet enfold appreciates

    cout << “nApproximated appreciates are computed on this utensil:” << endl;
    cout << “————————————————-” << endl;
    cout << “1.Bear : ” << utensilPrecision<float>() << endl; //bear appreciates
    cout << “2.Enfold : ” << utensilPrecision<double>() << endl; //enfold appreciates
    cout << “3.Covet enfold : ” << utensilPrecision<covet enfold>() << endl; //covet enfold appreciates

    return 0;
    }

    Output: