I recently started to learn C++ and I have a question regarding the syntax of an exercise given in our lecture about the accuracy when we declare different types of variables, in this case float
and double
.
#include <iostream>
using namespace std ;
int main()
{
// Accuracy test with float
float eps_f = 1.0 ;
while (float(1.0 + eps_f) != 1.0)
eps_f /= 2.0 ;
cout << "Resolving capacity float approximately: " << 2*eps_f << endl ;
// Accuracy test with double
double eps_d = 1.0 ;
while (1.0 + eps_d != 1.0)
eps_d /= 2.0 ;
cout << "Resolving capacity double approximately : " << 2*eps_d << endl ;
}
So what I don't understand is what is the point of while here? What is happening?
while (1.0 + eps_d != 1.0) { eps_d /= 2.0; }