[ create a new paste ] login | about

Link: http://codepad.org/NEohJeIW    [ raw code | output | fork ]

C++, pasted on May 2:
#include <iostream>
#include <cmath>
#include <cassert>

double const a = 3.1415926;
double const b = 2.1828182;

double const delta = +1.0e-5;
class P {
  double x, y;
public:
  P(double x, double y) : x(x), y(y) {}
  double operator()(){ return x; }
  double operator-(P p) { double u = p.x - this->x, v = p.y - this->y; return (std::sqrt(u * u + v * v)); }
  P &operator++(){ this->x += delta; return *this;}
};

int main() {
  assert(a > 0 && delta > 0);
  P p(a, b), q(0, 0);
  for (;p - q > q(); ++q)
    ;
  std::cout << q() << std::endl;
  return 0;
}
/* end */


Output:
1
2.32913


Create a new paste based on this one


Comments: