code: public static double logSubtractExact(double x, double y) {
          if (x < y) {
              throw new IllegalStateException("x must be >= y. x=" + x + " y=" + y);
          }
          
          // p = 0 or q = 0, where x = log(p), y = log(q)
          if (Double.NEGATIVE_INFINITY == y) {
              return x;
          } else if (Double.NEGATIVE_INFINITY == x) {
              return y;
          }
  
          // p != 0 && q != 0
          return x + Math.log1p(-exp(y - x));
      }
docs: Subtracts two probabilities that are stored as log probabilities.
  Note that x >= y.
  
  @param x log(p)
  @param y log(q)
  @return log(p - q) = log(exp(p) + exp(q))
  @throws IllegalStateException if x < y