code: private static double interpolate(double lower, double upper, double remainder, double scale) {
      if (lower == NEGATIVE_INFINITY) {
        if (upper == POSITIVE_INFINITY) {
          // Return NaN when lower == NEGATIVE_INFINITY and upper == POSITIVE_INFINITY:
          return NaN;
        }
        // Return NEGATIVE_INFINITY when NEGATIVE_INFINITY == lower <= upper < POSITIVE_INFINITY:
        return NEGATIVE_INFINITY;
      }
      if (upper == POSITIVE_INFINITY) {
        // Return POSITIVE_INFINITY when NEGATIVE_INFINITY < lower <= upper == POSITIVE_INFINITY:
        return POSITIVE_INFINITY;
      }
      return lower + (upper - lower) * remainder / scale;
    }
docs: Returns a value a fraction {@code (remainder / scale)} of the way between {@code lower} and
  {@code upper}. Assumes that {@code lower <= upper}. Correctly handles infinities (but not
  {@code NaN}).