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 criterion your media nicety. Show the output.

    Expert Rejoinder

     

    Program:

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

    using namespace std;
    //using assort template
    template <assort T>
    T mediaPrecision()
    {
    T Epsilon; //Epsilon media lowest calculate of EPS

    Epsilon = (T)(1.0); //lowest appraise 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;
    //Media nicety(Epsilon) is limited in the exemplar header with the names FLT_EPSILON, DBL_EPSILON, //and LDBL_EPSILON.
    //The three macros surrender the media nicety(epsilon) ce the bear, inclose, and hanker inclose types.

    cout << “1.Bear : ” << FLT_EPSILON << endl; //bear appraises
    cout << “2.Inclose : ” << DBL_EPSILON << endl; //inclose appraises
    cout << “3.Hanker inclose : ” << LDBL_EPSILON << endl; //hanker inclose appraises

    cout << “nApproximated appraises are computed on this media:” << endl;
    cout << “————————————————-” << endl;
    cout << “1.Bear : ” << mediaPrecision<float>() << endl; //bear appraises
    cout << “2.Inclose : ” << mediaPrecision<double>() << endl; //inclose appraises
    cout << “3.Hanker inclose : ” << mediaPrecision<hanker inclose>() << endl; //hanker inclose appraises

    return 0;
    }

    Output: