Problem 2

Approximate the square root of non-zero positive integer c.

Use Newton-Raphson method: t' = ((c/t) +t) / 2.0.

The result t should be precise up to eps: abs(t*t -c) < eps.

Functions:

approximate_sqrt(c, eps)

Approximate the square-root of c up to the precision eps.

approximate_sqrt(c: int, eps: float) float[source]

Approximate the square-root of c up to the precision eps.

Requires
  • eps > 1e-6

  • c < 1000 * 1000

  • c > 0

Ensures
  • abs(result * result - c) <= eps

    (Guaranteed precision)