C++ Bc. 20 cpp

Z GeoWikiCZ
#include <iostream>
#include <climits>

double d_epsilon();

int main()
{
  std::cout << std::numeric_limits<double> ::epsilon() << "\n";
  std::cout << d_epsilon() << "\n";
}

double d_epsilon()
{
  const double jedna = 1;
  double tst, eps = jedna;

  do
    {
      eps /= 2;
      tst  = jedna;
      tst += eps/2;
    }
  while (tst != jedna);

  return eps;
}
g++ 20.cpp && ./a.out
2.22045e-16
2.22045e-16

[ Zpět ]