Double.MIN_VALUE and Double.MAX_VALUE are not the right ones to use. Use Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY instead.