mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 22:00:28 +01:00
[python] Upgrade to micropython 1.11
This commit is contained in:
@@ -83,6 +83,8 @@ mp_obj_t mp_parse_num_integer(const char *restrict str_, size_t len, int base, m
|
||||
mp_uint_t dig = *str;
|
||||
if ('0' <= dig && dig <= '9') {
|
||||
dig -= '0';
|
||||
} else if (dig == '_') {
|
||||
continue;
|
||||
} else {
|
||||
dig |= 0x20; // make digit lower-case
|
||||
if ('a' <= dig && dig <= 'z') {
|
||||
@@ -233,14 +235,19 @@ mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool
|
||||
// string should be a decimal number
|
||||
parse_dec_in_t in = PARSE_DEC_IN_INTG;
|
||||
bool exp_neg = false;
|
||||
mp_int_t exp_val = 0;
|
||||
mp_int_t exp_extra = 0;
|
||||
int exp_val = 0;
|
||||
int exp_extra = 0;
|
||||
while (str < top) {
|
||||
mp_uint_t dig = *str++;
|
||||
unsigned int dig = *str++;
|
||||
if ('0' <= dig && dig <= '9') {
|
||||
dig -= '0';
|
||||
if (in == PARSE_DEC_IN_EXP) {
|
||||
exp_val = 10 * exp_val + dig;
|
||||
// don't overflow exp_val when adding next digit, instead just truncate
|
||||
// it and the resulting float will still be correct, either inf or 0.0
|
||||
// (use INT_MAX/2 to allow adding exp_extra at the end without overflow)
|
||||
if (exp_val < (INT_MAX / 2 - 9) / 10) {
|
||||
exp_val = 10 * exp_val + dig;
|
||||
}
|
||||
} else {
|
||||
if (dec_val < DEC_VAL_MAX) {
|
||||
// dec_val won't overflow so keep accumulating
|
||||
@@ -274,6 +281,8 @@ mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool
|
||||
} else if (allow_imag && (dig | 0x20) == 'j') {
|
||||
imag = true;
|
||||
break;
|
||||
} else if (dig == '_') {
|
||||
continue;
|
||||
} else {
|
||||
// unknown character
|
||||
str--;
|
||||
@@ -292,15 +301,16 @@ mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool
|
||||
exp_val -= SMALL_NORMAL_EXP;
|
||||
dec_val *= SMALL_NORMAL_VAL;
|
||||
}
|
||||
|
||||
// At this point, we need to multiply the mantissa by its base 10 exponent. If possible,
|
||||
// we would rather manipulate numbers that have an exact representation in IEEE754. It
|
||||
// turns out small positive powers of 10 do, whereas small negative powers of 10 don't.
|
||||
// So in that case, we'll yield a division of exact values rather than a multiplication
|
||||
// of slightly erroneous values.
|
||||
if (exp_val < 0 && exp_val > -EXACT_POWER_OF_10) {
|
||||
dec_val /= MICROPY_FLOAT_C_FUN(pow)(10, -exp_val);
|
||||
if (exp_val < 0 && exp_val >= -EXACT_POWER_OF_10) {
|
||||
dec_val /= MICROPY_FLOAT_C_FUN(pow)(10, -exp_val);
|
||||
} else {
|
||||
dec_val *= MICROPY_FLOAT_C_FUN(pow)(10, exp_val);
|
||||
dec_val *= MICROPY_FLOAT_C_FUN(pow)(10, exp_val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,11 +339,13 @@ mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool
|
||||
return mp_obj_new_complex(0, dec_val);
|
||||
} else if (force_complex) {
|
||||
return mp_obj_new_complex(dec_val, 0);
|
||||
}
|
||||
#else
|
||||
if (imag || force_complex) {
|
||||
raise_exc(mp_obj_new_exception_msg(&mp_type_ValueError, "complex values not supported"), lex);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
else {
|
||||
return mp_obj_new_float(dec_val);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user