title: Subtraction not being evaluated in java? (caused by setting one array to another)
body: <p>Note: this is not a duplicate of the many "why is my floating point subtraction giving exactly what I want?" The difference is in the 3rd decimal place.</p>
  
  <p>I have the following in a java file:</p>
  
  <pre><code>perturb[i] = params[i]-h;
  writer.write("    params "+Double.toString(params[i])+"\n");
  writer.write("    h      "+Double.toString(h)+"\n");
  writer.write("    pert1  "+Double.toString(params[i]-h)+"\n");
  writer.write("    pert2  "+Double.toString(perturb[i])+"\n");
  </code></pre>
  
  <p>and the output file shows:</p>
  
  <pre><code>params 1.2E-7
  h      1.2E-10
  pert1  1.1987999999999999E-7
  pert2  1.2E-7
  </code></pre>
  
  <p>perturb and params are both double[] and h is a double. </p>
  
  <p>Why are pert1 and pert2 not the same? I can't seem to get perturb[i] to be params[i]-h.</p>
  
  <p>EDIT WITH SOLUTION:</p>
  
  <p>The issue is there was a previous assignment of perturb to params (which apparently just makes perturb a reference to params). You can repeat the behavior with the following test case:</p>
  
  <pre><code>public class test {
  
  public static void main(String[] args) {
      double[] perturb;
      double[] params = {1.2E-7};
      perturb = params;
      double h=1.2E-10;
      int i=0;
      perturb[i] += h;
      perturb[i] = params[i]-h;
      System.out.println("    params "+Double.toString(params[i])+"\n");
      System.out.println("    h      "+Double.toString(h)+"\n");
      System.out.println("    pert1  "+Double.toString(params[i]-h)+"\n");
      System.out.println("    pert2  "+Double.toString(perturb[i])+"\n");
  
    }
  }
  </code></pre>
  
  <p>which gives:</p>
  
  <pre><code>params 1.2E-7
  h      1.2E-10
  pert1  1.1987999999999999E-7
  pert2  1.2E-7
  </code></pre>