in core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF16.java [2679:2848]
public float readFloatValue() {
float floatValue = 0;
final char[] chars = this.chars;
int quote = '\0';
int ch = this.ch;
int offset = this.offset, end = this.end;
if (ch == '"' || ch == '\'') {
quote = ch;
ch = offset == end ? EOI : chars[offset++];
}
long result;
boolean wasNull = false;
if (quote != 0 && ch == quote) {
ch = offset == end ? EOI : chars[offset++];
wasNull = true;
result = 0;
} else {
int fc = ch;
result = ch >= '0' && ch <= '9'
? '0' - ch
: ch == '-' || ch == '+'
? 0
: 1; // or any value > 0
int d;
while (result <= 0
&& offset + 1 < end
&& (d = IOUtils.digit2(chars, offset)) != -1) {
if (Long.MIN_VALUE / 100 <= result) {
result = result * 100 - d; // overflow from d => result > 0
offset += 2;
} else {
result = 1; // overflow
}
}
if (result <= 0 && offset < end && IOUtils.isDigit(ch = chars[offset])) {
if (Long.MIN_VALUE / 10 <= result) {
result = result * 10 + '0' - ch; // overflow from '0' - d => result > 0
offset++;
} else {
result = 1; // overflow
}
}
int scale = 0;
if (result <= 0
&& offset < end
&& chars[offset] == '.'
) {
offset++;
while (result <= 0
&& offset + 1 < end
&& (d = IOUtils.digit2(chars, offset)) != -1) {
if (Long.MIN_VALUE / 100 <= result) {
result = result * 100 - d; // overflow from d => result > 0
offset += 2;
scale += 2;
} else {
result = 1; // overflow
}
}
if (result <= 0 && offset < end && IOUtils.isDigit(ch = chars[offset])) {
if (Long.MIN_VALUE / 10 <= result) {
result = result * 10 + '0' - ch; // overflow from '0' - d => result > 0
offset++;
scale++;
} else {
result = 1; // overflow
}
}
}
if (result <= 0) {
ch = offset == end ? EOI : chars[offset++];
}
int expValue;
if (result <= 0) {
if (ch == 'e' || ch == 'E') {
boolean negativeExp;
ch = offset == end ? EOI : chars[offset++];
if ((negativeExp = (ch == '-')) || ch == '+') {
ch = offset == end ? EOI : chars[offset++];
} else if (ch == ',') {
throw numberError();
}
if (IOUtils.isDigit(ch)) {
expValue = ch - '0';
while (offset < end
&& IOUtils.isDigit((ch = chars[offset]))
) {
d = ch - '0';
expValue = expValue * 10 + d;
if (expValue > MAX_EXP) {
throw new JSONException("too large exp value : " + expValue);
}
offset++;
}
if (negativeExp) {
expValue = -expValue;
}
scale -= expValue;
ch = offset == end ? EOI : chars[offset++];
} else {
result = 1; // invalid
}
} else if (ch == 'L' || ch == 'F' || ch == 'D' || ch == 'B' || ch == 'S') {
ch = offset == end ? EOI : chars[offset++];
}
}
if (result <= 0 && quote != 0) {
if (ch == quote) {
ch = offset == end ? EOI : chars[offset++];
} else {
result = 1; // invalid
}
}
if (result <= 0) {
boolean value = true;
if (scale == 0) {
floatValue = (float) result;
} else if ((long) (float) result == result) {
if (0 < scale && scale < FLOAT_10_POW.length) {
floatValue = (float) result / FLOAT_10_POW[scale];
} else if (0 > scale && scale > -FLOAT_10_POW.length) {
floatValue = (float) result * FLOAT_10_POW[-scale];
} else {
value = false;
}
} else {
value = false;
}
if (!value) {
if (scale > 0 && scale < 128) {
floatValue = TypeUtils.floatValue(fc == '-' ? -1 : 1, Math.abs(result), scale);
} else {
result = 1; // invalid
}
} else {
if (fc != '-' && floatValue != 0) {
floatValue = -floatValue;
}
}
}
}
if (result > 0) {
readNumber0();
return getFloatValue();
}
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : chars[offset++];
}
if (comma = (ch == ',')) {
ch = offset == end ? EOI : chars[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : chars[offset++];
}
}
this.wasNull = wasNull;
this.ch = (char) ch;
this.offset = offset;
return floatValue;
}