Report error when loading decimal value with scientific notation (#428)

Currently we do not support scientific notation of decimal value.
This commit is contained in:
Mingyu Chen
2018-12-17 21:04:18 +08:00
committed by ZHAO Chun
parent d291068b37
commit dc4cbab11e
3 changed files with 24 additions and 19 deletions

View File

@ -900,26 +900,27 @@ int DecimalValue::parse_from_str(const char* decimal_str, int32_t length) {
*buff = value * powers10[DIG_PER_DEC1 - index_in_powers10];
}
// Handle exponent
// TODO: we do not support decimal in scientific notation
if ((frac_ptr + 1) < end && (*frac_ptr == 'e' || *frac_ptr == 'E')) {
int64_t exponent = strtoll(frac_ptr + 1, (char**) end, 10);
if (end != frac_ptr + 1) { // If at least one digit
if (errno) { // system error number, it is thread local
set_to_zero();
return E_DEC_BAD_NUM;
}
if (exponent > (INT_MAX / 2) || (errno == 0 && exponent < 0)) {
set_to_zero();
return E_DEC_OVERFLOW;
}
if (exponent < INT_MAX / 2 && error != E_DEC_OVERFLOW) {
set_to_zero();
return E_DEC_TRUNCATED;
}
if (error != E_DEC_OVERFLOW) {
// error = shift((int32_t) exponent);
}
}
return E_DEC_BAD_NUM;
// int64_t exponent = strtoll(frac_ptr + 1, (char**) &end, 10);
// if (end != frac_ptr + 1) { // If at least one digit
// if (errno) { // system error number, it is thread local
// set_to_zero();
// return E_DEC_BAD_NUM;
// }
// if (exponent > (INT_MAX / 2) || (errno == 0 && exponent < 0)) {
// set_to_zero();
// return E_DEC_OVERFLOW;
// }
// if (exponent < INT_MAX / 2 && error != E_DEC_OVERFLOW) {
// set_to_zero();
// return E_DEC_TRUNCATED;
// }
// if (error != E_DEC_OVERFLOW) {
// // error = shift((int32_t) exponent);
// }
// }
}
if (_sign && is_zero()) {
_sign = false;