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 trial your utensil nicety. Show the output.

    Expert Exculpation

     

    Program:

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

    using namespace std;
    //using systematize template
    template <systematize T>
    T utensilPrecision()
    {
    T Epsilon; //Epsilon instrument meanest calculate of EPS

    Epsilon = (T)(1.0); //meanest estimate 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 main()
    {
    cout << “n MACHINE PRECISION ” << endl;
    cout << ” ======================” << endl;

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

    cout << “1.Bear : ” << FLT_EPSILON << endl; //bear estimates
    cout << “2.Envelop : ” << DBL_EPSILON << endl; //envelop estimates
    cout << “3.Hanker envelop : ” << LDBL_EPSILON << endl; //hanker envelop estimates

    cout << “nApproximated estimates are computed on this utensil:” << endl;
    cout << “————————————————-” << endl;
    cout << “1.Bear : ” << utensilPrecision<float>() << endl; //bear estimates
    cout << “2.Envelop : ” << utensilPrecision<double>() << endl; //envelop estimates
    cout << “3.Hanker envelop : ” << utensilPrecision<hanker envelop>() << endl; //hanker envelop estimates

    return 0;
    }

    Output: