@Override protected double solveImpl(final Ops.DoubleOp f,final double xAccuracy){
  double min1, min2;
  double froot, p, q, r, s, xAcc1, xMid;
  double d=0.0, e=0.0;
  root=xMax;
  froot=fxMax;
  while (evaluationNumber <= getMaxEvaluations()) {
    if ((froot > 0.0 && fxMax > 0.0) || (froot < 0.0 && fxMax < 0.0)) {
      xMax=xMin;
      fxMax=fxMin;
      e=d=root - xMin;
    }
    if (Math.abs(fxMax) < Math.abs(froot)) {
      xMin=root;
      root=xMax;
      xMax=xMin;
      fxMin=froot;
      froot=fxMax;
      fxMax=fxMin;
    }
    xAcc1=2.0 * Constants.QL_EPSILON * Math.abs(root) + 0.5 * xAccuracy;
    xMid=(xMax - root) / 2.0;
    if (Math.abs(xMid) <= xAcc1 || froot == 0.0)     return root;
    if (Math.abs(e) >= xAcc1 && Math.abs(fxMin) > Math.abs(froot)) {
      s=froot / fxMin;
      if (Closeness.isClose(xMin,xMax)) {
        p=2.0 * xMid * s;
        q=1.0 - s;
      }
 else {
        q=fxMin / fxMax;
        r=froot / fxMax;
        p=s * (2.0 * xMid * q* (q - r) - (root - xMin) * (r - 1.0));
        q=(q - 1.0) * (r - 1.0) * (s - 1.0);
      }
      if (p > 0.0)       q=-q;
      p=Math.abs(p);
      min1=3.0 * xMid * q - Math.abs(xAcc1 * q);
      min2=Math.abs(e * q);
      if (2.0 * p < (min1 < min2 ? min1 : min2)) {
        e=d;
        d=p / q;
      }
 else {
        d=xMid;
        e=d;
      }
    }
 else {
      d=xMid;
      e=d;
    }
    xMin=root;
    fxMin=froot;
    if (Math.abs(d) > xAcc1)     root+=d;
 else     root+=sign(xAcc1,xMid);
    froot=f.op(root);
    evaluationNumber++;
  }
  throw new ArithmeticException("maximum number of function evaluations exceeded");
}

@ Override protected double solveImpl ( final Ops . DoubleOp f , final double xAccuracy ) { double min1 , min2 ; double froot , p , q , r , s , xAcc1 , xMid ; double d = 0.0 , e = 0.0 ; root = xMax ; froot = fxMax ; while ( evaluationNumber <= getMaxEvaluations ( ) ) { if ( ( froot > 0.0 && fxMax > 0.0 ) || ( froot < 0.0 && fxMax < 0.0 ) ) { xMax = xMin ; fxMax = fxMin ; e = d = root - xMin ; } if ( Math . abs ( fxMax ) < Math . abs ( froot ) ) { xMin = root ; root = xMax ; xMax = xMin ; fxMin = froot ; froot = fxMax ; fxMax = fxMin ; } xAcc1 = 2.0 * Constants . QL_EPSILON * Math . abs ( root ) + 0.5 * xAccuracy ; xMid = ( xMax - root ) / 2.0 ; if ( Math . abs ( xMid ) <= xAcc1 || froot == 0.0 ) return root ; if ( Math . abs ( e ) >= xAcc1 && Math . abs ( fxMin ) > Math . abs ( froot ) ) { s = froot / fxMin ; if ( Closeness . isClose ( xMin , xMax ) ) { p = 2.0 * xMid * s ; q = 1.0 - s ; } else { q = fxMin / fxMax ; r = froot / fxMax ; p = s * ( 2.0 * xMid * q * ( q - r ) - ( root - xMin ) * ( r - 1.0 ) ) ; q = ( q - 1.0 ) * ( r - 1.0 ) * ( s - 1.0 ) ; } if ( p > 0.0 ) q = - q ; p = Math . abs ( p ) ; min1 = 3.0 * xMid * q - Math . abs ( xAcc1 * q ) ; min2 = Math . abs ( e * q ) ; if ( 2.0 * p < ( min1 < min2 ? min1 : min2 ) ) { e = d ; d = p / q ; } else { d = xMid ; e = d ; } } else { d = xMid ; e = d ; } xMin = root ; fxMin = froot ; if ( Math . abs ( d ) > xAcc1 ) root += d ; else root += sign ( xAcc1 , xMid ) ; froot = f . op ( root ) ; evaluationNumber ++ ; } throw new ArithmeticException ( "maximum number of function evaluations exceeded" ) ; }
computes the roots of a function by using the brent method .
