Program: 57323
Project: 57323
Buggy source:
/** 
 * Two arguments arctangent function
 * @param y ordinate
 * @param x abscissa
 * @return phase angle of point (x,y) between {@code -PI} and {@code PI}
 */
public static double atan2(double y,double x){
  if (x != x || y != y) {
    return Double.NaN;
  }
  if (y == 0.0) {
    double result=x * y;
    double invx=1.0 / x;
    double invy=1.0 / y;
    if (invx == 0.0) {
      if (x > 0) {
        return y;
      }
 else {
        return copySign(Math.PI,y);
      }
    }
    if (x < 0.0 || invx < 0.0) {
      if (y < 0.0 || invy < 0.0) {
        return -Math.PI;
      }
 else {
        return Math.PI;
      }
    }
 else {
      return result;
    }
  }
  if (y == Double.POSITIVE_INFINITY) {
    if (x == Double.POSITIVE_INFINITY) {
      return Math.PI / 4.0;
    }
    if (x == Double.NEGATIVE_INFINITY) {
      return Math.PI * 3.0 / 4.0;
    }
    return Math.PI / 2.0;
  }
  if (y == Double.NEGATIVE_INFINITY) {
    if (x == Double.POSITIVE_INFINITY) {
      return -Math.PI / 4.0;
    }
    if (x == Double.NEGATIVE_INFINITY) {
      return -Math.PI * 3.0 / 4.0;
    }
    return -Math.PI / 2.0;
  }
  if (x == Double.POSITIVE_INFINITY) {
    if (y > 0.0 || 1 / y > 0.0) {
      return 0.0;
    }
    if (y < 0.0 || 1 / y < 0.0) {
      return -0.0;
    }
  }
  if (x == Double.NEGATIVE_INFINITY) {
    if (y > 0.0 || 1 / y > 0.0) {
      return Math.PI;
    }
    if (y < 0.0 || 1 / y < 0.0) {
      return -Math.PI;
    }
  }
  if (x == 0) {
    if (y > 0.0 || 1 / y > 0.0) {
      return Math.PI / 2.0;
    }
    if (y < 0.0 || 1 / y < 0.0) {
      return -Math.PI / 2.0;
    }
  }
  final double r=y / x;
  if (Double.isInfinite(r)) {
    return atan(r,0,x < 0);
  }
  double ra=doubleHighPart(r);
  double rb=r - ra;
  final double xa=doubleHighPart(x);
  final double xb=x - xa;
  rb+=(y - ra * xa - ra * xb - rb * xa - rb * xb) / x;
  double temp=ra + rb;
  rb=-(temp - ra - rb);
  ra=temp;
  if (ra == 0 && (y < 0)) {
    ra=-0.0;
  }
  double result=atan(ra,rb,x < 0);
  return result;
}

Fixed version (ground truth):
/** 
 * Two arguments arctangent function
 * @param y ordinate
 * @param x abscissa
 * @return phase angle of point (x,y) between {@code -PI} and {@code PI}
 */
public static double atan2(double y,double x){
  if (x != x || y != y) {
    return Double.NaN;
  }
  if (y == 0.0) {
    double result=x * y;
    double invx=1.0 / x;
    double invy=1.0 / y;
    if (invx == 0.0) {
      if (x > 0) {
        return y;
      }
 else {
        return copySign(Math.PI,y);
      }
    }
    if (x < 0.0 || invx < 0.0) {
      if (y < 0.0 || invy < 0.0) {
        return -Math.PI;
      }
 else {
        return Math.PI;
      }
    }
 else {
      return result;
    }
  }
  if (y == Double.POSITIVE_INFINITY) {
    if (x == Double.POSITIVE_INFINITY) {
      return Math.PI / 4.0;
    }
    if (x == Double.NEGATIVE_INFINITY) {
      return Math.PI * 3.0 / 4.0;
    }
    return Math.PI / 2.0;
  }
  if (y == Double.NEGATIVE_INFINITY) {
    if (x == Double.POSITIVE_INFINITY) {
      return -Math.PI / 4.0;
    }
    if (x == Double.NEGATIVE_INFINITY) {
      return -Math.PI * 3.0 / 4.0;
    }
    return -Math.PI / 2.0;
  }
  if (x == Double.POSITIVE_INFINITY) {
    if (y > 0.0 || 1 / y > 0.0) {
      return 0.0;
    }
    if (y < 0.0 || 1 / y < 0.0) {
      return -0.0;
    }
  }
  if (x == Double.NEGATIVE_INFINITY) {
    if (y > 0.0 || 1 / y > 0.0) {
      return Math.PI;
    }
    if (y < 0.0 || 1 / y < 0.0) {
      return -Math.PI;
    }
  }
  if (x == 0) {
    if (y > 0.0 || 1 / y > 0.0) {
      return Math.PI / 2.0;
    }
    if (y < 0.0 || 1 / y < 0.0) {
      return -Math.PI / 2.0;
    }
  }
  final double r=y / x;
  if (Double.isInfinite(r)) {
    return atan(r,0,x < 0);
  }
  double ra=doubleHighPart(r);
  double rb=r - ra;
  final double xa=doubleHighPart(x);
  final double xb=x - xa;
  rb+=(y - ra * xa - ra * xb - rb * xa - rb * xb) / x;
  double temp=ra + rb;
  rb=-(temp - ra - rb);
  ra=temp;
  if (ra == 0) {
    ra=copySign(0.0,y);
  }
  double result=atan(ra,rb,x < 0);
  return result;
}