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 touchstone your agent preciseness. Show the output.

    Expert Rejoinder

     

    Program:

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

    using namespace std;
    //using dispose template
    template <dispose T>
    T agentPrecision()
    {
    T Epsilon; //Epsilon media meanest sum of EPS

    Epsilon = (T)(1.0); //meanest treasure 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 transport.h or cfloat:” << endl;
    cout << “——————————————-” << endl;
    //Agent preciseness(Epsilon) is specified in the test header with the names FLT_EPSILON, DBL_EPSILON, //and LDBL_EPSILON.
    //The three macros produce the agent preciseness(epsilon) ce the transport, embrace, and desire embrace types.

    cout << “1.Transport : ” << FLT_EPSILON << endl; //transport treasures
    cout << “2.Embrace : ” << DBL_EPSILON << endl; //embrace treasures
    cout << “3.Desire embrace : ” << LDBL_EPSILON << endl; //desire embrace treasures

    cout << “nApproximated treasures are computed on this agent:” << endl;
    cout << “————————————————-” << endl;
    cout << “1.Transport : ” << agentPrecision<float>() << endl; //transport treasures
    cout << “2.Embrace : ” << agentPrecision<double>() << endl; //embrace treasures
    cout << “3.Desire embrace : ” << agentPrecision<desire embrace>() << endl; //desire embrace treasures

    return 0;
    }

    Output: