@Test public void testParseExplicitDouble() throws Exception { Assert.assertEquals(1234.123d, Numbers.parseDouble("1234.123d"), 0.000001); }
public static double parseDouble(CharSequence sequence) throws NumericException { int lim = sequence.length(); if (lim == 0) { throw NumericException.INSTANCE; } boolean negative = sequence.charAt(0) == '-'; int i; if (negative) { i = 1; } else { i = 0; } if (i >= lim) { throw NumericException.INSTANCE; } switch (sequence.charAt(i)) { case 'N': return parseConst(sequence, i, lim, NaN, Double.NaN); case 'I': return parseConst(sequence, i, lim, INFINITY, negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY); default: break; } long val = 0; int dp = -1; int dpe = lim; int exp = 0; out: for (; i < lim; i++) { final int c = sequence.charAt(i); switch (c) { case '.': dp = i; continue; case 'E': case 'e': exp = parseInt(sequence, i + 1, lim); if (dpe == lim) { dpe = i; } break out; case 'D': case 'd': if (i + 1 < lim || i == 0) { throw NumericException.INSTANCE; } if (dpe == lim) { dpe = i; } break out; default: if (c < '0' || c > '9') { throw NumericException.INSTANCE; } if (val < LONG_OVERFLOW_MAX) { val = (val << 3) + (val << 1) + (c - '0'); } else if (dpe == lim) { dpe = i; } break; } } exp = dp == -1 ? exp : exp - (dpe - dp - 1); if (exp > 308) { exp = 308; } else if (exp < -308) { exp = -308; } if (exp > -1) { return (negative ? -val : val) * pow10d[exp]; } else { return (negative ? -val : val) * pow10dNeg[-exp]; } }
Numbers { public static double parseDouble(CharSequence sequence) throws NumericException { int lim = sequence.length(); if (lim == 0) { throw NumericException.INSTANCE; } boolean negative = sequence.charAt(0) == '-'; int i; if (negative) { i = 1; } else { i = 0; } if (i >= lim) { throw NumericException.INSTANCE; } switch (sequence.charAt(i)) { case 'N': return parseConst(sequence, i, lim, NaN, Double.NaN); case 'I': return parseConst(sequence, i, lim, INFINITY, negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY); default: break; } long val = 0; int dp = -1; int dpe = lim; int exp = 0; out: for (; i < lim; i++) { final int c = sequence.charAt(i); switch (c) { case '.': dp = i; continue; case 'E': case 'e': exp = parseInt(sequence, i + 1, lim); if (dpe == lim) { dpe = i; } break out; case 'D': case 'd': if (i + 1 < lim || i == 0) { throw NumericException.INSTANCE; } if (dpe == lim) { dpe = i; } break out; default: if (c < '0' || c > '9') { throw NumericException.INSTANCE; } if (val < LONG_OVERFLOW_MAX) { val = (val << 3) + (val << 1) + (c - '0'); } else if (dpe == lim) { dpe = i; } break; } } exp = dp == -1 ? exp : exp - (dpe - dp - 1); if (exp > 308) { exp = 308; } else if (exp < -308) { exp = -308; } if (exp > -1) { return (negative ? -val : val) * pow10d[exp]; } else { return (negative ? -val : val) * pow10dNeg[-exp]; } } }
Numbers { public static double parseDouble(CharSequence sequence) throws NumericException { int lim = sequence.length(); if (lim == 0) { throw NumericException.INSTANCE; } boolean negative = sequence.charAt(0) == '-'; int i; if (negative) { i = 1; } else { i = 0; } if (i >= lim) { throw NumericException.INSTANCE; } switch (sequence.charAt(i)) { case 'N': return parseConst(sequence, i, lim, NaN, Double.NaN); case 'I': return parseConst(sequence, i, lim, INFINITY, negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY); default: break; } long val = 0; int dp = -1; int dpe = lim; int exp = 0; out: for (; i < lim; i++) { final int c = sequence.charAt(i); switch (c) { case '.': dp = i; continue; case 'E': case 'e': exp = parseInt(sequence, i + 1, lim); if (dpe == lim) { dpe = i; } break out; case 'D': case 'd': if (i + 1 < lim || i == 0) { throw NumericException.INSTANCE; } if (dpe == lim) { dpe = i; } break out; default: if (c < '0' || c > '9') { throw NumericException.INSTANCE; } if (val < LONG_OVERFLOW_MAX) { val = (val << 3) + (val << 1) + (c - '0'); } else if (dpe == lim) { dpe = i; } break; } } exp = dp == -1 ? exp : exp - (dpe - dp - 1); if (exp > 308) { exp = 308; } else if (exp < -308) { exp = -308; } if (exp > -1) { return (negative ? -val : val) * pow10d[exp]; } else { return (negative ? -val : val) * pow10dNeg[-exp]; } } private  Numbers(); }
Numbers { public static double parseDouble(CharSequence sequence) throws NumericException { int lim = sequence.length(); if (lim == 0) { throw NumericException.INSTANCE; } boolean negative = sequence.charAt(0) == '-'; int i; if (negative) { i = 1; } else { i = 0; } if (i >= lim) { throw NumericException.INSTANCE; } switch (sequence.charAt(i)) { case 'N': return parseConst(sequence, i, lim, NaN, Double.NaN); case 'I': return parseConst(sequence, i, lim, INFINITY, negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY); default: break; } long val = 0; int dp = -1; int dpe = lim; int exp = 0; out: for (; i < lim; i++) { final int c = sequence.charAt(i); switch (c) { case '.': dp = i; continue; case 'E': case 'e': exp = parseInt(sequence, i + 1, lim); if (dpe == lim) { dpe = i; } break out; case 'D': case 'd': if (i + 1 < lim || i == 0) { throw NumericException.INSTANCE; } if (dpe == lim) { dpe = i; } break out; default: if (c < '0' || c > '9') { throw NumericException.INSTANCE; } if (val < LONG_OVERFLOW_MAX) { val = (val << 3) + (val << 1) + (c - '0'); } else if (dpe == lim) { dpe = i; } break; } } exp = dp == -1 ? exp : exp - (dpe - dp - 1); if (exp > 308) { exp = 308; } else if (exp < -308) { exp = -308; } if (exp > -1) { return (negative ? -val : val) * pow10d[exp]; } else { return (negative ? -val : val) * pow10dNeg[-exp]; } } private  Numbers(); static void append(CharSink sink, final float value, int scale); static void append(CharSink sink, final int value); static void append(CharSink sink, final long value); static void append(CharSink sink, double value); static void append(CharSink sink, double value, int scale); static void appendHex(CharSink sink, final int value); static void appendHex(CharSink sink, final long value, boolean pad); static void appendHexPadded(CharSink sink, final int value); static void appendLong256(long a, long b, long c, long d, CharSink sink); static int ceilPow2(int value); static long ceilPow2(long value); static int compare(double a, double b); static int compare(float a, float b); static int decodeHighInt(long val); static int decodeLowInt(long val); static long encodeLowHighInts(int low, int high); static int hexToDecimal(int c); static int msb(int value); static int msb(long value); static double parseDouble(CharSequence sequence); static float parseFloat(CharSequence sequence); static int parseHexInt(CharSequence sequence); static int parseHexInt(CharSequence sequence, int lo, int hi); static long parseHexLong(CharSequence sequence, int lo, int hi); static int parseInt(CharSequence sequence); static int parseInt(CharSequence sequence, int p, int lim); static int parseIntQuiet(CharSequence sequence); static long parseIntSafely(CharSequence sequence, final int p, int lim); static int parseIntSize(CharSequence sequence); static long parseLong(CharSequence sequence); static long parseLong(CharSequence sequence, int p, int lim); static long parseLongQuiet(CharSequence sequence); static long parseLongSize(CharSequence sequence); static short parseShort(CharSequence sequence, int p, int lim); static double roundDown(double value, int scale); static double roundDownNegScale(double value, int scale); static double roundDownPosScale(double value, int scale); static double roundHalfDown(double value, int scale); static double roundHalfEven(double value, int scale); static double roundHalfEven0NegScale(double value, int scale); static double roundHalfEven0PosScale(double value, int scale); static double roundHalfEvenNegScale(double value, int scale); static double roundHalfEvenPosScale(double value, int scale); static double roundHalfUp(double value, int scale); static double roundHalfUpNegScale(double value, int scale); static double roundHalfUpPosScale(double value, int scale); static double roundUp(double value, int scale); static double roundUpNegScale(double value, int scale); static double roundUpPosScale(double value, int scale); static boolean isFinite(double d); static double longToDouble(long value); static float longToFloat(long value); static double intToDouble(int value); static float intToFloat(int value); static long intToLong(int value); }
Numbers { public static double parseDouble(CharSequence sequence) throws NumericException { int lim = sequence.length(); if (lim == 0) { throw NumericException.INSTANCE; } boolean negative = sequence.charAt(0) == '-'; int i; if (negative) { i = 1; } else { i = 0; } if (i >= lim) { throw NumericException.INSTANCE; } switch (sequence.charAt(i)) { case 'N': return parseConst(sequence, i, lim, NaN, Double.NaN); case 'I': return parseConst(sequence, i, lim, INFINITY, negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY); default: break; } long val = 0; int dp = -1; int dpe = lim; int exp = 0; out: for (; i < lim; i++) { final int c = sequence.charAt(i); switch (c) { case '.': dp = i; continue; case 'E': case 'e': exp = parseInt(sequence, i + 1, lim); if (dpe == lim) { dpe = i; } break out; case 'D': case 'd': if (i + 1 < lim || i == 0) { throw NumericException.INSTANCE; } if (dpe == lim) { dpe = i; } break out; default: if (c < '0' || c > '9') { throw NumericException.INSTANCE; } if (val < LONG_OVERFLOW_MAX) { val = (val << 3) + (val << 1) + (c - '0'); } else if (dpe == lim) { dpe = i; } break; } } exp = dp == -1 ? exp : exp - (dpe - dp - 1); if (exp > 308) { exp = 308; } else if (exp < -308) { exp = -308; } if (exp > -1) { return (negative ? -val : val) * pow10d[exp]; } else { return (negative ? -val : val) * pow10dNeg[-exp]; } } private  Numbers(); static void append(CharSink sink, final float value, int scale); static void append(CharSink sink, final int value); static void append(CharSink sink, final long value); static void append(CharSink sink, double value); static void append(CharSink sink, double value, int scale); static void appendHex(CharSink sink, final int value); static void appendHex(CharSink sink, final long value, boolean pad); static void appendHexPadded(CharSink sink, final int value); static void appendLong256(long a, long b, long c, long d, CharSink sink); static int ceilPow2(int value); static long ceilPow2(long value); static int compare(double a, double b); static int compare(float a, float b); static int decodeHighInt(long val); static int decodeLowInt(long val); static long encodeLowHighInts(int low, int high); static int hexToDecimal(int c); static int msb(int value); static int msb(long value); static double parseDouble(CharSequence sequence); static float parseFloat(CharSequence sequence); static int parseHexInt(CharSequence sequence); static int parseHexInt(CharSequence sequence, int lo, int hi); static long parseHexLong(CharSequence sequence, int lo, int hi); static int parseInt(CharSequence sequence); static int parseInt(CharSequence sequence, int p, int lim); static int parseIntQuiet(CharSequence sequence); static long parseIntSafely(CharSequence sequence, final int p, int lim); static int parseIntSize(CharSequence sequence); static long parseLong(CharSequence sequence); static long parseLong(CharSequence sequence, int p, int lim); static long parseLongQuiet(CharSequence sequence); static long parseLongSize(CharSequence sequence); static short parseShort(CharSequence sequence, int p, int lim); static double roundDown(double value, int scale); static double roundDownNegScale(double value, int scale); static double roundDownPosScale(double value, int scale); static double roundHalfDown(double value, int scale); static double roundHalfEven(double value, int scale); static double roundHalfEven0NegScale(double value, int scale); static double roundHalfEven0PosScale(double value, int scale); static double roundHalfEvenNegScale(double value, int scale); static double roundHalfEvenPosScale(double value, int scale); static double roundHalfUp(double value, int scale); static double roundHalfUpNegScale(double value, int scale); static double roundHalfUpPosScale(double value, int scale); static double roundUp(double value, int scale); static double roundUpNegScale(double value, int scale); static double roundUpPosScale(double value, int scale); static boolean isFinite(double d); static double longToDouble(long value); static float longToFloat(long value); static double intToDouble(int value); static float intToFloat(int value); static long intToLong(int value); static final int INT_NaN; static final long LONG_NaN; static final double TOLERANCE; static final int SIZE_1MB; static final char[] hexDigits; final static int[] hexNumbers; final static int pow10max; static final int SIGNIFICAND_WIDTH; static final int MAX_SCALE; static final long SIGN_BIT_MASK; }