import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;

public class Main {
    static final NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);

    static void parse(final String s, final double expected) throws ParseException {
        final Number parseResult = numberFormat.parse(s);
        System.out.println(s+"->"+parseResult+"=="+expected+" "+(parseResult.doubleValue()==expected));
    }

    public static void main(final String[] args) throws ParseException {

        // Making sure we're dealing with DecimalFormat
        if (numberFormat.getClass() != DecimalFormat.class) {
            throw new AssertionError("Did not get a DecimalFormat");
        }

        parse("0.123E1",1.23); // Ok
        parse("0.123E309",1.23E308); // Ok
        parse("0.123E310",Double.POSITIVE_INFINITY); // Ok, this exceeds the range of double and results in +INFINITY
        parse("0.123E2147483647",Double.POSITIVE_INFINITY); // Ok, this exceeds the range of double and results in +INFINITY; exponent is Integer.MAX_VALUE
        parse("0.123E2147483648",Double.POSITIVE_INFINITY); // NOT ok, result is 0, but should be +INFINITY; exponent is Integer.MAX_VALUE + 1

        parse("0.0123E2147483648",Double.POSITIVE_INFINITY); // Ok, results in +INFINITY; exponent is Integer.MAX_VALUE + 1, but mantissa is between 0.01 and 0.1
        parse("0.0123E2147483649",Double.POSITIVE_INFINITY); // NOT ok, result is 0, but should be +INFINITY; exponent is Integer.MAX_VALUE + 2 and mantissa is between 0.01 and 0.1

        parse("1.23E2147483646",Double.POSITIVE_INFINITY); // Ok, results in +INFINITY; exponent is Integer.MAX_VALUE - 1 and mantissa is between 1 and 10
        parse("1.23E2147483647",Double.POSITIVE_INFINITY); // NOT ok, result is 0, but should be +INFINITY; exponent is Integer.MAX_VALUE, but mantissa is between 1 and 10

        parse("0.123E-322",0.123E-322); // Ok
        parse("0.123E-323",0.0); // Ok, this exceeds the range of double (Double.MIN_VALUE) and results in 0
        parse("0.123E-2147483648",0.0); // Ok, this exceeds the range of double (Double.MIN_VALUE) and results in 0; exponent is Integer.MIN_VALUE
        parse("0.123E-2147483649",0.0); // Not ok, result is +INFINITY, but should be 0; exponent is Integer.MIN_VALUE - 1

        parse("0.123E4294967296",Double.POSITIVE_INFINITY); // Not ok, result is 0.123, but should be +INFINITY; exponent is FFFF_FFFF + 1
    }
}