public class FloatExample {
  
  // try this out with t1=1 and t2=0.0000000000000001
  //
  public static void cumulativeError(double t1, double t2, int repeats) {
    double r = t1;
    for (int i = 0; i < repeats; ++i) {
      r += t2;
    }
    System.out.println("Result after " + repeats + 
                       " additions with unstable algorithm: " + r);
    r = 0;
    for (int i = 0; i < repeats; ++i) {
      r += t2;
    }
    r += t1;
    System.out.println("Result after " + repeats +
                       " addition with stabler algorithm: " + r);
  }
}
