in util/src/main/java/com/epam/deltix/util/text/CharSequenceParser.java [328:422]
public static float parseFloat (final CharSequence sc, final int startIncl, final int endExcl) {
if (startIncl > endExcl)
throw new IllegalArgumentException ("Illegal range: " + startIncl + ".." + endExcl);
if (startIncl == endExcl)
throw new NumberFormatException ("Empty string");
int pos = startIncl;
int numerator = 0;
float denominator = 1;
int sign = 0;
boolean dotSeen = false;
boolean overflow = false;
char ch = sc.charAt (pos);
if (ch == '+' || ch == '-') {
if (ch == '-')
sign = INT_SIGN_BIT;
pos++;
checkNotAtEnd (pos, endExcl, sc, startIncl);
ch = sc.charAt (pos);
}
for (;;) {
if (ch != ',') {
if (!dotSeen && ch == '.')
dotSeen = true;
else {
final int digit = ch - '0';
if (digit < 0 || digit > 9) {
if (Util.equals (sc, "NaN"))
return (Float.NaN);
throw new NumberFormatException (
"Illegal digit at position " + (pos + 1) + " in: " +
sc.subSequence (startIncl, endExcl).toString ()
);
}
if (overflow) {
// Stop shifting the numerator
if (!dotSeen)
denominator *= 0.1;
}
else {
numerator = numerator * 10 + digit;
if (dotSeen)
denominator *= 10;
if (numerator >= FLOAT_ASSUMED_BIT)
overflow = true;
}
}
}
pos++;
if (pos == endExcl)
break;
ch = sc.charAt (pos);
}
if (numerator == 0)
return (0.0F);
// Build the double first, ignoring the denominator
int exp = FLOAT_NORM_EXP;
if (overflow)
while ((numerator & FLOAT_OVERFLOW_BITMASK) != 0) {
exp++;
numerator >>>= 1;
}
else
while ((numerator & FLOAT_ASSUMED_BIT) == 0) {
exp--;
numerator <<= 1;
}
numerator &= FLOAT_MANTISSA_BITMASK;
final int bits = sign | (exp << FLOAT_MANTISSA_WIDTH) | numerator;
float result = Float.intBitsToFloat (bits);
if (denominator != 1)
result /= denominator;
return (result);
}