class Convert {

    @NonNull
    public static String glide2(double groundSpeed, double climb, int precision, boolean units) {
        final double glideRatio = -groundSpeed / climb;
        if (Double.isNaN(glideRatio)) {
            return "";
        } else if (groundSpeed + Math.abs(climb) < 0.5) { // ~1 mph
            return ""; // Stationary
        } else if (Double.isInfinite(glideRatio) || Math.abs(glideRatio) > 30) {
            return ""; // Level
        } else if (groundSpeed < 0.5 && Math.abs(climb) > 0.5) {
            return ""; // Vertical
        } else {
            final String value;
            if (glideRatio < 0) {
                value = String.format("+%." + precision + "f", -glideRatio);
            } else {
                value = String.format("%." + precision + "f", glideRatio);
            }
            if (units) {
                return value + " : 1";
            } else {
                return value;
            }
        }
    }

}