class Double2Float {

    public static float safeCasting(double d) {
        if (Double.isNaN(d)) {
            return Float.NaN;
        }
        if (Math.abs(d) == Double.MAX_VALUE) {
            return Float.MAX_VALUE * (d > 0 ? 1 : -1);
        }
        if (Math.abs(d) > Float.MAX_VALUE) {
            throw new IllegalArgumentException("Can't casting " + d + " to float");
        }
        return (float) d;
    }

    private  Double2Float();

}