public static RealInterval midpoint(RealInterval x) {
    RealInterval z = new RealInterval();
    z.lo = (x.lo + x.hi)/2.0;
    z.hi = z.lo;

    if ((Double.NEGATIVE_INFINITY < z.lo) &&
        (Double.POSITIVE_INFINITY > z.lo)) {
      return(z);
    }
    else if ((Double.NEGATIVE_INFINITY == x.lo)) {
      if (x.hi > 0.0) {
        z.lo = 0.0; z.hi = z.lo; return(z);
      } else if (x.hi == 0.0){
        z.lo = -1.0; z.hi = z.lo; return(z);
      } else {
        z.lo = x.hi*2; z.hi = z.lo; return(z);
      }
    } else if ((Double.POSITIVE_INFINITY == x.hi)) {
      if (x.lo < 0.0) {
        z.lo = 0.0; z.hi = z.lo; return(z);
      } else if (x.lo == 0.0){
        z.lo = 1.0; z.hi = z.lo; return(z);
      } else {
        z.lo = x.lo*2; z.hi = z.lo; return(z);
      }
    } else {
      z.lo = x.lo; z.hi = x.hi;
      System.out.println("Error in RealInterval.midpoint");
      return(z);
    }
  }