title: How to understand Newton's method for square root in Java?
body: <pre><code>public static double sqrt(double c)
  {
      if (c &lt; 0) return Double.NaN;
      double t = c;                          // line 1
      double err = 1e-15;                    // line 2
      while (Math.abs(t - c/t) &gt; err * t)    // line 3
          t = (c/t + t) / 2.0;           // line 4
      return t;
  }
  </code></pre>
  
  <p>Q1: I am confused by the variable t in line1 and line 4: 
  since t = c, then  c/t = 1, what does line 4 mean?</p>
  
  <p>Q2: In line 3, what's the purpose to check?</p>
  
  <p>I searched "Newton's method" and got several explanation, but I still could not understand. May I request an straight forward explanation here? </p>